Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » [Texo] Getting started, JEE/JTA-Transactions & Persistence
[Texo] Getting started, JEE/JTA-Transactions & Persistence [message #891793] Mon, 25 June 2012 22:26 Go to next message
Jon Doe is currently offline Jon Doe
Messages: 4
Registered: June 2012
Junior Member
Hello,

after having learned how to (successfully) generate my entities, the DAOs and stuff from my ecore-diagram, I'm stuck trying to deploy the servlets as in "org.eclipse.texo.web.example" to a Glassfish-instance.

My attempts setting the EntityManagerFactory to an injected @PersistenceUnit fail with

Quote:

Exception Description: Cannot use an EntityTransaction while using JTA.
at org.eclipse.persistence.internal.jpa.transaction.JTATransactionWrapper.getTransaction(JTATransactionWrapper.java:65)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.getTransaction(EntityManagerImpl.java:1192)
at org.eclipse.emf.texo.server.store.EntityManagerObjectStore.begin(EntityManagerObjectStore.java:209)
at org.eclipse.emf.texo.server.service.ModelOperation.execute(ModelOperation.java:46)
at org.eclipse.emf.texo.server.web.WebServiceHandler.doGet(WebServiceHandler.java:89)
at org.eclipse.emf.texo.server.web.WebServiceServlet.doGet(WebServiceServlet.java:57)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)


How do I correctly setup things to support JTA-transactions, if that is supported at all?


Regards,
Jon


Versions:
eclipse 3.7.2,
teneo_1.1.2.v201006151458,
texo_0.1.0.v201206130437,
glassfish 3.1.2



Re: [Texo] Getting started, JEE/JTA-Transactions & Persistence [message #891872 is a reply to message #891793] Tue, 26 June 2012 07:45 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5049
Registered: July 2009
Senior Member
He Jon,
Indeed this needs to be extended/changed, you configure the JTA transactions using jndi?

Maybe you want to help to get this working for Texo. The idea is to implement a subclass of EntityManagerObjectStore and
override the begin, commit and rollback methods. These methods should then work in the correct way for JTA (either start
a new transaction or join a transaction). Then you can tell Texo to use the JTAEntityManagerObjectStore by doing this
when the application starts:
ComponentProvider.getInstance().register(EntityManagerObjectStore.class, JTAEntityManagerObjectStore.class);

Let me know what you think about this.

gr. Martin

On 06/26/2012 04:26 AM, Jon Doe wrote:
> Hello,
>
> after having learned how to (successfully) generate my entities, the DAOs and stuff from my ecore-diagram, I'm stuck
> trying to deploy the servlets as in "org.eclipse.texo.web.example" to a Glassfish-instance.
>
> My attempts setting the EntityManagerFactory to an injected @PersistenceUnit fail with
> Quote:
>> Exception Description: Cannot use an EntityTransaction while using JTA.
>> at org.eclipse.persistence.internal.jpa.transaction.JTATransactionWrapper.getTransaction(JTATransactionWrapper.java:65)
>> at org.eclipse.persistence.internal.jpa.EntityManagerImpl.getTransaction(EntityManagerImpl.java:1192)
>> at org.eclipse.emf.texo.server.store.EntityManagerObjectStore.begin(EntityManagerObjectStore.java:209)
>> at org.eclipse.emf.texo.server.service.ModelOperation.execute(ModelOperation.java:46)
>> at org.eclipse.emf.texo.server.web.WebServiceHandler.doGet(WebServiceHandler.java:89)
>> at org.eclipse.emf.texo.server.web.WebServiceServlet.doGet(WebServiceServlet.java:57)
>> at javax.servlet.http.HttpServlet.service(HttpServlet.java:668)
>
>
> How do I correctly setup things to support JTA-transactions, if that is supported at all?
>
>
> Regards,
> Jon
>
>
> Versions: eclipse 3.7.2, teneo_1.1.2.v201006151458,
> texo_0.1.0.v201206130437, glassfish 3.1.2
>
>
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] Getting started, JEE/JTA-Transactions & Persistence [message #891880 is a reply to message #891872] Tue, 26 June 2012 08:22 Go to previous messageGo to next message
Jon Doe is currently offline Jon Doe
Messages: 4
Registered: June 2012
Junior Member
Hi Martin,

nice to hear that I was not entirely wrong when deriving from EntityManagerObjectStore, overriding the suspicious [begin|close|commit|rollback] methods and registering it in the ComponentProvider.

So far I just made those methods empty, except calling setRollbackOnly() in rollback -- and there's response from the webservice-servlets now :-).

I'm not sure if I understand enough about container-side transaction-handling to implement this in a really clean way, but I'd be happy to give back to this project!

Regards,
Jon


Martin taal wrote on Tue, 26 June 2012 07:45
He Jon,
Indeed this needs to be extended/changed, you configure the JTA transactions using jndi?

Maybe you want to help to get this working for Texo. The idea is to implement a subclass of EntityManagerObjectStore and
override the begin, commit and rollback methods. These methods should then work in the correct way for JTA (either start
a new transaction or join a transaction). Then you can tell Texo to use the JTAEntityManagerObjectStore by doing this
when the application starts:
ComponentProvider.getInstance().register(EntityManagerObjectStore.class, JTAEntityManagerObjectStore.class);

Let me know what you think about this.

gr. Martin


Re: [Texo] Getting started, JEE/JTA-Transactions & Persistence [message #891906 is a reply to message #891880] Tue, 26 June 2012 09:36 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5049
Registered: July 2009
Senior Member
Hi Jon,
You were entirely correct in this approach :-). I think if the transaction is managed by the container then the object
store should not touch it. So looks fine to me. You can try to update through the webservice and see if the transaction
commits.

But if the transaction is/should be managed by the objectstore then something like this can maybe work:

public class JTAEntityManagerObjectStore {

private UserTransaction userTransaction;

public void begin() {
InitialContext initCtx = new InitialContext();
userTransaction = (UserTransaction)initCtx.lookup(
"java:comp/UserTransaction");
userTransaction.begin();
getEntityManager().joinTransaction();
}

public void commit() {
userTransaction.commit();
}

public void rollback() {
userTransaction.rollback();
}

public void close() {
userTransaction = null;
super.close();
}
}

On 06/26/2012 02:22 PM, Jon Doe wrote:
> Hi Martin,
>
> nice to hear that I was not entirely wrong when deriving from EntityManagerObjectStore, overriding the suspicious
> [begin|close|commit|rollback] methods and registering it in the ComponentProvider.
>
> So far I just made those methods empty, except calling setRollbackOnly() in rollback -- and there's response from the
> webservice-servlets now :-).
>
> I'm not sure if I understand enough about container-side transaction-handling to implement this in a really clean way,
> but I'd be happy to give back to this project!
>
> Regards,
> Jon
>
>
> Martin taal wrote on Tue, 26 June 2012 07:45
>> He Jon,
>> Indeed this needs to be extended/changed, you configure the JTA transactions using jndi?
>>
>> Maybe you want to help to get this working for Texo. The idea is to implement a subclass of EntityManagerObjectStore
>> and override the begin, commit and rollback methods. These methods should then work in the correct way for JTA (either
>> start a new transaction or join a transaction). Then you can tell Texo to use the JTAEntityManagerObjectStore by doing
>> this when the application starts:
>> ComponentProvider.getInstance().register(EntityManagerObjectStore.class, JTAEntityManagerObjectStore.class);
>>
>> Let me know what you think about this.
>>
>> gr. Martin
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] Getting started, JEE/JTA-Transactions & Persistence [message #891907 is a reply to message #891906] Tue, 26 June 2012 09:56 Go to previous messageGo to next message
Jon Doe is currently offline Jon Doe
Messages: 4
Registered: June 2012
Junior Member
Hi Martin,

thanks, I'll try my best to include these improvements.

But first - "Getting started some more":
Can you point me to any client-side example for consuming the (now working) webservices? :)
I'm not sure if JSONTexoResource is already finished [getting UnsupportedOperationExceptions], and I have to admit that I can't make sense of "org.eclipse.emf.texo.example1.rcp"..

Regards,
Jon

P.S.:
Forgive my ignorance - as you might have guessed the entire EMF-universe is new to me, and things are slightly overwhelming/confusing..


Martin taal wrote on Tue, 26 June 2012 09:36
Hi Jon,
You were entirely correct in this approach :-). I think if the transaction is managed by the container then the object
store should not touch it. So looks fine to me. You can try to update through the webservice and see if the transaction
commits.

But if the transaction is/should be managed by the objectstore then something like this can maybe work:

public class JTAEntityManagerObjectStore {

private UserTransaction userTransaction;

public void begin() {
InitialContext initCtx = new InitialContext();
userTransaction = (UserTransaction)initCtx.lookup(
"java:comp/UserTransaction");
userTransaction.begin();
getEntityManager().joinTransaction();
}

public void commit() {
userTransaction.commit();
}

public void rollback() {
userTransaction.rollback();
}

public void close() {
userTransaction = null;
super.close();
}
}

Re: [Texo] Getting started, JEE/JTA-Transactions & Persistence [message #891912 is a reply to message #891907] Tue, 26 June 2012 10:14 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5049
Registered: July 2009
Senior Member
He Jon,
No problem, you can ask anything you want!

You maybe have seen this blog post:
http://martintaal.wordpress.com/2012/05/09/emft-texo-model-driven-rcp-using-texo-generated-jpa-entities/

The JSONTexoResource is not yet implemented, it is a to-do for me to get this done.... Will be a few weeks before I have
more time for it...

So maybe you can make use of the TexoResource as it is described in the blog post.

The example1.rcp makes use of the EPersistenceService for retrieving EObjects through jpa.

gr. Martin

On 06/26/2012 03:56 PM, Jon Doe wrote:
> Hi Martin,
>
> thanks, I'll try my best to include these improvements.
>
> But first - "Getting started some more":
> Can you point me to any client-side example for consuming the (now working) webservices? :)
> I'm not sure if JSONTexoResource is already finished [getting UnsupportedOperationExceptions], and I have to admit that
> I can't make sense of "org.eclipse.emf.texo.example1.rcp"..
> Regards,
> Jon
>
> P.S.:
> Forgive my ignorance - as you might have guessed the entire EMF-universe is new to me, and things are slightly
> overwhelming/confusing..
>
>
> Martin taal wrote on Tue, 26 June 2012 09:36
>> Hi Jon,
>> You were entirely correct in this approach :-). I think if the transaction is managed by the container then the object
>> store should not touch it. So looks fine to me. You can try to update through the webservice and see if the
>> transaction commits.
>>
>> But if the transaction is/should be managed by the objectstore then something like this can maybe work:
>>
>> public class JTAEntityManagerObjectStore {
>>
>> private UserTransaction userTransaction;
>>
>> public void begin() {
>> InitialContext initCtx = new InitialContext();
>> userTransaction = (UserTransaction)initCtx.lookup(
>> "java:comp/UserTransaction");
>> userTransaction.begin();
>> getEntityManager().joinTransaction();
>> }
>>
>> public void commit() {
>> userTransaction.commit();
>> }
>>
>> public void rollback() {
>> userTransaction.rollback();
>> }
>>
>> public void close() {
>> userTransaction = null;
>> super.close();
>> }
>> }
>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: [Texo] Getting started, JEE/JTA-Transactions & Persistence [message #892023 is a reply to message #891912] Tue, 26 June 2012 16:54 Go to previous message
Jon Doe is currently offline Jon Doe
Messages: 4
Registered: June 2012
Junior Member
'lo Martin,

ok, so I'll try to get even more started with TexoResource and see how far I'll get.
Eventually this teaches me enough about the matter to support the JSONTexoResource-Implementation.

For now a big ThankYou for your time -- expect further questions soon :)

Regards,
Jon


Martin taal wrote on Tue, 26 June 2012 10:14
He Jon,
No problem, you can ask anything you want!

You maybe have seen this blog post:
i'm not allowed to post links

The JSONTexoResource is not yet implemented, it is a to-do for me to get this done.... Will be a few weeks before I have
more time for it...

So maybe you can make use of the TexoResource as it is described in the blog post.

The example1.rcp makes use of the EPersistenceService for retrieving EObjects through jpa.

Previous Topic:How to Document MWE and XPT Files
Next Topic:my EMF model generated tests...
Goto Forum:
  


Current Time: Sat May 18 21:16:53 EDT 2013

Powered by FUDForum. Page generated in 0.02495 seconds