Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Test works under JTA but not JPA transactions
Test works under JTA but not JPA transactions [message #382744] Sat, 18 October 2008 02:37 Go to next message
Douglas Hammond is currently offline Douglas HammondFriend
Messages: 8
Registered: July 2009
Junior Member
I have the following test

Person person = new Person();
person.setCommonName("Test Person one");
person.setFirstName("Test");
person.setLastName("Person");
person = personService.save(person);

log.debug("GOT PERSON ID: " + person.getId().toString());
Assert.assertNotNull(person.getId());

Person loadedPerson = personService.getPerson(person.getId());
Assert.assertNotNull(loadedPerson.getId());

It works fine under the JTA transaction manager but as RESOURCE_LOCAL it
fails on the getPerson. I am running under the spring transaction manager.

I get this exception

[main] DEBUG com.travelonly.test.PersonServiceTest - GOT PERSON ID: 138
[main] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Using
transaction object
[org.springframework.orm.jpa.JpaTransactionManager$JpaTransactionObject@1304043]
[main] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Creating
new transaction with name [com.test.service.PersonService.getPerson]:
PROPAGATION_REQUIRED,ISOLATION_DEFAULT
[main] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Opened
new EntityManager
[org.eclipse.persistence.internal.jpa.EntityManagerImpl@cb07ef] for JPA
transaction
[main] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Exposing
JPA transaction as JDBC transaction [SimpleConnectionHandle:
jdbc:postgresql://localhost/dev, UserName=dev, PostgreSQL Native Driver]
[main] DEBUG
org.springframework.transaction.support.TransactionSynchroni zationManager
- Bound value
[org.springframework.jdbc.datasource.ConnectionHolder@176086d] for key
[org.apache.commons.dbcp.BasicDataSource@1df2964] to thread [main]
[main] DEBUG
org.springframework.transaction.support.TransactionSynchroni zationManager
- Bound value [org.springframework.orm.jpa.EntityManagerHolder@234265] for
key
[ org.springframework.orm.jpa.LocalContainerEntityManagerFacto ryBean @cc7439]
to thread [main]
[main] DEBUG
org.springframework.transaction.support.TransactionSynchroni zationManager
- Initializing transaction synchronization
[main] DEBUG
org.springframework.transaction.support.TransactionSynchroni zationManager
- Retrieved value [org.springframework.orm.jpa.EntityManagerHolder@234265]
for key
[ org.springframework.orm.jpa.LocalContainerEntityManagerFacto ryBean @cc7439]
bound to thread [main]
[main] DEBUG org.springframework.orm.jpa.JpaTransactionManager -
Triggering beforeCommit synchronization
[main] DEBUG org.springframework.orm.jpa.JpaTransactionManager -
Triggering beforeCompletion synchronization
[main] DEBUG org.springframework.orm.jpa.JpaTransactionManager -
Initiating transaction commit
[main] DEBUG org.springframework.orm.jpa.JpaTransactionManager -
Committing JPA transaction on EntityManager
[org.eclipse.persistence.internal.jpa.EntityManagerImpl@cb07ef]
[EL Warning]: Exception [EclipseLink-7197] (Eclipse Persistence Services -
1.0.1 (Build 20080905)):
org.eclipse.persistence.exceptions.ValidationException
Exception Description: Null primary key encountered in unit of work clone
[com.test.model.User@1758cd1[id=<null>]].
[main] DEBUG org.springframework.orm.jpa.JpaTransactionManager -
Triggering afterCompletion synchronization
[main] DEBUG
org.springframework.transaction.support.TransactionSynchroni zationManager
- Clearing transaction synchronization
[main] DEBUG
org.springframework.transaction.support.TransactionSynchroni zationManager
- Removed value [org.springframework.orm.jpa.EntityManagerHolder@234265]
for key
[ org.springframework.orm.jpa.LocalContainerEntityManagerFacto ryBean @cc7439]
from thread [main]
[main] DEBUG
org.springframework.transaction.support.TransactionSynchroni zationManager
- Removed value
[org.springframework.jdbc.datasource.ConnectionHolder@176086d] for key
[org.apache.commons.dbcp.BasicDataSource@1df2964] from thread [main]
[main] DEBUG org.springframework.orm.jpa.JpaTransactionManager - Closing
JPA EntityManager
[org.eclipse.persistence.internal.jpa.EntityManagerImpl@cb07ef] after
transaction
[main] DEBUG org.springframework.orm.jpa.EntityManagerFactoryUtils -
Closing JPA EntityManager


I can't figure out how the id is null when it confirms that the person has
an id = 138 in this case.


Is it a spring problem?
Re: Test works under JTA but not JPA transactions [message #382746 is a reply to message #382744] Sat, 18 October 2008 13:20 Go to previous messageGo to next message
Gordon Yorke is currently offline Gordon YorkeFriend
Messages: 78
Registered: July 2009
Member
The error is reported on a User entity :
com.test.model.User@1758cd1[id=<null>]
What does the method personService.getPerson() do?
--Gordon
Re: Test works under JTA but not JPA transactions [message #382748 is a reply to message #382746] Sat, 18 October 2008 13:45 Go to previous messageGo to next message
Douglas Hammond is currently offline Douglas HammondFriend
Messages: 8
Registered: July 2009
Junior Member
Here is what it does

@Override
@Transactional
public Person getPerson(Long id) {
return entityManager.find(Person.class, id);
}

Pretty straight forward I think.

It is odd it works fine in a JTA transaction and not under resource_local
and spring JpaTransactionManager.

I did get it to work but I had to mark it with @Transactional(propagation=
Propagation.NOT_SUPPORTED). Which is strange as one would think it should
with or without a transaction as it it a select.
Re: Test works under JTA but not JPA transactions [message #382749 is a reply to message #382744] Mon, 20 October 2008 01:02 Go to previous message
Douglas Hammond is currently offline Douglas HammondFriend
Messages: 8
Registered: July 2009
Junior Member
I found my problem though I am not sure why it worked under JTA
transactions and not resource_local

I have a user helper class that holds the current user for adding cratedBy
user to audited entities.

I did not merge the user into the current entitymanager so this led to the
null id I guess.
Previous Topic:Mapping a lookup table
Next Topic:DescriptorEventAdapter merging and object
Goto Forum:
  


Current Time: Fri Mar 29 00:24:01 GMT 2024

Powered by FUDForum. Page generated in 0.03601 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top