This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

CMT: Container Management Transaction  RSS feed

 
dhouafli mohamed
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
i try to practice EJB3.0 transactions, i use the CMT mode (declarative) so :

I create my EJB with entites and I use the entityManager to manage data
I use the annotations
I have amready created two methods in the implementation classes :

there are my methods

@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void ajouterClient(Client Client) {

em.persist(Client);
}
@TransactionAttribute(TransactionAttributeType.REQUIRED)
public void createReservations(Reservations reservations) throws Exception{
System.out.println("entities saved");
em.persist(reservations);
}

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void reservation(Client client, Reservations reservation) throws Exception{

this.ajouterClient(client);
reservationsFacade.createReservations(reservation);

}

it seems to be correct, there is no compilation error either execution error, but I when call the reservation method I try to force the roll back in the container wiyh the method creatReservation, but ther is no roll bacj the insertion of the client is finished correctly.
NB : the transaction should be managed implicitly by the EJBcontainer (it use the method SetRollBackonlly() )

is there an body that have an idea how the container managed the transactions and was is wrong in my code !!

thank you !


 
Manuel Alberto Quero
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Notice that if you want the EJB container to be aware of transactions annotations (actually, any method annotation), you must invoke the methods as follows:

1- You can use a reference to itself using Dependency Injection:


2- Or you can use the SessionContext interface:


If you use the "this" keyword, the container will ignore transaction annotations.

Hope this helps,

Manuel
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!