[opencms-dev] JPA

Georgi Naplatanov gosho at oles.biz
Fri Jul 5 16:27:13 CEST 2013


Hi Jakub,

Some persitence unit configuration parameters are stored in 
opencms.properties file (DBCP and JDBC parameters) so you have 2 options 
to create factory for "OpenCmsJPAPool" peristence unit.

1. If your OpenCms instance is configured to use JPA layer, you can just 
invoke

org.opencms.db.jpa.CmsSqlManager#getFactory("OpenCmsJPAPool")

which will return EntityManagerFactory, or

org.opencms.db.jpa.CmsSqlManager#getEntityManager()

which will return EntityManager instance of that factory.

Note, after finishing work with EntityManager do not forget to invoke

returnEntityManager,

to return that instance back to pool (yes OpenCms use pool for 
EntityManager instances).

You can use createEntityManager("OpenCmsJPAPool") if you don't want to 
use that pool.

2. If your OpenCms instance doesn't use JPA layer you have to use

Persistence.createEntityManagerFactory(String persistenceUnitName, Map 
properties) ;

where persistenceUnitName is "OpenCmsJPAPool" and properties contains 
DBCP and JDBC parameters, you can look at

org.opencms.db.jpa.CmsSqlManager#buildConnectionPropertiesValue().

HTH

Best regards
Georgi

On 07/05/2013 04:53 PM, � wrote:
> Hello,
> I've been playing around with JPA in OpenCms(on default isntallation of
> OpenCms 8.5.1). I have problem with creation of EntityManager from
> EntityManagerFactory.
> I am trying to obtain EntityManager in stadard way from
> EntityManagerFactory with default OpenCms pool name OpenCmsJPAPool.
> �EntityManagerFactory emf =
> Persistence.createEntityManagerFactory("OpenCmsJPAPool");
> �EntityManager em = emf.createEntityManager();
> �em.close();
> �emf.close();
>
> This code gives me an error:
> Cannot create JDBC driver of class '' for connect URL 'null'
> Reason: Cannot create JDBC driver of class '' for connect URL 'null'
>
> This would sugest that there is something wrong with configuration in
> persistance.xml but I did not modify this file, so it should be ok.
> Has anybody experienced this issue? Or if anybody has a code snippet as
> example of �working with JPA in Opencms I'd be very greatful. I'd love
> to use JPA in a module that I am developing.
>
> Thanks.
>
> Jakub Je�m�nek
> ------------------------------------------------
> NELASOFT Technologies, s.r.o.
> Mob: +420 604 575 772
> E-mail: jakub.jecminek at nelasoft.cz <mailto:jakub.jecminek at nelasoft.cz>
> Web: www.nelasoft.cz <http://www.nelasoft.cz>
>
>
>
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/cgi-bin/mailman/listinfo/opencms-dev
>
>
>



More information about the opencms-dev mailing list