Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 18:49 Go to next message
Sunil Varma is currently offline Sunil VarmaFriend
Messages: 5
Registered: February 2012
Junior Member
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 17:45 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 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



James : Wiki : Book : Blog : Twitter
Re: Dynamic JPA and AttributeOverrides [message #809821 is a reply to message #808359] Wed, 29 February 2012 09:50 Go to previous messageGo to next message
Sunil Varma is currently offline Sunil VarmaFriend
Messages: 5
Registered: February 2012
Junior Member
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 15:36 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 have to override using the column names.


mapping.addFieldNameTranslation("db_jsonstring","db_jsonstring_2") ;


James : Wiki : Book : Blog : Twitter
Re: Dynamic JPA and AttributeOverrides [message #810908 is a reply to message #810814] Thu, 01 March 2012 17:10 Go to previous messageGo to next message
Sunil Varma is currently offline Sunil VarmaFriend
Messages: 5
Registered: February 2012
Junior Member
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 16:29 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

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?


James : Wiki : Book : Blog : Twitter
Re: Dynamic JPA and AttributeOverrides [message #825412 is a reply to message #813714] Tue, 20 March 2012 20:24 Go to previous message
Sunil Varma is currently offline Sunil VarmaFriend
Messages: 5
Registered: February 2012
Junior Member
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: Wed Apr 24 20:20:30 GMT 2024

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

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

Back to the top