Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc) » [Texo] Getting started, JEE/JTA-Transactions & Persistence
[Texo] Getting started, JEE/JTA-Transactions & Persistence [message #891793] |
Tue, 26 June 2012 02:26 |
Jon Doe Messages: 7 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 11:45 |
Martin Taal Messages: 5468 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 12:22 |
Jon Doe Messages: 7 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:45He 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 13:36 |
Martin Taal Messages: 5468 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 #891912 is a reply to message #891907] |
Tue, 26 June 2012 14:14 |
Martin Taal Messages: 5468 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 #1096603 is a reply to message #1096273] |
Wed, 28 August 2013 16:13 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Monica,
I did not incorporate the sample code I gave in the thread into Texo (if that's what you mean). I am not sure if it can
be done generically (let me know if it can, that I can detect the jndi name and that a jta transaction is ongoing).
Have you got it working with the sample code I provided?
gr. Martin
On 08/28/2013 04:36 PM, Oana Monica wrote:
> Hi Martin,
>
> Could you please tell if JTA-transactions are supported by Texo now...? I'm having the same problem presented here by
> Jon and i am trying to do what you suggested to make it work on Glassfish 4.
>
> Thanks in advance for your time.
>
> Regards,
> Monica
--
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 #1097287 is a reply to message #1097161] |
Thu, 29 August 2013 13:41 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Great Monica, if it somehow works generically and you want to contribute then I more than happy to add it into Texo's
code base!
gr. Martin
On 08/29/2013 12:09 PM, Oana Monica wrote:
> Hi Martin,
>
> First i tried creating a class JTAEntityManagerObjectStore which extends EntityManagerObjectStore with empty methods
> begin/commit/rollback/close and i initialized the UserTransaction in ExampleModelBrowserServlet. I also registered my
> class with ComponentProvider as you suggested and it worked.
>
> Today, when i saw your reply i tried with your sample code and created an instance of the class aswell:
>
> public class JTAEntityManagerObjectStore extends EntityManagerObjectStore {
>
> private UserTransaction userTransaction;
> private static JTAEntityManagerObjectStore instance =
> ComponentProvider.getInstance().newInstance(JTAEntityManagerObjectStore.class);
>
> public static JTAEntityManagerObjectStore getInstance(){
> return instance;
> }
>
> @Override
> public void begin() {
> InitialContext initCtx;
> try {
> initCtx = new InitialContext();
> userTransaction = (UserTransaction)initCtx.lookup("java:comp/UserTransaction");
> try {
> userTransaction.begin();
> } catch (NotSupportedException | SystemException e) {
> e.printStackTrace();
> }
> } catch (NamingException e) {
> e.printStackTrace();
> }
>
> getEntityManager().joinTransaction();
> }
>
> @Override
> public void commit() {
> try {
> userTransaction.commit();
> } catch (SecurityException | IllegalStateException | RollbackException
> | HeuristicMixedException | HeuristicRollbackException
> | SystemException e) {
> e.printStackTrace();
> }
> }
>
> @Override
> public void close() {
>
> }
>
> @Override
> public void rollback() {
> try {
> userTransaction.rollback();
> } catch (IllegalStateException | SecurityException | SystemException e) {
> e.printStackTrace();
> }
> }
>
> public UserTransaction getUserTransaction() {
> return userTransaction;
> }
>
> public void setUserTransaction(UserTransaction userTransaction) {
> this.userTransaction = userTransaction;
> }
> }
>
>
> Usage of this class in ExampleModelBrowserServlet:
>
> //persist everything
> JTAEntityManagerObjectStore jtaEM = JTAEntityManagerObjectStore.getInstance();
> EntityManager entityManager = jtaEM.getEntityManager();
> for(Object o: modelObjects){
> if(o instanceof Book){
> if(((Book) o).getCategory() != null){
> jtaEM.begin();
> entityManager.persist(o);
> jtaEM.commit();
> }
> }else{
> jtaEM.begin();
> entityManager.joinTransaction();
> entityManager.persist(o);
> jtaEM.commit();
> }
> }
>
>
>
> I am trying to find a way to do this generically as you asked and I'll let you know if I get to a solution :) .
>
> Next i need to make this example work in an OSGI container.
>
> Thanks for your reply.
>
> Best regards,
> Monica.
--
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
|
|
|
Goto Forum:
Current Time: Thu Apr 25 22:26:49 GMT 2024
Powered by FUDForum. Page generated in 0.03907 seconds
|