Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Hibernate Sessions and Read Committed Isolation Level
PostPosted: Sat Sep 03, 2016 6:49 am 
Newbie

Joined: Sat Sep 03, 2016 5:01 am
Posts: 2
i have crated two session factories, they were named: SFA and SFB

my question is how to make their isolatoin level become read committed between the two factories, for example:
OpenSessoin from SFA - update a record in Table A, but the modified data has not been committed yet.

Open Session SFB - retrieve reocrd from Table A, it return the moifided record, but the record has not commited yet (i expect it only return the committed data only)

following is my hibernate config xml, which is used to initialize both SFA and SFB:

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.ibm.db2.jcc.DB2Driver</property>
<property name="connection.datasource">java:jboss/datasources/CSSS2DS</property>
<property name="hibernate.dialect">org.hibernate.dialect.DB2Dialect</property>
<property name="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</property>
<property name="hibernate.current_session_context_class">jta</property>
<property name="hibernate.show_sql">true</property>
<property name="use_sql_comments">true</property>
<mapping resource="hbm/Stock.hbm.xml" />
</session-factory>
</hibernate-configuration>

following is my pseudo code:

public static UserTransaction createUserTransaction(){
UserTransaction utx=null;
try {
InitialContext ic = new InitialContext();
utx = (UserTransaction) ic.lookup("java:comp/UserTransaction");
} catch (NamingException e) {
e.printStackTrace();
}

return utx;
}


UserTransaction ut = DatabaseConnectionFactory.createUserTransaction();

ut.begin();
Session sessionA = SFA.getSessionFactory().openSession();

//update a record in Table A

Session sessionB = SFB.getSessionFactory().openSession();

//select record from Table B
//expect can retrieve the commited values only


thanks!


Top
 Profile  
 
 Post subject: Re: how to make their isolatoin level become read committed
PostPosted: Sat Sep 03, 2016 8:44 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1103
The two sessions are enrolled in the same Transaction, that's why Session B is seeing the uncommitted changed from Session A. Check out this post for more details.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
 Post subject: Re: Hibernate Sessions and Read Committed Isolation Level
PostPosted: Sat Sep 03, 2016 10:35 am 
Newbie

Joined: Sat Sep 03, 2016 5:01 am
Posts: 2
thanks mihalcea_vlad !

i have tried to add <property name="hibernate.connection.isolation">2</property> in the xml config file, but it seems not work. does it means i cant use JTA as transaction manager in my situation?


Top
 Profile  
 
 Post subject: Re: Hibernate Sessions and Read Committed Isolation Level
PostPosted: Sat Sep 03, 2016 11:15 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1103
JTA does not support setting isolation levels from the application-side. You have to set it at DataSource level in the App Server.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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.