Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » Dynamic JPA and AttributeOverrides(How to set AttributeOverrides using Dynamic JPA)
Dynamic JPA and AttributeOverrides [message #804538] Wed, 22 February 2012 13:49 Go to next message
Eclipse UserFriend
I am using Dynamic JPA Api and would like to know how to use "AttributeOverrides" (or equivalent of) on an embedded type.
For e.g I have a type "Employee" having two attributes of embedded type "MyType".
Employee {
@Embedded
public MyType t1;

@AttributeOverrides({
@AttributeOverride(name = "DBCOL"})
@Embedded
public MyType t2;

}
I was able to create the embedded type mapping using "addAggregateObjectMapping" but havent found way to override the database mapping using Dynamic API.

Is this possible in Dynamic JPA ?
Re: Dynamic JPA and AttributeOverrides [message #808359 is a reply to message #804538] Mon, 27 February 2012 12:45 Go to previous messageGo to next message
Eclipse UserFriend
You can use orm.xml with Dynamic JPA, so can use the same JPA overrides in XML.

For the API, you can call addMapping() and pass an AggregateObjectMapping.

It contains the API addFieldNameTranslation() which allows the column names to be overridden.

For its API refer to the JavaDocs,

http://www.eclipse.org/eclipselink/api/2.3/org/eclipse/persistence/mappings/AggregateObjectMapping.html

Re: Dynamic JPA and AttributeOverrides [message #809821 is a reply to message #808359] Wed, 29 February 2012 04:50 Go to previous messageGo to next message
Eclipse UserFriend
Thanks for your response.I tried using the approach but it looks like the overridden mapping specified via "addFieldNameTranslation"is being ignored .
In the code below Iam expecting "EMD_ATTR2.JsonString" to use the db mapping "db_jsonstring_2" but it reverts to "db_jsonstring".
//////START CODE
configureEmbeddable(emdType);
....
dynType.addAggregateObjectMapping("EMD_ATTR", emdType.getType(), false);
AggregateObjectMapping mapping = dynType.addAggregateObjectMapping("EMD_ATTR2", emdType.getType(), false);

mapping.addFieldNameTranslation("db_jsonstring_2","JsonString") ; //overriding here

private static void configureEmbeddable(JPADynamicTypeBuilder emdType) {
emdType.addDirectMapping("Data_Type", String.class, "db_data_type");
emdType.addDirectMapping("JsonString", String.class, "db_jsonstring");
}
/////////END CODE
Re: Dynamic JPA and AttributeOverrides [message #810814 is a reply to message #809821] Thu, 01 March 2012 10:36 Go to previous messageGo to next message
Eclipse UserFriend
You have to override using the column names.


mapping.addFieldNameTranslation("db_jsonstring","db_jsonstring_2") ;
Re: Dynamic JPA and AttributeOverrides [message #810908 is a reply to message #810814] Thu, 01 March 2012 12:10 Go to previous messageGo to next message
Eclipse UserFriend
Ok Thanks. I tried that too and it doesnt work. Basically whatever that is being specified by the addFieldNameTranslation is being ignored.
Re: Dynamic JPA and AttributeOverrides [message #813714 is a reply to message #810908] Mon, 05 March 2012 11:29 Go to previous messageGo to next message
Eclipse UserFriend
This does work in general, but I'm not sure how the Dynamic support initializes the descriptors.
Ensure you define the parent and child descriptors together.
There could be an issue with how Dynamic JPA does initialization, which you may wish to log a bug on.
Does it work if you use an orm.xml instead of the API?
Re: Dynamic JPA and AttributeOverrides [message #825412 is a reply to message #813714] Tue, 20 March 2012 16:24 Go to previous message
Eclipse UserFriend
Apologies for the late reply. The API using addFieldNameTranslation does work.
Thanks for your help in resolving this.
Previous Topic:cache coordination - Received JMS message is null
Next Topic:ConcurrencyException
Goto Forum:
  


Current Time: Tue Jul 22 18:03:57 EDT 2025

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

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

Back to the top