-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: regardless hibernate.hbm2ddl.auto=update tables are droped
PostPosted: Wed Jan 18, 2006 3:36 pm 
Newbie

Joined: Wed Jan 18, 2006 3:07 pm
Posts: 1
Hello,
i am using this simple code as configuration:
Code:
   cfg = new Configuration();
   cfg.SetProperty("hibernate.connection.provider", "NHibernate.Connection.DriverConnectionProvider");
   cfg.SetProperty("hibernate.hbm2ddl.auto", "update");
   cfg.SetProperty("hibernate.show_sql", "true");
   cfg.SetProperty("hibernate.dialect", "NHibernate.Dialect.MySQLDialect");
   cfg.SetProperty("hibernate.connection.driver_class", "NHibernate.Driver.MySqlDataDriver");
   cfg.SetProperty("hibernate.connection.connection_string", "Server=127.0.0.1;Database=schulze;Uid=root;Pwd=xxx;");
   cfg.AddXmlFile("car.hbm.xml");
   factory = cfg.BuildSessionFactory();

this is my carClass:
Code:
class Car
{
  public long id;
  public String name;
  public String speed;
  public long Id { get { return id; } set { id = value; } }
  public String Name { get { return name; } set { name = value; } }
  public String Speed { get { return speed; } set { speed = value; } }
}


Then i devided the hibernate action into 4 Steps:
initialization
connect
generating data & saveIt
closeConnection

Everything works fine, if i do not reinitialze nhibernate. So start my testprogramm, initialize it and then only connect, fill and disconnect (as often as i want) makes the db filled like expected. But closing and restarting the programm (the same like reinitialization) makes nHibernate dropping my nice existing car tables! I was searching for my failure for a long time, but couldn't solve the problem.(8h)
As "cfg.SetProperty("hibernate.hbm2ddl.auto", "update");" shows, i want only non existing tables beeing created. And i absolutely do not want to loose the stuff in the tables. Why is nhibernate dropping my tables, even if update is configured?

Thankz for your answers
Richard


Hibernate version:1.0.2.0

Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="HibernateTest.Car, HibernateTest" table="cars">
<id name="Id" unsaved-value="0">
<generator class="native" />
</id>
<property name="Name"/>
<property name="Speed"/>
</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Car car = new Car();
car.name = "ford1";
car.speed = "null1";
Car goodCar = new Car();
goodCar.name = "Porsche1";
goodCar.speed = "impressive1";
session.SaveOrUpdate(car);
session.SaveOrUpdate(goodCar);


Full stack trace of any exception that occurs: noExceptions occured

Name and version of the database you are using: MySQL 5.0.18


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 18, 2006 4:04 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
NHibernate does not support SchemaUpdate.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.