Re: RE: RE: RE: Pb. while searching entitybeans via the entitymanager.

Florent BENOIT <[email protected]> Tue, 26 Jul 2011 14:01:35 +0200
Newsgroups gmane.comp.java.objectweb.jonas
Message-ID <[email protected]>
     Hi,

The transaction will begin when the foo() method is called and will be 
committed at the end of the method
And even if you call flush() method 500 times, the DB will receive data 
only at the commit on the TX.
So maybe that the JMS message is handled before the end of the foo() 
method (I don't know what you do after 
this.clusterManager.createImageFromVirtualMachine() but if it take time, 
the first TX may not be committed before the new transaction that is 
started by the MDB.

So maybe to better handle the problem, you could try some stuff :

1/ Change TX on the foo() method so that you don't have any TX so the DB 
is updated when you flush the EntityManager

or

2/ Handle yourself the TX by using BeanManaged Transaction (and you 
should commit the TX just after the em.persist() call so you're sure 
data are in the database.

or

3/ Split foo method into 2 methods so that you'll have one method that 
will persist data and a new method that will call the clusterManager API


Regards,

Florent


On 07/25/2011 05:46 PM, [email protected] wrote:
>
> Hi ,
>
> I am facing the same problem in a Stateless SB, here is a concrete 
> example with Java code (in Jonas 5.2.1) :
>
> /Method foo  { /
>
> /VMImage image = new VMImage();/
>
> /        image.setStatus(VMImage.Status.IN_CONSTRUCTION);/
>
> /                .../
>
> /        this.em.persist(image);/
>
> /        this.em.flush();/
>
> /        try {/
>
> /            
> this.clusterManager.createImageFromVirtualMachine(vs.getProviderId(), 
> image.getId(), name, description);/
>
> /                .../
>
> /}/
>
> The method createImageFromVirtualMachine emits a JMS message which is 
> handled here:
>
> /public void onMessage(final Message msg) {/
>
> /(some code)/
>
> /                VMImage image = this.em.find(VMImage.class, vmiId); /
>
> /}/
>
> Image is null whereas I can see the record in MySQL database...
>
> What is wrong with the code above ?
>
> Thanks a lot,
>
> Serge
>
> *De :* [email protected] 
> [mailto:[email protected]]
> *Envoyé :* mercredi 20 juillet 2011 18:06
> *À :* [email protected]
> *Cc :* CHAZALET Antonin NRS
> *Objet :* [jonas] RE: RE: Pb. while searching entitybeans via the 
> entitymanager.
>
> Ok.
>
> In my conf., easybeans-jonas.xml is the default one, and 
> jonas.properties's transaction part uses also the default conf.
>
> So, I think that the container creates the transaction for me.
>
> Does putting a transaction around createAComposite, and a transaction 
> around createAComponent will solve my pb. ?
>
> (What is the easiest way to define transaction ?)
>
> Thanks,
>
> Regards,
>
> Antonin.
>
> *De :* [email protected] [mailto:[email protected]] *De la 
> part de* Guillaume Sauthier (OW2)
> *Envoyé :* mercredi 20 juillet 2011 17:51
> *À :* [email protected]
> *Cc :* CHAZALET Antonin NRS
> *Objet :* Re: [jonas] RE: Pb. while searching entitybeans via the 
> entitymanager.
>
> By default it is REQUIRED.
>
> That means that if a transaction is not already present, the container 
> creates a new transaction for you (and commit at the end of the 
> method). Otherwise, the code "join" the existing transaction (no 
> begin/commit at start/end of the method).
>
> --G
>
> 2011/7/20 <[email protected] 
> <mailto:[email protected]>>
>
> Guillaume,
>
> I don't know :-|
>
> Is there any default transactional behaviour defined for the 
> applications ? In Jonas ?
>
> Where can I find my transaction configuration ?
>
> Thanks,
>
> Regards,
>
> Antonin.
>
> *De :* [email protected] <mailto:[email protected]> 
> [mailto:[email protected] <mailto:[email protected]>] *De 
> la part de* Guillaume Sauthier (OW2)
> *Envoyé :* mercredi 20 juillet 2011 17:30
>
>
> *À :* [email protected] <mailto:[email protected]>
> *Cc :* CHAZALET Antonin NRS
>
> *Objet :* Re: [jonas] Pb. while searching entitybeans via the 
> entitymanager.
>
> How do you manage your transactions ?
> --G
>
> 2011/7/20 <[email protected] 
> <mailto:[email protected]>>
>
> Dear,
>
> I have problem with my EJB3 application.
>
> I have a remote client that calls a statelessbean in order to 
> createAComposite.
>
> The createAComposite method itself calls, several times, a second 
> statelessbean in order to create the composite's components. (This 
> second statelessbean atcs as a component manager.)
>
> Each component creation is persisted, and flushed in DB (the 
> corresponding lines appear in DB).
>
> Once the components' creation is done, createAComposite searches in DB 
> for the just created components, and find nothing.
>
> (I need to retrieve the just created components in order to define 
> several associations within components, and with others entity objects.)
>
> I don't understand my mistake, can you help me ?
>
> I use JOnAS 5.2-RC1.
>
> Thanks,
>
> Regards,
>
> Antonin.
>
> ********************************************************************************
> IMPORTANT.Les informations contenues dans ce message electronique y compris les fichiers attaches sont strictement confidentielles
> et peuvent etre protegees par la loi.
>   
> Ce message electronique est destine exclusivement au(x) destinataire(s) mentionne(s) ci-dessus.
> Si vous avez recu ce message par erreur ou s il ne vous est pas destine, veuillez immediatement le signaler  a l expediteur et effacer ce message
> et tous les fichiers eventuellement attaches.
> Toute lecture, exploitation ou transmission des informations contenues dans ce message est interdite.
> Tout message electronique est susceptible d alteration.
> A ce titre, le Groupe France Telecom decline toute responsabilite notamment s il a ete altere, deforme ou falsifie.
> De meme, il appartient au destinataire de s assurer de l absence de tout virus.
>   
> IMPORTANT.This e-mail message and any attachments are strictly confidential and may be protected by law. This message is
> intended only for the named recipient(s) above.
> If you have received this message in error, or are not the named recipient(s), please immediately notify the sender and delete this e-mail message.
> Any unauthorized view, usage or disclosure ofthis message is prohibited.
> Since e-mail messages may not be reliable, France Telecom Group shall not be liable for any message if modified, changed or falsified.
> Additionally the recipient should ensure they are actually virus free.
> ********************************************************************************
>
> ********************************************************************************
> IMPORTANT.Les informations contenues dans ce message electronique y compris les fichiers attaches sont strictement confidentielles
> et peuvent etre protegees par la loi.
> Ce message electronique est destine exclusivement au(x) destinataire(s) mentionne(s) ci-dessus.
> Si vous avez recu ce message par erreur ou s il ne vous est pas destine, veuillez immediatement le signaler  a l expediteur et effacer ce message
> et tous les fichiers eventuellement attaches.
> Toute lecture, exploitation ou transmission des informations contenues dans ce message est interdite.
> Tout message electronique est susceptible d alteration.
> A ce titre, le Groupe France Telecom decline toute responsabilite notamment s il a ete altere, deforme ou falsifie.
> De meme, il appartient au destinataire de s assurer de l absence de tout virus.
>   
> IMPORTANT.This e-mail message and any attachments are strictly confidential and may be protected by law. This message is
> intended only for the named recipient(s) above.
> If you have received this message in error, or are not the named recipient(s), please immediately notify the sender and delete this e-mail message.
> Any unauthorized view, usage or disclosure ofthis message is prohibited.
> Since e-mail messages may not be reliable, France Telecom Group shall not be liable for any message if modified, changed or falsified.
> Additionally the recipient should ensure they are actually virus free.
> ********************************************************************************
>
> ********************************************************************************
> IMPORTANT.Les informations contenues dans ce message electronique y compris les fichiers attaches sont strictement confidentielles
> et peuvent etre protegees par la loi.
> Ce message electronique est destine exclusivement au(x) destinataire(s) mentionne(s) ci-dessus.
> Si vous avez recu ce message par erreur ou s il ne vous est pas destine, veuillez immediatement le signaler  a l expediteur et effacer ce message
> et tous les fichiers eventuellement attaches.
> Toute lecture, exploitation ou transmission des informations contenues dans ce message est interdite.
> Tout message electronique est susceptible d alteration.
> A ce titre, le Groupe France Telecom decline toute responsabilite notamment s il a ete altere, deforme ou falsifie.
> De meme, il appartient au destinataire de s assurer de l absence de tout virus.
>   
> IMPORTANT.This e-mail message and any attachments are strictly confidential and may be protected by law. This message is
> intended only for the named recipient(s) above.
> If you have received this message in error, or are not the named recipient(s), please immediately notify the sender and delete this e-mail message.
> Any unauthorized view, usage or disclosure ofthis message is prohibited.
> Since e-mail messages may not be reliable, France Telecom Group shall not be liable for any message if modified, changed or falsified.
> Additionally the recipient should ensure they are actually virus free.
> ********************************************************************************