Home » Modeling » EMF » [Teneo] CurrentSession problem with spring managed transactions
|
Re: [Teneo] CurrentSession problem with spring managed transactions [message #491156 is a reply to message #491132] |
Tue, 13 October 2009 13:32 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi David,
Maybe it is a default configuration setting difference, can you try the following extra hibernate configuration setting:
<prop key="hibernate.current_session_context_class">thread</prop >
there are also two other values: jta and managed. I am not sure which one would work with Spring transactional scopes.
Let me know if this helped, or not...
gr. Martin
David Polách wrote:
> Hello, I'm facing problems with Spring managed Txs when working with
> HbSessionDataStore. Problem is caused by
> sessionFactory.getCurrentSession() failing in transactional scope. My
> session factory is configured in Spring context as HbSessionDataStore
> and transactions are provided by HibernateTransactionManager.
>
> When trying to save new entity to DB by invoking
> sessionFactory.getCurrentSession().saveOrUpdate(entity), test fails with
> org.hibernate.HibernateException: No CurrentSessionContext configured!
> This is strange since the call is in transactional scope. I've tried to
> setup transactions either with Spring TransactionTemplate or
> @Transactional annotation or AspectJ style is Spring context (none of it
> helped).
>
> When invoking the same test case with standard POJO entities and session
> factory configured with Spring AnnotationSessionFactoryBean (no Teneo),
> sessionFactory.getCurrentSession() returns working session and
> transaction commits without errors.
>
> Part of my spring context config follows:
>
> <bean id="sessionFactory"
> class="org.eclipse.emf.teneo.hibernate.HbSessionDataStore"
> init-method="initialize">
> <property name="name" value="test-store" />
> <property name="hibernateProperties">
> <props>
> <prop key="hibernate.dialect">${hibernate.dialect}</prop>
> <prop key="hibernate.show_sql">false</prop>
> <prop key="hibernate.hbm2ddl.auto">create</prop>
> <prop key="hibernate.generate_statistics">true</prop>
> <prop key="hibernate.connection.datasource">java:comp/env/jdbc/teneo </prop>
> </props>
> </property>
> <property name="EPackageClasses">
> <list>
> <value>eu.collectionspro.test.entity.impl.EntityPackageImpl </value>
> </list>
> </property>
> </bean>
>
> <bean id="transactionManager"
> class=" org.springframework.orm.hibernate3.HibernateTransactionManag er ">
> <property name="sessionFactory" ref="sessionFactory" />
> </bean>
>
> Thanks for help,
> David
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
Re: [Teneo] CurrentSession problem with spring managed transactions [message #491187 is a reply to message #491156] |
Tue, 13 October 2009 14:54 |
david Messages: 61 Registered: July 2009 |
Member |
|
|
Hi Martin,
thanks for hint but it did not help. I'm runnig my test locally so I
can't use JTA session context. Setting the current_session_context_class
to thread produces different exception:
org.hibernate.HibernateException: saveOrUpdate is not valid without
active transaction
at
org.hibernate.context.ThreadLocalSessionContext$TransactionP rotectionWrapper.invoke(ThreadLocalSessionContext.java:338)
at $Proxy4.saveOrUpdate(Unknown Source)
at eu.collectionspro.dao.GenDaoHib.save(GenDaoHib.java:47)
at
eu.collectionspro.test.PopulateDbTest$3.doInTransactionWitho utResult(PopulateDbTest.java:147)
at
org.springframework.transaction.support.TransactionCallbackW ithoutResult.doInTransaction(TransactionCallbackWithoutResul t.java:33)
at
org.springframework.transaction.support.TransactionTemplate. execute(TransactionTemplate.java:128)
The last line of stack trace shows that my code is actually enclosed in
transaction managed by HibernateTransactionManager. There still must be
some other difference between Teneo session factory config/behavior and
Spring AnnotationSessionFactoryBean.
Thanks,
David
Martin Taal wrote:
> Hi David,
> Maybe it is a default configuration setting difference, can you try the
> following extra hibernate configuration setting:
> <prop key="hibernate.current_session_context_class">thread</prop >
> there are also two other values: jta and managed. I am not sure which
> one would work with Spring transactional scopes.
>
> Let me know if this helped, or not...
>
> gr. Martin
>
> David Polách wrote:
>> Hello, I'm facing problems with Spring managed Txs when working with
>> HbSessionDataStore. Problem is caused by
>> sessionFactory.getCurrentSession() failing in transactional scope. My
>> session factory is configured in Spring context as HbSessionDataStore
>> and transactions are provided by HibernateTransactionManager.
>>
>> When trying to save new entity to DB by invoking
>> sessionFactory.getCurrentSession().saveOrUpdate(entity), test fails
>> with org.hibernate.HibernateException: No CurrentSessionContext
>> configured! This is strange since the call is in transactional scope.
>> I've tried to setup transactions either with Spring
>> TransactionTemplate or @Transactional annotation or AspectJ style is
>> Spring context (none of it helped).
>>
>> When invoking the same test case with standard POJO entities and
>> session factory configured with Spring AnnotationSessionFactoryBean
>> (no Teneo), sessionFactory.getCurrentSession() returns working session
>> and transaction commits without errors.
>>
>> Part of my spring context config follows:
>>
>> <bean id="sessionFactory"
>> class="org.eclipse.emf.teneo.hibernate.HbSessionDataStore"
>> init-method="initialize">
>> <property name="name" value="test-store" />
>> <property name="hibernateProperties">
>> <props> <prop
>> key="hibernate.dialect">${hibernate.dialect}</prop>
>> <prop key="hibernate.show_sql">false</prop>
>> <prop key="hibernate.hbm2ddl.auto">create</prop>
>> <prop key="hibernate.generate_statistics">true</prop>
>> <prop
>> key="hibernate.connection.datasource">java:comp/env/jdbc/teneo </prop>
>> </props>
>> </property>
>> <property name="EPackageClasses">
>> <list>
>> <value>eu.collectionspro.test.entity.impl.EntityPackageImpl </value>
>> </list>
>> </property> </bean>
>>
>> <bean id="transactionManager"
>> class=" org.springframework.orm.hibernate3.HibernateTransactionManag er ">
>> <property name="sessionFactory" ref="sessionFactory" />
>> </bean>
>>
>> Thanks for help,
>> David
>
>
|
|
|
Re: [Teneo] CurrentSession problem with spring managed transactions [message #491199 is a reply to message #491187] |
Tue, 13 October 2009 15:36 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi David,
Did you try the managed option?
A search on the internet also showed other options:
http://histos.net/blog/2008/12/on-hibernate-spring-sessions- and-transactions.html
(using a spring context)
And this one (but it talks about the opposite, a Spring wrapped sessionfactory outside of a spring managed transaction,
but maybe it gives usefull info):
http://www.theresearchkitchen.com/blog/archives/73
Let me know if this helps, otherwise I can try to reproduce it locally (with your help).
gr. Martin
David Polách wrote:
> Hi Martin,
>
> thanks for hint but it did not help. I'm runnig my test locally so I
> can't use JTA session context. Setting the current_session_context_class
> to thread produces different exception:
>
> org.hibernate.HibernateException: saveOrUpdate is not valid without
> active transaction
> at
> org.hibernate.context.ThreadLocalSessionContext$TransactionP rotectionWrapper.invoke(ThreadLocalSessionContext.java:338)
>
> at $Proxy4.saveOrUpdate(Unknown Source)
> at eu.collectionspro.dao.GenDaoHib.save(GenDaoHib.java:47)
> at
> eu.collectionspro.test.PopulateDbTest$3.doInTransactionWitho utResult(PopulateDbTest.java:147)
>
> at
> org.springframework.transaction.support.TransactionCallbackW ithoutResult.doInTransaction(TransactionCallbackWithoutResul t.java:33)
>
> at
> org.springframework.transaction.support.TransactionTemplate. execute(TransactionTemplate.java:128)
>
>
> The last line of stack trace shows that my code is actually enclosed in
> transaction managed by HibernateTransactionManager. There still must be
> some other difference between Teneo session factory config/behavior and
> Spring AnnotationSessionFactoryBean.
>
> Thanks,
> David
>
> Martin Taal wrote:
>> Hi David,
>> Maybe it is a default configuration setting difference, can you try
>> the following extra hibernate configuration setting:
>> <prop key="hibernate.current_session_context_class">thread</prop >
>> there are also two other values: jta and managed. I am not sure which
>> one would work with Spring transactional scopes.
>>
>> Let me know if this helped, or not...
>>
>> gr. Martin
>>
>> David Polách wrote:
>>> Hello, I'm facing problems with Spring managed Txs when working with
>>> HbSessionDataStore. Problem is caused by
>>> sessionFactory.getCurrentSession() failing in transactional scope. My
>>> session factory is configured in Spring context as HbSessionDataStore
>>> and transactions are provided by HibernateTransactionManager.
>>>
>>> When trying to save new entity to DB by invoking
>>> sessionFactory.getCurrentSession().saveOrUpdate(entity), test fails
>>> with org.hibernate.HibernateException: No CurrentSessionContext
>>> configured! This is strange since the call is in transactional scope.
>>> I've tried to setup transactions either with Spring
>>> TransactionTemplate or @Transactional annotation or AspectJ style is
>>> Spring context (none of it helped).
>>>
>>> When invoking the same test case with standard POJO entities and
>>> session factory configured with Spring AnnotationSessionFactoryBean
>>> (no Teneo), sessionFactory.getCurrentSession() returns working
>>> session and transaction commits without errors.
>>>
>>> Part of my spring context config follows:
>>>
>>> <bean id="sessionFactory"
>>> class="org.eclipse.emf.teneo.hibernate.HbSessionDataStore"
>>> init-method="initialize">
>>> <property name="name" value="test-store" />
>>> <property name="hibernateProperties">
>>> <props> <prop
>>> key="hibernate.dialect">${hibernate.dialect}</prop>
>>> <prop key="hibernate.show_sql">false</prop>
>>> <prop key="hibernate.hbm2ddl.auto">create</prop>
>>> <prop key="hibernate.generate_statistics">true</prop>
>>> <prop
>>> key="hibernate.connection.datasource">java:comp/env/jdbc/teneo </prop>
>>> </props>
>>> </property>
>>> <property name="EPackageClasses">
>>> <list>
>>> <value>eu.collectionspro.test.entity.impl.EntityPackageImpl </value>
>>> </list>
>>> </property> </bean>
>>>
>>> <bean id="transactionManager"
>>> class=" org.springframework.orm.hibernate3.HibernateTransactionManag er ">
>>> <property name="sessionFactory" ref="sessionFactory" />
>>> </bean>
>>>
>>> Thanks for help,
>>> David
>>
>>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
Re: [Teneo] CurrentSession problem with spring managed transactions [message #491321 is a reply to message #491199] |
Wed, 14 October 2009 07:17 |
david Messages: 61 Registered: July 2009 |
Member |
|
|
Hi Martin,
looks like we both find the same solution - correct hibernate property
setting is:
<prop
key="hibernate.current_session_context_class">org.springframework.orm.hibernate3.SpringSessionContext </prop>
I found this when debugging the Spring AnnotationSessionFactoryBean -
spring sets this property programatically when building spring managed
sessionFactory.
Thank you for your fast responses :)
David
Martin Taal wrote:
> Hi David,
> Did you try the managed option?
> A search on the internet also showed other options:
> http://histos.net/blog/2008/12/on-hibernate-spring-sessions- and-transactions.html
>
> (using a spring context)
>
> And this one (but it talks about the opposite, a Spring wrapped
> sessionfactory outside of a spring managed transaction, but maybe it
> gives usefull info):
> http://www.theresearchkitchen.com/blog/archives/73
>
> Let me know if this helps, otherwise I can try to reproduce it locally
> (with your help).
>
> gr. Martin
>
> David Polách wrote:
>> Hi Martin,
>>
>> thanks for hint but it did not help. I'm runnig my test locally so I
>> can't use JTA session context. Setting the
>> current_session_context_class to thread produces different exception:
>>
>> org.hibernate.HibernateException: saveOrUpdate is not valid without
>> active transaction
>> at
>> org.hibernate.context.ThreadLocalSessionContext$TransactionP rotectionWrapper.invoke(ThreadLocalSessionContext.java:338)
>>
>> at $Proxy4.saveOrUpdate(Unknown Source)
>> at eu.collectionspro.dao.GenDaoHib.save(GenDaoHib.java:47)
>> at
>> eu.collectionspro.test.PopulateDbTest$3.doInTransactionWitho utResult(PopulateDbTest.java:147)
>>
>> at
>> org.springframework.transaction.support.TransactionCallbackW ithoutResult.doInTransaction(TransactionCallbackWithoutResul t.java:33)
>>
>> at
>> org.springframework.transaction.support.TransactionTemplate. execute(TransactionTemplate.java:128)
>>
>>
>> The last line of stack trace shows that my code is actually enclosed
>> in transaction managed by HibernateTransactionManager. There still
>> must be some other difference between Teneo session factory
>> config/behavior and Spring AnnotationSessionFactoryBean.
>>
>> Thanks,
>> David
>>
>> Martin Taal wrote:
>>> Hi David,
>>> Maybe it is a default configuration setting difference, can you try
>>> the following extra hibernate configuration setting:
>>> <prop key="hibernate.current_session_context_class">thread</prop >
>>> there are also two other values: jta and managed. I am not sure which
>>> one would work with Spring transactional scopes.
>>>
>>> Let me know if this helped, or not...
>>>
>>> gr. Martin
>>>
>>> David Polách wrote:
>>>> Hello, I'm facing problems with Spring managed Txs when working with
>>>> HbSessionDataStore. Problem is caused by
>>>> sessionFactory.getCurrentSession() failing in transactional scope.
>>>> My session factory is configured in Spring context as
>>>> HbSessionDataStore and transactions are provided by
>>>> HibernateTransactionManager.
>>>>
>>>> When trying to save new entity to DB by invoking
>>>> sessionFactory.getCurrentSession().saveOrUpdate(entity), test fails
>>>> with org.hibernate.HibernateException: No CurrentSessionContext
>>>> configured! This is strange since the call is in transactional
>>>> scope. I've tried to setup transactions either with Spring
>>>> TransactionTemplate or @Transactional annotation or AspectJ style is
>>>> Spring context (none of it helped).
>>>>
>>>> When invoking the same test case with standard POJO entities and
>>>> session factory configured with Spring AnnotationSessionFactoryBean
>>>> (no Teneo), sessionFactory.getCurrentSession() returns working
>>>> session and transaction commits without errors.
>>>>
>>>> Part of my spring context config follows:
>>>>
>>>> <bean id="sessionFactory"
>>>> class="org.eclipse.emf.teneo.hibernate.HbSessionDataStore"
>>>> init-method="initialize">
>>>> <property name="name" value="test-store" />
>>>> <property name="hibernateProperties">
>>>> <props> <prop
>>>> key="hibernate.dialect">${hibernate.dialect}</prop>
>>>> <prop key="hibernate.show_sql">false</prop>
>>>> <prop key="hibernate.hbm2ddl.auto">create</prop>
>>>> <prop key="hibernate.generate_statistics">true</prop>
>>>> <prop
>>>> key="hibernate.connection.datasource">java:comp/env/jdbc/teneo </prop>
>>>> </props>
>>>> </property>
>>>> <property name="EPackageClasses">
>>>> <list>
>>>> <value>eu.collectionspro.test.entity.impl.EntityPackageImpl </value>
>>>> </list>
>>>> </property> </bean>
>>>>
>>>> <bean id="transactionManager"
>>>> class=" org.springframework.orm.hibernate3.HibernateTransactionManag er ">
>>>> <property name="sessionFactory" ref="sessionFactory" />
>>>> </bean>
>>>>
>>>> Thanks for help,
>>>> David
>>>
>>>
>
>
|
|
|
Re: [Teneo] CurrentSession problem with spring managed transactions [message #491330 is a reply to message #491321] |
Wed, 14 October 2009 07:40 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi David,
Thanks for letting us know that it works! I will probably add this somewhere in the docs.
gr. Martin
David Polách wrote:
> Hi Martin,
>
> looks like we both find the same solution - correct hibernate property
> setting is:
>
> <prop
> key="hibernate.current_session_context_class">org.springframework.orm.hibernate3.SpringSessionContext </prop>
>
>
> I found this when debugging the Spring AnnotationSessionFactoryBean -
> spring sets this property programatically when building spring managed
> sessionFactory.
>
> Thank you for your fast responses :)
> David
>
> Martin Taal wrote:
>> Hi David,
>> Did you try the managed option?
>> A search on the internet also showed other options:
>> http://histos.net/blog/2008/12/on-hibernate-spring-sessions- and-transactions.html
>>
>> (using a spring context)
>>
>> And this one (but it talks about the opposite, a Spring wrapped
>> sessionfactory outside of a spring managed transaction, but maybe it
>> gives usefull info):
>> http://www.theresearchkitchen.com/blog/archives/73
>>
>> Let me know if this helps, otherwise I can try to reproduce it locally
>> (with your help).
>>
>> gr. Martin
>>
>> David Polách wrote:
>>> Hi Martin,
>>>
>>> thanks for hint but it did not help. I'm runnig my test locally so I
>>> can't use JTA session context. Setting the
>>> current_session_context_class to thread produces different exception:
>>>
>>> org.hibernate.HibernateException: saveOrUpdate is not valid without
>>> active transaction
>>> at
>>> org.hibernate.context.ThreadLocalSessionContext$TransactionP rotectionWrapper.invoke(ThreadLocalSessionContext.java:338)
>>>
>>> at $Proxy4.saveOrUpdate(Unknown Source)
>>> at eu.collectionspro.dao.GenDaoHib.save(GenDaoHib.java:47)
>>> at
>>> eu.collectionspro.test.PopulateDbTest$3.doInTransactionWitho utResult(PopulateDbTest.java:147)
>>>
>>> at
>>> org.springframework.transaction.support.TransactionCallbackW ithoutResult.doInTransaction(TransactionCallbackWithoutResul t.java:33)
>>>
>>> at
>>> org.springframework.transaction.support.TransactionTemplate. execute(TransactionTemplate.java:128)
>>>
>>>
>>> The last line of stack trace shows that my code is actually enclosed
>>> in transaction managed by HibernateTransactionManager. There still
>>> must be some other difference between Teneo session factory
>>> config/behavior and Spring AnnotationSessionFactoryBean.
>>>
>>> Thanks,
>>> David
>>>
>>> Martin Taal wrote:
>>>> Hi David,
>>>> Maybe it is a default configuration setting difference, can you try
>>>> the following extra hibernate configuration setting:
>>>> <prop key="hibernate.current_session_context_class">thread</prop >
>>>> there are also two other values: jta and managed. I am not sure
>>>> which one would work with Spring transactional scopes.
>>>>
>>>> Let me know if this helped, or not...
>>>>
>>>> gr. Martin
>>>>
>>>> David Polách wrote:
>>>>> Hello, I'm facing problems with Spring managed Txs when working
>>>>> with HbSessionDataStore. Problem is caused by
>>>>> sessionFactory.getCurrentSession() failing in transactional scope.
>>>>> My session factory is configured in Spring context as
>>>>> HbSessionDataStore and transactions are provided by
>>>>> HibernateTransactionManager.
>>>>>
>>>>> When trying to save new entity to DB by invoking
>>>>> sessionFactory.getCurrentSession().saveOrUpdate(entity), test fails
>>>>> with org.hibernate.HibernateException: No CurrentSessionContext
>>>>> configured! This is strange since the call is in transactional
>>>>> scope. I've tried to setup transactions either with Spring
>>>>> TransactionTemplate or @Transactional annotation or AspectJ style
>>>>> is Spring context (none of it helped).
>>>>>
>>>>> When invoking the same test case with standard POJO entities and
>>>>> session factory configured with Spring
>>>>> AnnotationSessionFactoryBean (no Teneo),
>>>>> sessionFactory.getCurrentSession() returns working session and
>>>>> transaction commits without errors.
>>>>>
>>>>> Part of my spring context config follows:
>>>>>
>>>>> <bean id="sessionFactory"
>>>>> class="org.eclipse.emf.teneo.hibernate.HbSessionDataStore"
>>>>> init-method="initialize">
>>>>> <property name="name" value="test-store" />
>>>>> <property name="hibernateProperties">
>>>>> <props> <prop
>>>>> key="hibernate.dialect">${hibernate.dialect}</prop>
>>>>> <prop key="hibernate.show_sql">false</prop>
>>>>> <prop key="hibernate.hbm2ddl.auto">create</prop>
>>>>> <prop key="hibernate.generate_statistics">true</prop>
>>>>> <prop
>>>>> key="hibernate.connection.datasource">java:comp/env/jdbc/teneo </prop>
>>>>> </props>
>>>>> </property>
>>>>> <property name="EPackageClasses">
>>>>> <list>
>>>>> <value>eu.collectionspro.test.entity.impl.EntityPackageImpl </value>
>>>>> </list>
>>>>> </property> </bean>
>>>>>
>>>>> <bean id="transactionManager"
>>>>> class=" org.springframework.orm.hibernate3.HibernateTransactionManag er ">
>>>>>
>>>>> <property name="sessionFactory" ref="sessionFactory" />
>>>>> </bean>
>>>>>
>>>>> Thanks for help,
>>>>> David
>>>>
>>>>
>>
>>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
Goto Forum:
Current Time: Thu Apr 25 05:45:45 GMT 2024
Powered by FUDForum. Page generated in 0.03520 seconds
|