Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Dynamic JPA problem - empty Metamodel
Dynamic JPA problem - empty Metamodel [message #741504] Wed, 19 October 2011 15:40 Go to next message
Jerome  is currently offline Jerome Friend
Messages: 5
Registered: May 2010
Junior Member
I'm a JPA newbee using EclipseLink 2.3.0.

I'm trying to use the Dynamic JPA API as described here (grr I can't post links to this forum yet). Just google "EclipseLink Dynamic Persistence" and the first 2 hits should give you pages with these titles:


  • EclipseLink/Development/Dynamic - Eclipsepedia
  • EclipseLink/Examples/JPA/Dynamic - Eclipsepedia


I can get the querying to work as in the example. However, the Metamodel returned from the EntityManagerFactory is empty. Is that a bug? If not, why is it empty?

I had expected JPADynamicHelper.addTypes to populate the EMF Metamodel.

- Jerome
Re: Dynamic JPA problem - empty Metamodel [message #742581 is a reply to message #741504] Thu, 20 October 2011 16:13 Go to previous messageGo to next message
Jerome  is currently offline Jerome Friend
Messages: 5
Registered: May 2010
Junior Member
I found the problem is that when the constructor for JPADynamicHelper is called the Metamodel is created on the session. However for the dynamic case we haven't added the types yet because we need the JPADynamicHelper to be created before we call it's addTypes method. So by the time we call addTypes the empty Metamodel instance is already created so that empty one is the one returned from EntityManagerFactory.

I downloaded the latest EclipseLink code and modified EntityManagerSetupImpl.getMetamodel() to return a null Metamodel instead of an empty one. Now after JPADynamicHelper.addTypes is called when I call EntityManagerFactory.getMetamodel for the first time it creates the Metamodel with my types. Yay!

However, I was doing all of this for an odata4j application. And during my next step, which was to supply my EntityManagerFactory to odata4j's JPAProducer I discovered that odat4j doesn't like the EclipseLink dynamic classes. I get the following exception:

Exception in thread "main" java.lang.ClassCastException: org.eclipse.persistence.internal.dynamic.ValuesAccessor cannot be cast to org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor
at org.eclipse.persistence.internal.jpa.metamodel.AttributeImpl.getJavaMember(AttributeImpl.java:139)
at org.odata4j.producer.jpa.JPAEdmGenerator.toEdmProperty(JPAEdmGenerator.java:107)
at org.odata4j.producer.jpa.JPAEdmGenerator.getProperties(JPAEdmGenerator.java:130)
at org.odata4j.producer.jpa.JPAEdmGenerator.buildEdm(JPAEdmGenerator.java:182)
at org.odata4j.producer.jpa.JPAProducer.<init>(JPAProducer.java:85)
at edu.vt.ipg.odatahandsdynamic.App.main(App.java:59)

So I'm giving up on this Dynamic JPA business. Just thought I'd post this in case it helps someone else.
Re: Dynamic JPA problem - empty Metamodel [message #742585 is a reply to message #741504] Thu, 20 October 2011 16:13 Go to previous messageGo to next message
Jerome is currently offline JeromeFriend
Messages: 4
Registered: July 2009
Junior Member
I found the problem is that when the constructor for JPADynamicHelper is called the Metamodel is created on the session. However for the dynamic case we haven't added the types yet because we need the JPADynamicHelper to be created before we call it's addTypes method. So by the time we call addTypes the empty Metamodel instance is already created so that empty one is the one returned from EntityManagerFactory.

I downloaded the latest EclipseLink code and modified EntityManagerSetupImpl.getMetamodel() to return a null Metamodel instead of an empty one. Now after JPADynamicHelper.addTypes is called when I call EntityManagerFactory.getMetamodel for the first time it creates the Metamodel with my types. Yay!

However, I was doing all of this for an odata4j application. And during my next step, which was to supply my EntityManagerFactory to odata4j's JPAProducer I discovered that odat4j doesn't like the EclipseLink dynamic classes. I get the following exception:

Exception in thread "main" java.lang.ClassCastException: org.eclipse.persistence.internal.dynamic.ValuesAccessor cannot be cast to org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor
at org.eclipse.persistence.internal.jpa.metamodel.AttributeImpl.getJavaMember(AttributeImpl.java:139)
at org.odata4j.producer.jpa.JPAEdmGenerator.toEdmProperty(JPAEdmGenerator.java:107)
at org.odata4j.producer.jpa.JPAEdmGenerator.getProperties(JPAEdmGenerator.java:130)
at org.odata4j.producer.jpa.JPAEdmGenerator.buildEdm(JPAEdmGenerator.java:182)
at org.odata4j.producer.jpa.JPAProducer.<init>(JPAProducer.java:85)
at edu.vt.ipg.odatahandsdynamic.App.main(App.java:59)

So I'm giving up on this Dynamic JPA business. Just thought I'd post this in case it helps someone else.
Re: Dynamic JPA problem - empty Metamodel [message #748487 is a reply to message #742581] Mon, 24 October 2011 18:14 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Please log a bug that the JPA meta-model does not work with dynamic JPA.


James : Wiki : Book : Blog : Twitter
Re: Dynamic JPA problem - empty Metamodel [message #748489 is a reply to message #742581] Mon, 24 October 2011 18:14 Go to previous messageGo to next message
James is currently offline JamesFriend
Messages: 272
Registered: July 2009
Senior Member
Please log a bug that the JPA meta-model does not work with dynamic JPA.

--
James : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/
Re: Dynamic JPA problem - empty Metamodel [message #996165 is a reply to message #741504] Tue, 01 January 2013 07:45 Go to previous message
Arieh Faiga is currently offline Arieh FaigaFriend
Messages: 3
Registered: December 2012
Junior Member
Opened defect
https://bugs.eclipse.org/bugs/show_bug.cgi?id=397283
Previous Topic:How to print the objects that are stored in the isolated cache in EclipseLink?
Next Topic:JPA meta-model getJavaMember does not work with dynamic JPA
Goto Forum:
  


Current Time: Thu Nov 27 04:54:20 GMT 2014

Powered by FUDForum. Page generated in 0.03233 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software