-->
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.  [ 8 posts ] 
Author Message
 Post subject: Make a session read-only
PostPosted: Wed Mar 21, 2007 11:50 am 
Beginner
Beginner

Joined: Thu Jan 04, 2007 5:44 am
Posts: 26
Location: Innsbruck - Sivas(TR) - Bregenz
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

MySql

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Hello, I use the 2-session-pattern for a RCP application, thats mean I use a session per application only to read data and the second one to write. I read that I must make the read-session read-only. How I can do this?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 3:32 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
See this: http://www.docjar.com/docs/api/org/hibe ... %20boolean)

=> Session.setReadOnly(Entity, boolean)

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 22, 2007 6:52 pm 
Beginner
Beginner

Joined: Thu Jan 04, 2007 5:44 am
Posts: 26
Location: Innsbruck - Sivas(TR) - Bregenz
ok I know setReadOnly I have think its exists a method to set the session one time readOnly in the creation, independent from a entity...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 3:10 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I don't think this method exists.

Another way to do it could be putting the transaction in readonly mode, instead of the session. But no standard hibernate method let you do it. For my case, I do it in the tx demarcation xml file(the declaration of my tx proxy).

Maybe also see Query.setReadOnly(boolean), every queries in this mode will retrieve entities in readonly mode.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 4:17 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Read-only transactions are _not_ the same as session.setReadOnly() or query.setReadOnly(). The first is a hint for weak DBMS implementations that you only want to do SELECTs - a good DBMS transaction system should figure this out automatically. The latter is a setting that disables object snapshots at the Hibernate persistence context level. That means no dirty checking of these instances during flush-time. You safe memory but you still get the repeatable read guarantees of the persistence context cache.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 4:21 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
http://opensource.atlassian.com/project ... e/HHH-2501

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 6:30 am 
Beginner
Beginner

Joined: Thu Jan 04, 2007 5:44 am
Posts: 26
Location: Innsbruck - Sivas(TR) - Bregenz
But I read in the Best Practices for Thick-Client Applications (i.e., non-web apps.) http://www.hibernate.org/333.html that when we use a think client application the best method is to use a multi session pattern...


"...- One session will be read-only and allows the user to browse around in the application's data.

- Then for each Commands (or major delineated Task) I would create a separate session and transaction...."

What is the best method to implement this. I use criterias and queries, that means i get a list of entities. must i itereate them and set readonly?

The reason is that i want more performence when i load the entities.[/url]


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 23, 2007 7:00 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I didn't write that page and I don't think this is a good approach either. Read my blog entry that is linked on top of that page.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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