Skip to content

JPA Extended Persistence Context #88

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
arun-gupta opened this issue Nov 9, 2013 · 4 comments
Open

JPA Extended Persistence Context #88

arun-gupta opened this issue Nov 9, 2013 · 4 comments
Assignees

Comments

@arun-gupta
Copy link
Contributor

No description provided.

@ghost ghost assigned arun-gupta Nov 9, 2013
@arun-gupta
Copy link
Contributor Author

Added jpa/extended-pc

@arun-gupta
Copy link
Contributor Author

Needs further investigation. Entites are committed even when outside a transaction. Is that the expected behavior ?

@arun-gupta arun-gupta reopened this Nov 9, 2013
@kornelrabczak
Copy link
Contributor

Hi Arun,

from my investigation: it looks like when we calling persistWithoutTransaction, method is without transaction context and employee entity is not persisted to the database, but stays in Persistence Context. When there is no JTA transaction, the Persistence Context is not propagated, outside of a transaction inserts, updates and deletes will be queued until you access the persistence context within a transaction. Extended Persistence Context is created once only and is used for every transaction within the scope of the class. Next when calling get where Entity Manager is invoked within transaction what means our Extended Persistence Context will be bound to this transaction and employee entity from previous call which is located in Persistence Context should be persisted into database.

Solution would be setting annotation @TransactionAttribute(TransactionAttributeType.NEVER) for class scope. In that case invoking get method has no influence for employee entity in Persistence Context because none JTA transaction will be bound with Extended Persistence Context.

I’ve created arquilian test for this sample and made some changes in your code. Tests for now works only with wildfly-managed-arquillian profile. What is the policy of writing arquillian tests for JPA samples ? Should tests cover every maven profile ? For example: glassfish-embedded profile needs a little different persistence.xml than wildfly-managed and defined datasource configuration.

kornelrabczak@0caff5a

Best regards,
Korneliusz Rabczak

@kornelrabczak
Copy link
Contributor

@arun-gupta i have made some changes to make this more visual and straightforward

https://github.com/nikom1337/javaee7-samples/blob/jpa-extended-pc/jpa/extended-pc/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants