I'm working on a maven project which uses seam 2.2.0, hibernate 3.5.0-CR-2 as JPA provider, DB2 as database server and Websphere 7 as application server. Now I'm facing de following problem:
In my EJBs that are seen also as SEAM components I want to use the EntityManager from EJB container (#PersistenceContext private EntityManager em) not Seam's EntityManager (#In private EntityManager em). But this is the problem, I cannot obtain an EntityManager using #PersistenceContext.
On server logs it sais that it cannot create an EntityManagerFactory and gets a ClassCastException:
java.lang.ClassCastException: org.hibernate.ejb.HibernatePersistence incompatible with javax.persistence.spi.PersistenceProvider
After a lot of debugging and searching on forums I'm assuming that the problem is that Websphere doesn't use the Hibernate JPA provider.
Has anyone faced this problem and has a solution? I configured already WAS class loader order for my application to load the classes with the application class loader first and I\ve packed all necessary jars in application ear as written in: WAS InfoCenter: Features for EJB 3.0 development . If necessary I'll post my persistence.xml, components.xml files and stack trace.
I've found this problem discussed also here:
Websphere EntityManagerFactory creation problem
Hibernate 3.3 fail to create entity manager factory in Websphere 7.0. Please help
Any hint will be useful.
Thanks in advance!
Mihaela
I suspect that you've included the JPA API jar in your EAR. When using "parent last" (also known as "load classes with application class loader first"), your application is loading a second copy of the javax.persistence.spi.PersistenceProvider class, which is incompatible with the copy included in WAS. You need to either remove those classes from your EAR or change back to "parent first" delegation mode.
Related
I have demo application with JPA 2.1 and weblogic 12.1.3 deployment works fine and am able to get EntityManager which is annotated on the stateless bean.
I have application where I have ejb-jar.xml, on this file we have configured all MDB and session beans, Note: application is not using annotation.
And ejb-jar.xml uses http://java.sun.com/dtd/ejb-jar_2_0.dtd(ejb 2), but our application is running on weblogic 12.1.3. On this configuration, I tried to get EntityManager with the help of annotation in MDB, but am getting null object.
Question.
1. Is it possible to annotate EntityManager, with above configuration.
2. If not possible what are alternative ways. meaning I need to move all the configuration of ejb-jar.xml to annotation.
Thanks
Daya
I've searched for an answer to my problem on google and various forums, but couldn't find a solution. I'm currently trying to modify the persistence.xml at runtime by adding a persistence unit to the file.
The solutions for this question were always "pass a Map of properties when creating an EntityManagerFactory (or EntityManager)" but i need to save the new persistence unit in the persistence.xml, because the application is going to have 100 or even more persistence unit's, one for each tenant that will register to the service, each tenant will have his own database. I'm currently using EclipseLink 2.3.3 as my JPA implementation, EJB 3.1 and jboss 7.1.1.Final as my application server.
Is it possible to modify the persistence.xml at runtime (on the fly)?
The persistence.xml is a deployed artifact, so would be difficult to modify at runtime. I think passing a properties map to createEntityManagerFactory is your best solution, what issue are you having with this?
You may also want to try using the PersistenceProvider API, createContainerEntityManagerFactory() that takes a PersistenceUnitInfo.
Also, consider using EclipseLink's multi-tenant support,
http://www.eclipse.org/eclipselink/documentation/2.5/solutions/multitenancy.htm
I'm just about migrating from JBoss 6.1 to Glassfish 3.1 (don't ask why). The following occurs:
Invalid ejb jar [mmsUserMgmtAct-0.0.1-SNAPSHOT.jar]: it contains zero ejb
...
Note:
1. A valid ejb jar requires at least one session, entity (1.x/2.x style), or message-
driven bean.
2. EJB3+ entity beans (#Entity) are POJOs and please package them as library jar.
3. If the jar file contains valid EJBs which are annotated with EJB component level
annotations (#Stateless, #Stateful, #MessageDriven, #Singleton), please check server.log
to see whether the annotations were processed properly.
As everything was running perfectly with Jboss I can swear there are EJBs within the jars. The only thing which might cause the error is the fact, that I splitted the interfaces (#Remote and #Local) plus the entities (#Entity) into a package xyzService.jar and the stateless bean (#Stateless, #Remote(XyzService.class)) into another archive named xyzServiceImpl.jar.
All packaging was generated by maven, so no issues with this. Maybe I should mention that I simply copied the things into autodeploy folder.
Any glues?
Thx in advance
El Subcomandante
I'm stuck between a rock and a hard place at the moment with this problem. If I define my persistence context as:
#PersistenceContext(unitName = "persistentUnit")
private EntityManager entityManager;
Glassfish refused to start with the error:
SEVERE: Could not resolve a persistence unit corresponding to the persistence-context-ref-name [com.ckd.business.MusicService/entityManager] in the scope of the module called [home]. Please verify your application.
But if I changed the declaration to:
e#PersistenceContext(name = "persistentUnit")
private EntityManager entityManager;
Glassfish is able to deploy my WAR file but when I load the page up I get this:
java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName null
What the heck?! I have saved the persistence.xml file to WEB-INF\classes\META-INF directory as per the requirement and saw that Glassfish has loaded JPA properly. But it doesn't matter what I do, Glassfish always fail. I'm using Glassfish 3.1 OpenSource Edition.
Does anyone know of a solution or a workaround for this? Thanks.
Not a solution, but some thoughts:
I think the first is the correct usage. The unitName must be the same as in your persistence.xml. There should be something like this
<persistence-unit name="persistentUnit">
...
</persistence-unit>
As seen in the answer to this question, remember that injection takes place after the constructor.
Hope this helps to get a bit further.
I am trying to use Seam to persist my jpa entities, when I reference an entity that is in a jar seam says unknown entity. I don't want to add all classes in persistence.xml I want seam to scan my jars and auto detect entities (as done by spring).
What am I missing?
It actually depends a lot on the environment of your application.
If it's Java SE (for example war packaged application deployed on tomcat), your jars are not scanned for entities that compose your persistence unit. Those classes are seen as normal java classes, entity manager doesn't care about them that much... And you have to point them manually, or switch to Java EE and ear...