-->
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.  [ 5 posts ] 
Author Message
 Post subject: session.get(Class) don't return a proxy
PostPosted: Sun Sep 03, 2006 7:44 am 
Regular
Regular

Joined: Wed Sep 21, 2005 1:37 pm
Posts: 53
Location: Montpellier - France
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2

Hello,

I want to retrieve a proxy object of an entity using hibernate session and 'get(Class)'. Is it possible and how ?
Actually, when I use 'session.get(MyEntity.class)', it return an instance of MyEntity and not a proxy. So, when I change the entity using a setter, nothing is updated into the database or cache. I must use 'flush' or call an other method to synchronize the dirty object to the database.

When I use the same code in EJB3, it is the same trouble. The returned object is the entity, not the proxy so when I want to use a remote client, it don't work because it don't know the Entity class, only its interface.


Top
 Profile  
 
 Post subject: Use transactions
PostPosted: Tue Sep 05, 2006 10:10 am 
Regular
Regular

Joined: Wed Aug 24, 2005 11:49 am
Posts: 63
Generally, you want to use transactions.
You can either start them yourself :
Code:
Transaction t=session.getTransaction();
t.begin();

// your code

t.commit();


Better (more clean) is to configure your session to use JTA and let the EJB container take care of the transactions (using CMT).
At transaction commit time, the updates should happen (or earlier when needed, or when you call flush(), but this all depends on what you do, what your mappings are, etc.).

See http://www.hibernate.org/42.html

_________________
Edwin van der Elst
Finalist IT Group


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 05, 2006 3:00 pm 
Regular
Regular

Joined: Wed Sep 21, 2005 1:37 pm
Posts: 53
Location: Montpellier - France
Thanks

Ok, JTA is available only in the JBoss context, not in standalone one with tomcat. So, in this last configuration (hibernate + tomcat), I must use the session methods to flush or commit all the changes ?


Top
 Profile  
 
 Post subject: yeah
PostPosted: Tue Sep 05, 2006 4:12 pm 
Regular
Regular

Joined: Wed Aug 24, 2005 11:49 am
Posts: 63
Use the session to get a transaction, and commit that transaction when you are done.
Flush can be used within the transaction to force SQL statements to be executed (but not committed).
Committing is not the same as flushing!

_________________
Edwin van der Elst
Finalist IT Group


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 06, 2006 1:55 am 
Regular
Regular

Joined: Wed Sep 21, 2005 1:37 pm
Posts: 53
Location: Montpellier - France
Thanks


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