-->
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: Issue with the EntityManager method "refresh" and Hibernate
PostPosted: Sat Oct 23, 2010 8:56 am 
Newbie

Joined: Sat Oct 23, 2010 8:40 am
Posts: 2
Hey,
The following code throws an exception when invoking "em.refresh(p)":

1: EntityManager em = emf.createEntityManager();
2: em.getTransaction().begin();
3:
4: Product p = new Product("J&D", 35.0,"Whisky");
5: em.persist(p);
6:
7: em.refresh(p);
8: em.getTransaction().commit();
9: em.close();


When debugging the code, we see that Hibernate didn't write the record into the DB at line 6. He does is like foreseen - when it's required, not earlier.

At line 7, we get the following exception:
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.HibernateException: this instance does not yet exist as a row in the database
When we force Hibernate to flush the record into the DB at line 6, the INSERT is executed and no error occurs. We can do this by executing a select or just force the flush (with all consequences):

6 : em.createQuery("select p from Product p").getResultList();
6 : em.flush();


My question: should the method "refresh" not force Hibernate to write the record into the DB, as does the select or the flush statement wehn placesd before? (Might this be a bug?).

Thanks in advance for your answers.

Pierre


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.