-->
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: Objects loaded by createSQLQuery are not persisted
PostPosted: Fri Sep 16, 2005 5:33 am 
Newbie

Joined: Fri Sep 16, 2005 4:57 am
Posts: 2
Hi

I am using createSQLQuery to fetch a list of objects. The objects does not exist in the database, the query is used to get the attributes for instantiating the loaded objects.
This works fine - the objects are in my list.

However the objects are not persisted. The objects are loaded into the list and into the session, but hibernate does not persist them.
I guess hibernate thinks that the objects are persisted since they where loaded from tha database, but that is not the case. Thus calling persist(), saveOrUpdate() or save() does not do anything.

If I try to instantiate a new objects based the fetched list and persist these objects - then hibernate complains that the objects are already in the session.

A workaround is to do a session.delete and session.persist. This will delete the objects from the session (and the database, but they where never in the database) and thus I can persist the objects again - this time also into the database.

My question is - is this:
Objects loaded by createSQLQuery are in the session, but not necessarily persisted - is this correct hibernate behavior?

/Tage

PS: Hibernate 3 - Oracle 9


Top
 Profile  
 
 Post subject: Re: Objects loaded by createSQLQuery are not persisted
PostPosted: Fri Sep 16, 2005 6:39 am 
Newbie

Joined: Wed Jul 20, 2005 11:32 am
Posts: 7
As long as the objects are created in the same session that executes the query, the objects should get persisted.

Can you post the code snippet where you are facing this problem?

regards,
~Vinayak


Top
 Profile  
 
 Post subject: Re: Objects loaded by createSQLQuery are not persisted
PostPosted: Fri Sep 16, 2005 7:57 am 
Newbie

Joined: Fri Sep 16, 2005 4:57 am
Posts: 2
cvinayak wrote:
As long as the objects are created in the same session that executes the query, the objects should get persisted.

Exactly, but the table in the database remains empty.

cvinayak wrote:
Can you post the code snippet where you are facing this problem?

Fetching the list by:
List rels = session.createSQLQuery(
"select " +
"est.stamklasseidfk AS {FagholdxStamklasse.stamklasseId}, " +
"fxe.fagholdidfk AS {FagholdxStamklasse.fagholdId}, " +
"count(UNIQUE fxe.elevidfk) AS {FagholdxStamklasse.gyldig} " +
"from " +
"elevxstamklasse est " +
"LEFT JOIN fagholdxelev fxe on est.elevidfk = fxe.elevidfk " +
"group by est.stamklasseidfk, fxe.fagholdidfk")
.addEntity("FagholdxStamklasse", FagholdxStamklasse.class)
.list();

I guess this somehow should be sufficient to persist the "FagholdxStamklasse"-objects , but they do not get persisted.

Maybe the explanation is pretty simple. The objects have just been loaded - albeit via a query - and hibernate assumes that the objects are persisted since the values retreived are from the database.

The caveat is that the objects haven't been loaded as hibernate assumes.

Or am I complete off here?

/Tage


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.