[hibernate-dev] Temporary session and commit issue with manual flush mode

Steve Ebersole steve at hibernate.org
Sun Feb 12 18:28:53 EST 2012


Probably openTemporarySession() should be deprecated.  Notice it also 
says it is for HEM use, though the only current uses I see of it all 
come from envers.

If you want to share information from the main session, then the 
appropriate access would be to use org.hibernate.SharedSessionBuilder as 
obtained from org.hibernate.Session#sessionWithOptions

If the 2 should share JDBC connection, then 
org.hibernate.SharedSessionBuilder#connection() should be used.  If you 
want it to share the entire "transaction context", then 
org.hibernate.SharedSessionBuilder#transactionContext() should be used. 
  Pretty sure I asked Adam and the rest of the list about this 
transactionContext() method back when I first added it.  I never heard 
any response.  So if you go that transactionContext() route you may run 
into issues because I am pretty sure transactionContext() is sharing too 
much.


On 02/12/2012 04:40 AM, Łukasz Antoniak wrote:
> Hi all,
>
> I have a question regarding SessionFactoryImplementor.openTemporarySession() (bug HHH-7017). As observed in non JTA environment
> with manual flush mode enabled, and 'hibernate.connection.autocommit' disabled, temporary session is not getting committed.
> How/when should I commit it manually? According to JavaDoc, it's "nontransactional". See the following log (H2):
>
> 11:19:01,531 DEBUG SQL:104 - insert into StrTestEntity_AUD (REVTYPE, str, id, REV) values (?, ?, ?, ?)
> 11:19:03,687  WARN SqlExceptionHelper:143 - SQL Error: 50200, SQLState: HYT00
> Timeout trying to lock table "STRTESTENTITY_AUD"; SQL statement:
> select strtestent0_.REV as col_0_0_ from StrTestEntity_AUD strtestent0_ cross join REVINFO defaultrev1_ where strtestent0_.id=?
> and strtestent0_.REV=defaultrev1_.REV order by strtestent0_.REV asc [50200-145]
> 	at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:52)
> ...
>
> Method AuditProcess.doBeforeTransactionCompletion() is responsible for persisting all audit data. The description in HHH-7017 is
> very accurate and correct. Please advice.
>
> How is temporary session related to current normal session and its lifecycle?
>
> Regards,
> Lukasz
> _______________________________________________
> hibernate-dev mailing list
> hibernate-dev at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/hibernate-dev

-- 
steve at hibernate.org
http://hibernate.org



More information about the hibernate-dev mailing list