Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Extensible Entities(Using extensible entities to support flex fields)
Extensible Entities [message #735305] Tue, 11 October 2011 13:54 Go to next message
John Dugo is currently offline John DugoFriend
Messages: 13
Registered: October 2011
Junior Member
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 15:43 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

You can extend entities mapped through annotations. What error do you get?

What is your persistence and orm.xml?


James : Wiki : Book : Blog : Twitter
Re: Extensible Entities [message #735377 is a reply to message #735368] Tue, 11 October 2011 15:53 Go to previous messageGo to next message
John Dugo is currently offline John DugoFriend
Messages: 13
Registered: October 2011
Junior Member
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 15:43 Go to previous messageGo to next message
James is currently offline JamesFriend
Messages: 272
Registered: July 2009
Senior Member
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 15:53 Go to previous messageGo to next message
John is currently offline JohnFriend
Messages: 52
Registered: July 2009
Member
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 18:21 Go to previous messageGo to next message
John Dugo is currently offline John DugoFriend
Messages: 13
Registered: October 2011
Junior Member
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 18:33 Go to previous messageGo to next message
John Dugo is currently offline John DugoFriend
Messages: 13
Registered: October 2011
Junior Member
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 18:34]

Report message to a moderator

Re: Extensible Entities [message #735429 is a reply to message #735422] Tue, 11 October 2011 18:54 Go to previous message
John Dugo is currently offline John DugoFriend
Messages: 13
Registered: October 2011
Junior Member
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 18:54 Go to previous message
John is currently offline JohnFriend
Messages: 52
Registered: July 2009
Member
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: Thu Apr 25 08:58:20 GMT 2024

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

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

Back to the top