Beginners Question (EJB, Vaadin 7 & JPAContainer)

Hello,

Basically, I have to projects.

Project1Gui (Vaadin 7)
Project1Backend (EJB)

Those two packages are deployed together into an EAR called Project1EAR.

My Java knowledge is a little bit rusty. I’m trying to set up a custom EntityProvider for using JTA.
How can I achieve this within my Project1Backend? The both projects need to stay splitted!

I am using Eclipse and JBoss 7.

Hello Pete,

I would do some thing like the following -

  • I would define a persistence.xml under Project1Backend/META-INF with an unique JNDI Name for EntityManager and EntityManagerFactory
  • In My Project1Gui I would do either of the following
    • If I am using CDI, I would inject the entityManager with the JNDI name defined
    • Else I would do a look up for EntityManagerFactory and create an EntityManager from it.
      • Then I would, use the API
        JPAContainerFactory.make(MyEntity.class, entityManager);
        to create Container.

Please note that you have to close all resources like EntityManagerFactory in your detach listeners or detach Methods.

Hope these pointers would help you. Incase, if any issues please let me know and I will get back to you.

Thanks.

Hi Pete.
Did you find the solution?
I have your same goal, and I have already tried to do the things suggested by Ktishna, but something is still wrong…
I’m going to open a specific topic about it, but if you already have the solution please reply…
Thanks,
Susanna

Hello Susanna,

Can you please describe your problem so that we can troubleshoot the same.

Thanks,
Krishna.

From the very limited information provided above I asume you are having problems to access your persistence unit from both application modules ( ejb, and web module ). By default a persistence unit is module scoped and not available to the whole application.

To make the persistence unit available to the whole application , move your META-INF/persistence.xml to a seperate jar project (shared-persistence.jar), it only has to contain your META-INF/persistence.xml

Explicitly add shared-persistence.jar to your ear project (and other module projects that need the persistence unit ) as dependency …

Hi all.
Sorry if I didn’t reply immediatly.
My problem is detailed in this post:
https://vaadin.com/forum#!/thread/7975671
Any help is really welcome…
Thanks again,
Su