-->
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.  [ 3 posts ] 
Author Message
 Post subject: Query fails after persist
PostPosted: Fri Oct 06, 2006 10:59 am 
Newbie

Joined: Fri Oct 06, 2006 10:52 am
Posts: 8
I'm new to Hibernate and I'm trying to use the latest Hibernate EntityManager code with MySQL in a J2SE environment.

If I persist an object, then query that object, the query return null.
If I persist the object, then flush the entity manager, the query is successfull.

I wasn't expecting to have to flush the entity manager after every persist or remove call.


I've also just discovered that if I wrap the persist in a transaction, then a query works ...

em.getTransaction().begin();
em.persist(user);
em.getTransaction.commit();

Query query = em.createQuery("select user from User as user");
return (List<User>) query.getResultList();

Is there a setting I'm missing, or does this have something to do with the transaction model when running in a J2SE environment?

Bryan


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 09, 2006 4:17 pm 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Maybe missing EM.joinTransaction() [http://www.hibernate.org/hib_docs/entitymanager/reference/en/html_single/#d0e1836] - as in joining current transaction.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 09, 2006 5:14 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
of course you *must* use transaction demarcation

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.