-->
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: Newbie - My Objects are not persistent
PostPosted: Fri Feb 24, 2006 4:10 pm 
Newbie

Joined: Fri Feb 24, 2006 12:16 pm
Posts: 4
I tried out the "Getting Started"-example (with the Event class).
It works fine so far, but my saved Objects are not persistent, they only exist as long as my applications runs - if I start my application a second time, Hibernate creates a new table (after it said "Event - Table not found) like nothing happened before.
Does anyone have an idea what Im doing wrong ?
Im using hsqldb1.8.0.1 with Hibernate 3.1.2.




<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:db_myfile</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<property name="connection.pool_size">1</property>
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<property name="current_session_context_class">thread</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>

<mapping resource="Event.hbm.xml"/>

</session-factory>

</hibernate-configuration>




<hibernate-mapping>
<class name="Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="increment"/>
</id>
<property name="date" type="timestamp" column="EVENT_DATE"/>
<property name="title"/>
</class>
</hibernate-mapping>




import org.hibernate.Session;

import java.util.*;


public class EventManager {

public static void main(String[] args) {
EventManager mgr = new EventManager();

//if (args[0].equals("store")) {
mgr.createAndStoreEvent("My Event1", new Date());

mgr.createAndStoreEvent("My Event2", new Date());

mgr.createAndStoreEvent("My Event3", new Date());

mgr.createAndStoreEvent("My Event4", new Date());
//}
//else if (args[0].equals("list")) {
List events = mgr.listEvents();
System.out.println("Listgröße:" + events.size());
for (int i = 0; i < events.size(); i++) {
Event theEvent = (Event) events.get(i);
System.out.println("Event: " + theEvent.getTitle() +
" Time: " + theEvent.getDate());
}
//}

//HibernateUtil.getSessionFactory().close();
}

private List listEvents() {

Session session = HibernateUtil.getSessionFactory().getCurrentSession();

session.beginTransaction();

List result = session.createQuery("from Event").list();

session.getTransaction().commit();

return result;
}

private void createAndStoreEvent(String title, Date theDate) {

Session session = HibernateUtil.getSessionFactory().getCurrentSession();

session.beginTransaction();

Event theEvent = new Event();
theEvent.setTitle(title);
theEvent.setDate(theDate);

session.save(theEvent);

session.getTransaction().commit();
}

}


Top
 Profile  
 
 Post subject: My Objects are not persistent
PostPosted: Fri Feb 24, 2006 4:35 pm 
Newbie

Joined: Fri Feb 24, 2006 12:16 pm
Posts: 4
Found the solution :
I have to add
<property name="hibernate.connection.shutdown">true</property>
to the hibernate.cfg.xml.


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.