Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Extensible Entities(Using extensible entities to support flex fields)
Extensible Entities [message #735305] Tue, 11 October 2011 09:54 Go to next message
Eclipse UserFriend
My application has a requirement to support dynamic (flex) fields on our Entity Objects. I was hoping that the extensible entity support added in v2.3 could handle this.

This application has entity objects that are purely annotation based. All of the extensible entity code samples I can find have EOs whose attributes are xml based. I attempted to extend my entities using a eclipselink-orm.xml (tried including in my war and loading via a Metadata repository) but continue to get exceptions on startup.

Does the extensible entity stuff support annotation based entities? If not, is there another way to support dynamic fields?

Thanks,

John
Re: Extensible Entities [message #735368 is a reply to message #735305] Tue, 11 October 2011 11:43 Go to previous messageGo to next message
Eclipse UserFriend
You can extend entities mapped through annotations. What error do you get?

What is your persistence and orm.xml?
Re: Extensible Entities [message #735377 is a reply to message #735368] Tue, 11 October 2011 11:53 Go to previous messageGo to next message
Eclipse UserFriend
I am specifying my persistence properties through spring (LocalContainerEntityManagerFactoryBean)

properties.put(PersistenceUnitProperties.METADATA_SOURCE, "XML");
properties.put(PersistenceUnitProperties.METADATA_SOURCE_XML_URL, "HTTP_URL/eclipselink-orm.xml");

In order to load this up...i need to call refreshMetadata() on the EntityManagerFactory.


extended eclipselink-orm.xml
...
<entity class="com.example.ProjectEO">
<attributes>
<basic name="shortName" attribute-type="String">
<column name="PROJ_SHORT_NAME"/>
</basic>
</attributes>
</entity>
...
</entity-mappings>

Note: I have also tried attribute-type="VIRTUAL" and also specifying the get/set methods in here.


when i try to load the external eclipselink-orm.xml i get the following:

xception Description: Predeployment of PersistenceUnit [Model] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:221)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1385)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.refreshMetadata(EntityManagerSetupImpl.java:2913)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.refreshMetadata(EntityManagerFactoryImpl.java:200)
at com.oracle.pgbu.dao.em.CustomLocalContainerEntityManagerBean.postProcessEntityManagerFactory(CustomLocalContainerEntityManagerBean.java:52)
Truncated. see log file for complete stacktrace
Caused By: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.getAccessibleMethod(ClassAccessor.java:672)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.addAccessors(ClassAccessor.java:337)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.preProcess(ClassAccessor.java:1134)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.MappedSuperclassAccessor.preProcess(MappedSuperclassAccessor.java:682)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.preProcess(EntityAccessor.java:542)
Truncated. see log file for complete stacktrace
Re: Extensible Entities [message #735397 is a reply to message #735305] Tue, 11 October 2011 11:43 Go to previous messageGo to next message
Eclipse UserFriend
You can extend entities mapped through annotations. What error do you get?

What is your persistence and orm.xml?

--
James : http://wiki.eclipse.org/EclipseLink : http://en.wikibooks.org/wiki/Java_Persistence : http://java-persistence-performance.blogspot.com/
Re: Extensible Entities [message #735398 is a reply to message #735397] Tue, 11 October 2011 11:53 Go to previous messageGo to next message
Eclipse UserFriend
I am specifying my persistence properties through spring (LocalContainerEntityManagerFactoryBean)

properties.put(PersistenceUnitProperties.METADATA_SOURCE, "XML");
properties.put(PersistenceUnitProperties.METADATA_SOURCE_XML_URL, "HTTP_URL/eclipselink-orm.xml");

In order to load this up...i need to call refreshMetadata() on the EntityManagerFactory.


extended eclipselink-orm.xml
...
<entity class="com.example.ProjectEO">
<attributes>
<basic name="shortName" attribute-type="String">
<column name="PROJ_SHORT_NAME"/>
</basic>
</attributes>
</entity>
...
</entity-mappings>

Note: I have also tried attribute-type="VIRTUAL" and also specifying the get/set methods in here.


when i try to load the external eclipselink-orm.xml i get the following:

xception Description: Predeployment of PersistenceUnit [Model] failed.
Internal Exception: java.lang.NullPointerException
at org.eclipse.persistence.exceptions.EntityManagerSetupException.predeployFailed(EntityManagerSetupException.java:221)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1385)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.refreshMetadata(EntityManagerSetupImpl.java:2913)
at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.refreshMetadata(EntityManagerFactoryImpl.java:200)
at com.oracle.pgbu.dao.em.CustomLocalContainerEntityManagerBean.postProcessEntityManagerFactory(CustomLocalContainerEntityManagerBean.java:52)
Truncated. see log file for complete stacktrace
Caused By: java.lang.NullPointerException
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.getAccessibleMethod(ClassAccessor.java:672)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.addAccessors(ClassAccessor.java:337)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.ClassAccessor.preProcess(ClassAccessor.java:1134)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.MappedSuperclassAccessor.preProcess(MappedSuperclassAccessor.java:682)
at org.eclipse.persistence.internal.jpa.metadata.accessors.classes.EntityAccessor.preProcess(EntityAccessor.java:542)
Truncated. see log file for complete stacktrace
Re: Extensible Entities [message #735418 is a reply to message #735398] Tue, 11 October 2011 14:21 Go to previous messageGo to next message
Eclipse UserFriend
Not sure if this helps, but looking at the decompiled weaved class, it looks like the "set" method isn't getting weaved correctly.


//decompiled virtual access methods methods
public void set(String fieldName, Object value)
{
m_extensions.put(fieldName, value);
}

public Object get(String fieldName)
{
_persistence_checkFetched(fieldName);
return m_extensions.get(fieldName);
}
Re: Extensible Entities [message #735422 is a reply to message #735418] Tue, 11 October 2011 14:33 Go to previous messageGo to next message
Eclipse UserFriend
something is wrong here:

for the get/set methods its calling into this:
getAccessibleMethod(MappingAccessor accessor)

Which is looking for a get() method with no args. When it calls to find the set method it throws an NPE, since the get method doesn't exist.

I'm assuming it should be calling into this method instead:
protected MetadataMethod getAccessibleVirtualMethod(MappingAccessor accessor)

[Updated on: Tue, 11 October 2011 14:34] by Moderator

Re: Extensible Entities [message #735429 is a reply to message #735422] Tue, 11 October 2011 14:54 Go to previous message
Eclipse UserFriend
Ok i got it working. I would recommend adding this to the documentation:

<basic name="calendarId" attribute-type="Integer" access="VIRTUAL">

Without that, if your entity is property or field based, adding virtual methods won't work (atleast in my case
Re: Extensible Entities [message #735434 is a reply to message #735422] Tue, 11 October 2011 14:54 Go to previous message
Eclipse UserFriend
Ok i got it working. I would recommend adding this to the documentation:

<basic name="calendarId" attribute-type="Integer" access="VIRTUAL">

Without that, if your entity is property or field based, adding virtual methods won't work (atleast in my case
Previous Topic:SQL to JPA
Next Topic:Possible to return a ref cursor from Oracle function using StoredFunctionCall?
Goto Forum:
  


Current Time: Wed Jul 23 11:59:01 EDT 2025

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

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

Back to the top