Does it have to be an embeddable? How about using a
MappedSuperclass instead?
Cheers,
Guy
On 31/10/2012 8:18 AM, bhakti b wrote:
Hi Guy
I tried the SessionEventListener workaround that you mentioned, it did not
work for me. I did the following :
public class SessionEventListener extends SessionEventAdapter {
@Override
public void postLogin(SessionEvent event) {
super.postLogin(event);
Session s = event.getSession();
ClassDescriptor classDescriptor =
s.getClassDescriptor(com.model.AnotherEmployee.class);
updateColumnMetaDataForMapping(s,
classDescriptor.getMappingForAttributeName("address1"));
updateColumnMetaDataForMapping(s,
classDescriptor.getMappingForAttributeName("address2"));
}
private void updateColumnMetaDataForMapping(Session s, DatabaseMapping
mapping) {
boolean isReadOnly = ((AggregateObjectMapping)
mapping).getReferenceDescriptor().getMappingForAttributeName("countryCode").isReadOnly();
((AggregateObjectMapping)
mapping).getReferenceDescriptor().getMappingForAttributeName("countryCode").setIsReadOnly(false);
((AggregateObjectMapping)
mapping).getReferenceDescriptor().getMappingForAttributeName("countryCode").getField().setInsertable(true);
((AggregateObjectMapping)
mapping).getReferenceDescriptor().getMappingForAttributeName("countryCode").getField().setUpdatable(true);
((AggregateObjectMapping)
mapping).getReferenceDescriptor().getMappingForAttributeName("countryCode").initialize((AbstractSession)
s);
isReadOnly = ((AggregateObjectMapping)
mapping).getReferenceDescriptor().getMappingForAttributeName("countryCode").isReadOnly();
}
}
Just setting setIsReadOnly(false) did not work, i had to explicitly set the
insertable and updatable flags too. This change started giving me the
correct query in DatabaseRecord object,
DatabaseRecord(
JPA_EMP_DIFF_COL_OVRD.EMP_ID => 1201
JPA_EMP_DIFF_COL_OVRD.EMP_NAME => Employee2
JPA_EMP_DIFF_COL_OVRD.ADDR1 => Home2
JPA_EMP_DIFF_COL_OVRD.ADDR1_COUNTRY_CODE => AUS
JPA_EMP_DIFF_COL_OVRD.ADDR2 => Work2
JPA_EMP_DIFF_COL_OVRD.ADDR2_COUNTRY_CODE => AUS)
but the query that is getting fired ultimately doesn't reflect this change,
it still gets fired as :
[EL Fine]: sql: 2012-10-31
17:22:27.499--ClientSession(185058837)--Connection(1583668601)--Thread(Thread[main,5,main])--INSERT
INTO JPA_EMP_DIFF_COL_OVRD (EMP_ID, EMP_NAME, ADDR1, ADDR2) VALUES (?, ?, ?,
?)
bind => [1901, Employee2, Home2, Work2]
Although i tried the above mentioned workaround, it is merely impossible for
us to implement such a thing in the current application, as we have a large
number of entities that would use these embeddable classes.
I would like to know if there is any other way by which such a requirement
can be mapped, some custom tag or converter that could do such a thing ?
--
View this message in context: http://eclipse.1072660.n5.nabble.com/Is-there-a-way-by-which-we-can-map-the-same-column-to-multipe-embedded-attribute-overrides-tp155354p155414.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
--

Guy Pelletier
ORACLE Canada,
45 O'Connor Street
Suite 400
Ottawa, Ontario
Canada K1P 1A4
Oracle is committed to developing
practices and products that help protect the environment
|