-->
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: My app recreate the tables each time it runs.
PostPosted: Tue Oct 09, 2007 1:30 pm 
Newbie

Joined: Tue Oct 09, 2007 12:55 pm
Posts: 1
I folow the Hibernate tutorial.
It insert, select, update just fine. My problem is that the application creates the table in the data base. So when I run the app again, the app delete the old table and create a new one.
What am I doing wrong?
Thanks!
RCM

Hibernate version:3.2.5
Name and version of the database you are using:PostgreSQL 8.2

Mapping documents:
Here is my hbm.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.emm.core.mensajes.Mensaje" table="MENSAJES">
<id name="id" column="MENSAJE_ID"  type="java.lang.Long">
<generator class ="native">
<param name="sequence">mensaje_id_seq</param>
</generator>
</id>
<property name="fecha" column="FECHA" type="java.util.Date"/>
<property name="mensaje" column="MENSAJE" type="java.lang.String"/>
<property name="titulo" column="TITULO" type="java.lang.String" />
</class>
</hibernate-mapping>


And here is my hibernate.cfg.xml
Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost/emmdb</property>
<property name="connection.username">administrator</property>
<property name="connection.password">damovo01</property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">create</property>
<mapping resource="com/emm/core/mensajes/Mensaje.hbm.xml" />
</session-factory>
</hibernate-configuration>


Code between sessionFactory.openSession() and session.close():

Code:

       session.beginTransaction();
        Mensaje elmensaje = new Mensaje();
        elmensaje.setMensaje("one");
        elmensaje.setFecha(new Date());
        elmensaje.setTitulo("one");
        session.save(elmensaje);
        session.getTransaction().commit();





The generated SQL (show_sql=true):
The console:

Code:
Hibernate: select nextval ('mensaje_id_seq')
Hibernate: insert into MENSAJES (FECHA, MENSAJE, TITULO, MENSAJE_ID) values (?, ?, ?, ?)
Hibernate: select nextval ('mensaje_id_seq')
Hibernate: insert into MENSAJES (FECHA, MENSAJE, TITULO, MENSAJE_ID) values (?, ?, ?, ?)



Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 09, 2007 2:21 pm 
Newbie

Joined: Tue Aug 07, 2007 2:31 am
Posts: 11
Try changing your hibernate.cfg.xml

Such that

Code:
<property name="hbm2ddl.auto">create</property>


becomes

Code:
<property name="hbm2ddl.auto">update</property>


Update will create your tables if they don't exist and update them if they exist but are not of the correct structure.


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.