You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by Ebenezer Graham <eg...@alustudent.com> on 2019/05/05 17:32:06 UTC

Entity Enhancement in Spring Boot

Hello Devs,

I am an Apache Fineract CN contributor currently working on migrating the
project's ORM from Hibernate to OpenJPA (more on the issue
<https://jira.apache.org/jira/projects/FINCN/issues/FINCN-2?filter=allopenissues>
).

https://github.com/ebenezergraham/fineract-cn-postgresql/commit/c10a1e77c3a290c1faa671621baf6c6037ba260a

I want to know how to dynamically enhance entity classes for each
microservice's entity without having to hardcode the configuration in an
XML.

The aim is to do the enhancement with spring or gradle. I would appreciate
it if someone could share their experience on how to handle this (a better
way of doing this https://openjpa.apache.org/enhancement-with-maven.html
with gradle, a plugin or spring boot autoconfiguration).

A brief overview, the project has a PostgreSQL library and a provisioner
microservice which provides persistence functionalities to 13 other
microservices. The goal is to configure the enhancement once in the
PostgreSQL library - a one size fits all approach.

The above issue has led to this error(full log here:
https://pastebin.com/kGQu4qLH)

Error creating bean with name 'jpaMappingContext': Invocation of init
method failed; nested exception is <openjpa-2.4.1-r422266:1730418 fatal
user error> org.apache.openjpa.util.MetaDataException: The type "class
org.apache.fineract.cn.customer.internal.repository.PortraitEntity" has not
been enhanced.

*Regards,*

*Ebenezer Graham*

Re: Entity Enhancement in Spring Boot

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Ps - thanks phone: see
https://docs.spring.io/spring/docs/current/javadoc-api/org/springframework/orm/jpa/LocalContainerEntityManagerFactoryBean.html

Le lun. 6 mai 2019 à 09:02, Francesco Chicchiriccò <il...@apache.org> a
écrit :

> Hi,
> at Syncope we had this migration from Hibernate to OpenJPA at the time
> of incubation, and we also had to face similar issues.
> FYI we are now on OpenJPA since 2011 and we have never been regretting
> such a choice that was initially dictated by licensing.
>
> Coming to your question, we also rely on Spring ORM: see configuration
> [1][2], allowing no persistence.xml, and a very tiny orm.xml [3] - I
> know it's somewhat involved, but we do have to support multi-tenancy,
> hence multiple persistence units, plus multiple DBMSes.
>
> Also, we do entity enhancement at build time [4] via Maven, at the sole
> price of a simple persistence.xml [5] to be used only there.
>
> Finally, we provide a tweak for Spring ORM to look for JPA entity
> classes from multiple JARs in the classpath - see [6].
>
> Please have a look at let me know if there is anything unclear.
>
> Regards.
>
> [1]
>
> https://github.com/apache/syncope/blob/2_1_X/core/persistence-jpa/src/main/resources/persistenceContext.xml
> [2]
>
> https://github.com/apache/syncope/blob/2_1_X/core/persistence-jpa/src/main/resources/domains/MasterDomain.xml
> [3]
>
> https://github.com/apache/syncope/blob/2_1_X/core/persistence-jpa/src/main/resources/META-INF/spring-orm.xml
> [4]
>
> https://github.com/apache/syncope/blob/2_1_X/core/persistence-jpa/pom.xml#L143-L174
> [5]
>
> https://github.com/apache/syncope/blob/2_1_X/core/persistence-jpa/src/main/resources/persistence-enhance.xml
> [6]
>
> https://github.com/apache/syncope/blob/2_1_X/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/spring/MultiJarAwarePersistenceUnitPostProcessor.java
>
> On 05/05/19 19:32, Ebenezer Graham wrote:
> > Hello Devs,
> >
> > I am an Apache Fineract CN contributor currently working on migrating the
> > project's ORM from Hibernate to OpenJPA (more on the issue
> > <
> https://jira.apache.org/jira/projects/FINCN/issues/FINCN-2?filter=allopenissues
> >
> > ).
> >
> >
> https://github.com/ebenezergraham/fineract-cn-postgresql/commit/c10a1e77c3a290c1faa671621baf6c6037ba260a
> >
> > I want to know how to dynamically enhance entity classes for each
> > microservice's entity without having to hardcode the configuration in an
> > XML.
> >
> > The aim is to do the enhancement with spring or gradle. I would
> appreciate
> > it if someone could share their experience on how to handle this (a
> better
> > way of doing this https://openjpa.apache.org/enhancement-with-maven.html
> > with gradle, a plugin or spring boot autoconfiguration).
> >
> > A brief overview, the project has a PostgreSQL library and a provisioner
> > microservice which provides persistence functionalities to 13 other
> > microservices. The goal is to configure the enhancement once in the
> > PostgreSQL library - a one size fits all approach.
> >
> > The above issue has led to this error(full log here:
> > https://pastebin.com/kGQu4qLH)
> >
> > Error creating bean with name 'jpaMappingContext': Invocation of init
> > method failed; nested exception is <openjpa-2.4.1-r422266:1730418 fatal
> > user error> org.apache.openjpa.util.MetaDataException: The type "class
> > org.apache.fineract.cn.customer.internal.repository.PortraitEntity" has
> not
> > been enhanced.
> >
> > *Regards,*
> >
> > *Ebenezer Graham*
>
>
> --
> Francesco Chicchiriccò
>
> Tirasa - Open Source Excellence
> http://www.tirasa.net/
>
> Member at The Apache Software Foundation
> Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMail
> http://home.apache.org/~ilgrosso/
>
>

Re: Entity Enhancement in Spring Boot

Posted by Francesco Chicchiriccò <il...@apache.org>.
Hi,
at Syncope we had this migration from Hibernate to OpenJPA at the time 
of incubation, and we also had to face similar issues.
FYI we are now on OpenJPA since 2011 and we have never been regretting 
such a choice that was initially dictated by licensing.

Coming to your question, we also rely on Spring ORM: see configuration 
[1][2], allowing no persistence.xml, and a very tiny orm.xml [3] - I 
know it's somewhat involved, but we do have to support multi-tenancy, 
hence multiple persistence units, plus multiple DBMSes.

Also, we do entity enhancement at build time [4] via Maven, at the sole 
price of a simple persistence.xml [5] to be used only there.

Finally, we provide a tweak for Spring ORM to look for JPA entity 
classes from multiple JARs in the classpath - see [6].

Please have a look at let me know if there is anything unclear.

Regards.

[1] 
https://github.com/apache/syncope/blob/2_1_X/core/persistence-jpa/src/main/resources/persistenceContext.xml
[2] 
https://github.com/apache/syncope/blob/2_1_X/core/persistence-jpa/src/main/resources/domains/MasterDomain.xml
[3] 
https://github.com/apache/syncope/blob/2_1_X/core/persistence-jpa/src/main/resources/META-INF/spring-orm.xml
[4] 
https://github.com/apache/syncope/blob/2_1_X/core/persistence-jpa/pom.xml#L143-L174
[5] 
https://github.com/apache/syncope/blob/2_1_X/core/persistence-jpa/src/main/resources/persistence-enhance.xml
[6] 
https://github.com/apache/syncope/blob/2_1_X/core/persistence-jpa/src/main/java/org/apache/syncope/core/persistence/jpa/spring/MultiJarAwarePersistenceUnitPostProcessor.java

On 05/05/19 19:32, Ebenezer Graham wrote:
> Hello Devs,
>
> I am an Apache Fineract CN contributor currently working on migrating the
> project's ORM from Hibernate to OpenJPA (more on the issue
> <https://jira.apache.org/jira/projects/FINCN/issues/FINCN-2?filter=allopenissues>
> ).
>
> https://github.com/ebenezergraham/fineract-cn-postgresql/commit/c10a1e77c3a290c1faa671621baf6c6037ba260a
>
> I want to know how to dynamically enhance entity classes for each
> microservice's entity without having to hardcode the configuration in an
> XML.
>
> The aim is to do the enhancement with spring or gradle. I would appreciate
> it if someone could share their experience on how to handle this (a better
> way of doing this https://openjpa.apache.org/enhancement-with-maven.html
> with gradle, a plugin or spring boot autoconfiguration).
>
> A brief overview, the project has a PostgreSQL library and a provisioner
> microservice which provides persistence functionalities to 13 other
> microservices. The goal is to configure the enhancement once in the
> PostgreSQL library - a one size fits all approach.
>
> The above issue has led to this error(full log here:
> https://pastebin.com/kGQu4qLH)
>
> Error creating bean with name 'jpaMappingContext': Invocation of init
> method failed; nested exception is <openjpa-2.4.1-r422266:1730418 fatal
> user error> org.apache.openjpa.util.MetaDataException: The type "class
> org.apache.fineract.cn.customer.internal.repository.PortraitEntity" has not
> been enhanced.
>
> *Regards,*
>
> *Ebenezer Graham*


-- 
Francesco Chicchiriccò

Tirasa - Open Source Excellence
http://www.tirasa.net/

Member at The Apache Software Foundation
Syncope, Cocoon, Olingo, CXF, OpenJPA, PonyMail
http://home.apache.org/~ilgrosso/


Re: Entity Enhancement in Spring Boot

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi Ebenezer

Idea is to add
https://github.com/apache/openjpa/blob/08bb3a5a0e7573622aa6dc25763cb6513095093b/openjpa-kernel/src/main/java/org/apache/openjpa/enhance/PCClassFileTransformer.java
to a classloader supporting it - tomcat or jetty ones for instance in
spring boot land.

It is automatically done using jpa container api -
createContainerEntityManagerFactory().

Can you try that to setup that in spring?

Le lun. 6 mai 2019 à 02:05, Ebenezer Graham <eg...@alustudent.com> a
écrit :

> Hello Romain,
>
> Thank you for your reply. I did a little bit of reading on the options you
> gave and I would like to go with the class transformer option.
>
> Can you please elaborate on how to achieve this in spring?
>
> Regards.
>
> On Sun, 5 May 2019 at 21:58, Romain Manni-Bucau <rm...@gmail.com>
> wrote:
>
> > Hi Ebenezer
> >
> > I was using
> >
> >
> https://rmannibucau.wordpress.com/2016/03/24/enhance-openjpa-entities-with-gradle/
> > but you can also add openjpa.jar as a javaagent on the jvm.
> >
> > With spring you would need a custom ClassFileTransformer, not sure it
> would
> > be the simplest so maybe give a try to the two previous options first.
> >
> > Hope it helps,
> >
> > Romain
> >
> > Le dim. 5 mai 2019 à 19:39, Ebenezer Graham <eg...@alustudent.com> a
> > écrit :
> >
> > > Hello Devs,
> > >
> > > I am an Apache Fineract CN contributor currently working on migrating
> the
> > > project's ORM from Hibernate to OpenJPA (more on the issue
> > > <
> > >
> >
> https://jira.apache.org/jira/projects/FINCN/issues/FINCN-2?filter=allopenissues
> > > >
> > > ).
> > >
> > >
> > >
> >
> https://github.com/ebenezergraham/fineract-cn-postgresql/commit/c10a1e77c3a290c1faa671621baf6c6037ba260a
> > >
> > > I want to know how to dynamically enhance entity classes for each
> > > microservice's entity without having to hardcode the configuration in
> an
> > > XML.
> > >
> > > The aim is to do the enhancement with spring or gradle. I would
> > appreciate
> > > it if someone could share their experience on how to handle this (a
> > better
> > > way of doing this
> https://openjpa.apache.org/enhancement-with-maven.html
> > > with gradle, a plugin or spring boot autoconfiguration).
> > >
> > > A brief overview, the project has a PostgreSQL library and a
> provisioner
> > > microservice which provides persistence functionalities to 13 other
> > > microservices. The goal is to configure the enhancement once in the
> > > PostgreSQL library - a one size fits all approach.
> > >
> > > The above issue has led to this error(full log here:
> > > https://pastebin.com/kGQu4qLH)
> > >
> > > Error creating bean with name 'jpaMappingContext': Invocation of init
> > > method failed; nested exception is <openjpa-2.4.1-r422266:1730418 fatal
> > > user error> org.apache.openjpa.util.MetaDataException: The type "class
> > > org.apache.fineract.cn.customer.internal.repository.PortraitEntity"
> has
> > > not
> > > been enhanced.
> > >
> > > *Regards,*
> > >
> > > *Ebenezer Graham*
> > >
> >
>

Re: Entity Enhancement in Spring Boot

Posted by Ebenezer Graham <eg...@alustudent.com>.
Hello Romain,

Thank you for your reply. I did a little bit of reading on the options you
gave and I would like to go with the class transformer option.

Can you please elaborate on how to achieve this in spring?

Regards.

On Sun, 5 May 2019 at 21:58, Romain Manni-Bucau <rm...@gmail.com>
wrote:

> Hi Ebenezer
>
> I was using
>
> https://rmannibucau.wordpress.com/2016/03/24/enhance-openjpa-entities-with-gradle/
> but you can also add openjpa.jar as a javaagent on the jvm.
>
> With spring you would need a custom ClassFileTransformer, not sure it would
> be the simplest so maybe give a try to the two previous options first.
>
> Hope it helps,
>
> Romain
>
> Le dim. 5 mai 2019 à 19:39, Ebenezer Graham <eg...@alustudent.com> a
> écrit :
>
> > Hello Devs,
> >
> > I am an Apache Fineract CN contributor currently working on migrating the
> > project's ORM from Hibernate to OpenJPA (more on the issue
> > <
> >
> https://jira.apache.org/jira/projects/FINCN/issues/FINCN-2?filter=allopenissues
> > >
> > ).
> >
> >
> >
> https://github.com/ebenezergraham/fineract-cn-postgresql/commit/c10a1e77c3a290c1faa671621baf6c6037ba260a
> >
> > I want to know how to dynamically enhance entity classes for each
> > microservice's entity without having to hardcode the configuration in an
> > XML.
> >
> > The aim is to do the enhancement with spring or gradle. I would
> appreciate
> > it if someone could share their experience on how to handle this (a
> better
> > way of doing this https://openjpa.apache.org/enhancement-with-maven.html
> > with gradle, a plugin or spring boot autoconfiguration).
> >
> > A brief overview, the project has a PostgreSQL library and a provisioner
> > microservice which provides persistence functionalities to 13 other
> > microservices. The goal is to configure the enhancement once in the
> > PostgreSQL library - a one size fits all approach.
> >
> > The above issue has led to this error(full log here:
> > https://pastebin.com/kGQu4qLH)
> >
> > Error creating bean with name 'jpaMappingContext': Invocation of init
> > method failed; nested exception is <openjpa-2.4.1-r422266:1730418 fatal
> > user error> org.apache.openjpa.util.MetaDataException: The type "class
> > org.apache.fineract.cn.customer.internal.repository.PortraitEntity" has
> > not
> > been enhanced.
> >
> > *Regards,*
> >
> > *Ebenezer Graham*
> >
>

Re: Entity Enhancement in Spring Boot

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi Ebenezer

I was using
https://rmannibucau.wordpress.com/2016/03/24/enhance-openjpa-entities-with-gradle/
but you can also add openjpa.jar as a javaagent on the jvm.

With spring you would need a custom ClassFileTransformer, not sure it would
be the simplest so maybe give a try to the two previous options first.

Hope it helps,

Romain

Le dim. 5 mai 2019 à 19:39, Ebenezer Graham <eg...@alustudent.com> a
écrit :

> Hello Devs,
>
> I am an Apache Fineract CN contributor currently working on migrating the
> project's ORM from Hibernate to OpenJPA (more on the issue
> <
> https://jira.apache.org/jira/projects/FINCN/issues/FINCN-2?filter=allopenissues
> >
> ).
>
>
> https://github.com/ebenezergraham/fineract-cn-postgresql/commit/c10a1e77c3a290c1faa671621baf6c6037ba260a
>
> I want to know how to dynamically enhance entity classes for each
> microservice's entity without having to hardcode the configuration in an
> XML.
>
> The aim is to do the enhancement with spring or gradle. I would appreciate
> it if someone could share their experience on how to handle this (a better
> way of doing this https://openjpa.apache.org/enhancement-with-maven.html
> with gradle, a plugin or spring boot autoconfiguration).
>
> A brief overview, the project has a PostgreSQL library and a provisioner
> microservice which provides persistence functionalities to 13 other
> microservices. The goal is to configure the enhancement once in the
> PostgreSQL library - a one size fits all approach.
>
> The above issue has led to this error(full log here:
> https://pastebin.com/kGQu4qLH)
>
> Error creating bean with name 'jpaMappingContext': Invocation of init
> method failed; nested exception is <openjpa-2.4.1-r422266:1730418 fatal
> user error> org.apache.openjpa.util.MetaDataException: The type "class
> org.apache.fineract.cn.customer.internal.repository.PortraitEntity" has
> not
> been enhanced.
>
> *Regards,*
>
> *Ebenezer Graham*
>