-->
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.  [ 1 post ] 
Author Message
 Post subject: Is Hibernate 4.3.8 broken?
PostPosted: Sun Feb 15, 2015 11:44 am 
Newbie

Joined: Sun Feb 15, 2015 11:37 am
Posts: 2
Hi,
I am new to this version of Hibernate, though I used it a long time ago. I downloaded the tutoral, which contains the deprecated BuildSession method. I updated to the currently recommended way of creating a session
public static SessionFactory getSessionFactory() {
if (sessionFactory == null) {
// loads configuration and mappings
Configuration configuration = new Configuration().configure();
ServiceRegistry serviceRegistry
= new StandardServiceRegistryBuilder()
.applySettings(configuration.getProperties()).build();

// builds a session factory from the service registry
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
}

return sessionFactory;
}

and tried the test code in AnnotationsIllustrationTest.java.

As long as this property is set in the hibernate.cfg.xml file
<property name="hbm2ddl.auto">create</property>
the test code works. But if I remove it, or call the same code sequence from a regular main method, the code hangs AFTER the final close
This is the code
public static void main(String args[])
{
Session session = HibernateUtil.getSession();
session.beginTransaction();
session.save(new Event("Our very first event!", new Date()));
session.save(new Event("A follow up event", new Date()));
session.getTransaction().commit();
session.close();

// now lets pull events from the database and list them
session = HibernateUtil.getSession();
session.beginTransaction();
List result = session.createQuery("from Event").list();
for (Event event : (List<Event>) result) {
System.out.println("Event (" + event.getDate() + ") : " + event.getTitle());
}
session.getTransaction().commit();
session.close();
}

Everything runs to the end, but a thread keeps running so nothing every completes. If I forcibly close, using System.exit(0), then the program stops, but I hate to do that.

Something seems terribly wrong if even the basic tutorial code doesn't run correctly. And the tutorial is out of date with deprecated methods. I notice a lot of people asking about the deprecated methods in the tutorial on this forum, with no response. Have people just given up on Hibernate?


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

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.