• Post Reply Bookmark Topic Watch Topic
  • New Topic

Persisting 2 entities using JPA  RSS feed

 
Skumar kotika
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,



Am new to EJB and trying the below scenario.

Below is my use case and am facing difficulty in accomplishing this.

i need to persist some data for an entity and using the data from this entity i need to persist data into a history table (insert a new row for each column present in my first entity).

Am trying to persist 2 entities in a single transaction, below is the flow that am using.



in bean1:





in bean2:




while running the process, it gives me the below error:



java.lang.IllegalStateException: The transaction associated with this transaction-scoped persistence context has been rolled back and as a result,

the EntityManager has been closed. No further operations are allowed in this transaction context. Please see the server log for the cause of the rollback.



request you to help me with the above issue.
 
Mark Spencers
Ranch Hand
Posts: 51
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on transaction attribute you are using. This tutorial explains all transaction attributes for container managed transaction

In bean managed transaction you explicitly start , commit and rollback transaction. This tutorial can help
 
Skumar kotika
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
am using the following transaction attributes in my 2nd bean.

@TransactionManagement(TransactionManagementType.CONTAINER)

and at the method
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)

even after using the transaction attribute, i still get the illegalstateexception.
 
Mark Spencers
Ranch Hand
Posts: 51
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try to use TransactionAttributeType.REQUIRED and maybe there is exception in bean1.method1?
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!