-->
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.  [ 4 posts ] 
Author Message
 Post subject: Session per conversation & query unflushed entities
PostPosted: Wed Nov 03, 2010 6:05 am 
Newbie

Joined: Wed Nov 03, 2010 5:34 am
Posts: 4
Hi,

here's the context :

we are currently writing an application which is web based (flex front end). The server side is implemented with Java, using hibernate for ORM. Well, I'm not wrong with the forum I write to.
The specificity of this application is that it implements a conversation with the user. That means that the user is opening a conversation and before it decides to save (or cancel) the conversation, it performs many operations on objects which are mapped as hibernate entities.

For instance :
  • open a conversation
  • create an object A
  • save it in the session
  • query it
  • update it
  • etc...
  • save the conversation

and then another conversation cycle starts.

We chose naturally the session-per-conversation pattern to implement this way to work.
Let me remind you the principle : the hibernate session is created once when the user decides to start a conversation, its flush mode being set to MANUAL, and from now it is disconnected between each transaction until the user decide to end the conversation which is the only time when we explicitly flush the session (and so write the data from session to DB).

We had no problem at all until we want to query some unflushed entities! Because if we want to use this kind of conversation, that's because we want to be in a state of "simulation' until we explicitly flush the session.
But it appears that unflushed entities cannot be loaded using hibernate criterias or HQL except if a flush() is performed on the session which leads to loose all benefit from the session-per-conversation pattern...

So my question is :

Can we configure this behaviour? (ie can we enable querying the session cache event if the session is not flushed?)

As it seems that the answer is no (any contradictor will be welcome!), 2nd question :
Is there a smart way to make it on my own without perverting the probably intelligent and considered hibernate's way of doing?

Hoping that my english is understandable, I thank you all by advance.

Ben


Top
 Profile  
 
 Post subject: Re: Session per conversation & query unflushed entities
PostPosted: Fri Nov 05, 2010 6:55 am 
Newbie

Joined: Wed Nov 03, 2010 5:34 am
Posts: 4
Any idea, somebody?


Top
 Profile  
 
 Post subject: Re: Session per conversation & query unflushed entities
PostPosted: Fri Nov 05, 2010 7:19 am 
Newbie

Joined: Fri Jan 26, 2007 9:58 am
Posts: 18
Location: Dublin
Are you using sessions.persist(x), think it may give you the behaviour you're looking for?


Top
 Profile  
 
 Post subject: Re: Session per conversation & query unflushed entities
PostPosted: Fri Nov 05, 2010 9:22 am 
Newbie

Joined: Wed Nov 03, 2010 5:34 am
Posts: 4
Hi,

thanks for your answer.
I checked the session.persist() method and it does not what I expect. ACtually this method is used to mark a transient as persisted without performing an identifier generation (that needs an insert into the database in case of identity for instance).
This does not solved my problem that is that the queries using criteria and HQL does not look up in the session for unflushed entities.
I think that hibernate relies on the database to perform the queries by calling some SQL in the end. That is why the session is not queried (unless when trying to get an object by the session.get() or session.load() method). If hibernate would be able to do that, that means that it would have to implement a full query system for its session that would become then a database on its own.
Well it's not the average need of the developper...
I think I have to find another solution (or another need).


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