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