Foros de discusión

JPA portlet - Persistence provider

thumbnail
ilke Muhtaroglu, modificado hace 13 años.

JPA portlet - Persistence provider

Regular Member Mensajes: 226 Fecha de incorporación: 12/05/09 Mensajes recientes
I have a application working well under tomcat...

When I switch it to a liferay portlet I get the following error after adding the portlet at page...


It looks like liferay can not find the JPA's persistence.xml file ! Where should I put the persistence.xml file in a portlet to make the Liferay see it (in the portlet class path ?)

Any suggestion is welcome. it sounds like a class path error where persistence.xml can not be found... how to solve ?

I can provide more information ın case of request...

(I use Liferay 5.2.3 and JPA with anootations)

The same portlet works in liferay 6.0.2 but not in 5.3.2 (problem is persistence.xml can not be found! at class path probably...)

ilke





10:32:58,446 ERROR [jsp:164] javax.persistence.PersistenceException: No Persistence provider for EntityManager named Rehber
	at com.myeclipseide.examples.myblog.persistence.EntityManagerHelper.<clinit>(EntityManagerHelper.java:23)
	at com.myeclipseide.examples.myblog.persistence.TitleDAO.findAll(TitleDAO.java:93)
	at com.myeclipseide.examples.myblog.jsf.TitleController.<init>(TitleController.java:52)
	at java.lang.Class.newInstance0(Class.java:355)
	at java.lang.Class.newInstance(Class.java:308)
	at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:186)
	at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:106)
	at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:368)
	at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:222)
	at com.sun.faces.el.ManagedBeanELResolver.getValue(ManagedBeanELResolver.java:86)
	at javax.el.CompositeELResolver.getValue(CompositeELResolver.java:54)
	at com.sun.faces.el.FacesCompositeELResolver.getValue(FacesCompositeELResolver.java:72)
	at org.apache.el.parser.AstIdentifier.getValue(AstIdentifier.java:61)
	at org.apache.el.parser.AstValue.getValue(AstValue.java:107)
	at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:186)
	at org.apache.jasper.el.JspValueExpression.getValue(JspValueExpression.java:101)
	at javax.faces.component.UISelectItems.getValue(UISelectItems.java:141)
	at com.sun.faces.renderkit.RenderKitUtils.getSelectItems(RenderKitUtils.java:289)
	at com.sun.faces.renderkit.html_basic.MenuRenderer.renderSelect(MenuRenderer.java:814)
	at com.sun.faces.renderkit.html_basic.MenuRenderer.encodeEnd(MenuRenderer.java:280)
</init></clinit>




here is my persistence.xml file


<!--?xml version="1.0" encoding="UTF-8"?-->
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">

	<persistence-unit name="Rehber" transaction-type="RESOURCE_LOCAL">		

	<provider>org.hibernate.ejb.HibernatePersistence</provider>
	
	 <class>com.myeclipseide.examples.myblog.persistence.Person</class>
	 <class>com.myeclipseide.examples.myblog.persistence.Title</class>   
	 <class>com.myeclipseide.examples.myblog.persistence.Department</class>      
	
		<properties>
			<property name="hibernate.hbm2ddl.auto" value="update" />
		
         <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLInnoDBDialect" />
         <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
         <property name="hibernate.connection.username" value="root" />
         <property name="hibernate.connection.password" value="epdk" />
         <property name="hibernate.connection.url" value="jdbc:mysql://localhost/myblog" />			
		 <property name="hibernate.show_sql" value="true" />
		</properties>		
	</persistence-unit>

</persistence>




And the line that the exception is thrown is:


emf = Persistence.createEntityManagerFactory("Rehber");
Francisco Aranda, modificado hace 13 años.

RE: JPA portlet - Persistence provider

New Member Mensajes: 6 Fecha de incorporación: 24/05/10 Mensajes recientes
Hi!

I'm having the same issue, have you found any solution for this?

Thanks!
thumbnail
ilke Muhtaroglu, modificado hace 13 años.

RE: JPA portlet - Persistence provider

Regular Member Mensajes: 226 Fecha de incorporación: 12/05/09 Mensajes recientes
Hi,

I copy pasted the persistence.xml to the folders that I thought as class path, but it looks like Liferay can not find the persistence.xml at the class path.

For 5.2.3 we dont have any solution but upgrading to 6.0.2 ?

Did you make any investigation regarding this problem, what did you try ?

Please note here when you solve this issue somehow.

ilke
Hiran Chaudhuri, modificado hace 13 años.

RE: JPA portlet - Persistence provider

Regular Member Mensajes: 188 Fecha de incorporación: 1/09/10 Mensajes recientes
Liferay should not modify the JPA behaviour. So if you are unsure about where persistence.xml has to go, I suggest you rerad this:
http://codeidol.com/java/netbeans/Persistence-EntityManager/Packaging-a-Persistence-Unit/

In my case the persistence unit is found, but I get a ClassCastException as the JPA provider Hibernate cannot be cast into the JPA SPI, so I cannot use it. And I'm working on the Liferay-JBoss bundle 6.0.5.
thumbnail
ilke Muhtaroglu, modificado hace 13 años.

RE: JPA portlet - Persistence provider

Regular Member Mensajes: 226 Fecha de incorporación: 12/05/09 Mensajes recientes
I switched to liferay 6.05 and JPA persistence.xml worked as expected when I put the file into META_INF directory...

so no problem for us, after switching to liferay 6.x, but we faced problem with 5.2.3

ilke
thumbnail
Felix Ashirov, modificado hace 13 años.

RE: JPA portlet - Persistence provider

Regular Member Mensajes: 128 Fecha de incorporación: 26/02/10 Mensajes recientes
Hi!
I agree with Hiran Chaudhuri.
Liferay should not affect the Persistence provider. How do you package your war? Maven or ant?
What is resulting location of persistence.xml file after your application is deployed?
Are there any other messages before error "No Persistence provider for EntityManager named Rehber" occurs?
Hiran Chaudhuri, modificado hace 12 años.

RE: JPA portlet - Persistence provider

Regular Member Mensajes: 188 Fecha de incorporación: 1/09/10 Mensajes recientes
Hiran Chaudhuri:
In my case the persistence unit is found, but I get a ClassCastException as the JPA provider Hibernate cannot be cast into the JPA SPI, so I cannot use it. And I'm working on the Liferay-JBoss bundle 6.0.5.

Now I have a problem regarding this topic. However I doubt it is Liferay-related.

Already some time back I managed to get JPA working from within some Netbeans projects. They deploy nicely on the Liferay 6.0.5 JBoss build and use Hibernate JPA to access the database. It is the same datasource as Liferay's, but with a modified table naming convention all my tables have a unique prefix so they do not clash.

Now the new stuff: I learned more about the Liferay SDK and try using the Liferay IDE - so I'm switching from Netbeans to Eclipse.
And I'm wondering why I simply am not able to use JPA here. All I get is a
javax.persistence.PersistenceException: No Persistence provider for EntityManager named xxx

As a test I also tried just a Dynamic Web Project deployed on JBoss 5.1 GA but it is the same. The persistence.xml file is found, and all the persistence units I define show up in the JMX console. It's just that the application cannot get an instance using
javax.persistence.Persistence.createEntityManagerFactory("xxx")

Anyone any idea what might be going wrong?
I already compared the war file to my Netbeans projects, and all rhe important stuff looks the same...
pspyra pspyra, modificado hace 10 años.

RE: JPA portlet - Persistence provider

New Member Mensajes: 6 Fecha de incorporación: 31/07/13 Mensajes recientes
ilke Muhtaroglu:
I copy pasted the persistence.xml to the folders that I thought as class path, but it looks like Liferay can not find the persistence.xml at the class path.

For 5.2.3 we dont have any solution but upgrading to 6.0.2 ?

Hi Ilke, I think you can help me.
I have a similar issue with the persistence.xml file.
I'm using liferay 6.1 bundled with tomcat 7, and I'm stil getting the error
javax.persistence.PersistenceException: No Persistence provider for EntityManager named kepler_v1PU
I have attached openEJB to my maven project dependencies
<dependency>
   <groupid>org.apache.openejb</groupid>
   <artifactid>javaee-api</artifactid>
   <version>6.0-5</version>
</dependency>

Content of my persistence.xml file (but I think the content doesn't metter, because it looks like tomcat does not see this file)
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
<persistence-unit name="kepler_v1PU">
    <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
    <properties>
      <property name="openjpa.ConnectionURL" value="jdbc:mysql://localhost:3306/kepler_v1" />
      <property name="openjpa.ConnectionDriverName" value="com.mysql.jdbc.Driver" />
      <property name="openjpa.ConnectionUserName" value="username" />
      <property name="openjpa.ConnectionPassword" value="password" />
      <property name="openjpa.Log" value="DefaultLevel=WARN, Tool=INFO" />
    </properties>
  </persistence-unit>
</persistence>

In ServletContextListener I'm creating EntityManagerFactory in this way
EntityManagerFactory emf = Persistence.createEntityManagerFactory("kepler_v1PU");

and this method throws: javax.persistence.PersistenceException: No Persistence provider for EntityManager named kepler_v1PU
It's very similar solution to this http://stackoverflow.com/a/19376645/1501031
After generating war file (and unpacking) I can see that persistence.xml is present in /WEB-INF/classes/META-INF/

Maybe I should also integrate tomcat (delivered with liferay) with the openEJB like it's described here http://tomee.apache.org/manual-installation.html? I'll give it a shot and let you know about the results.
If you have some other tips please share them with me.

Piotrek.
pspyra pspyra, modificado hace 10 años.

RE: JPA portlet - Persistence provider

New Member Mensajes: 6 Fecha de incorporación: 31/07/13 Mensajes recientes
pspyra pspyra:
Maybe I should also integrate tomcat (delivered with liferay) with the openEJB like it's described here http://tomee.apache.org/manual-installation.html? I'll give it a shot and let you know about the results.

Unfortunately solution described here http://tomee.apache.org/manual-installation.html is probably out of date or not well adapted to tomcat bundled with liferay.
For example paragraph "Add OpenEJB javaagent to Tomcat startup" - I cannot find the right lines in catalina.sh where I should add snippet with openEJB.

Do you have any idea how to add persistence to liferay 6.1 bundled with tomcat 7?
pspyra pspyra, modificado hace 10 años.

RE: JPA portlet - Persistence provider

New Member Mensajes: 6 Fecha de incorporación: 31/07/13 Mensajes recientes
I solved my issue by adding openejb-core to the project maven dependencies

<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>openejb-core</artifactId>
<version>4.5.0</version>
</dependency>