Hi Chris/Tom,
. One step further. Thanks Chris for the nice tip. Now I am
getting the following exception. Actuall there is already a
DirectFieldMaping - CTR_CLAIMS_DYR.VALUE_CHAR0. So I though lets
make them *readonly* and *not writtable* but it didn't work
Exception [EclipseLink-48] (Eclipse Persistence Services -
2.3.2.v20111125-r10461):
org.eclipse.persistence.exceptions.DescriptorException
Exception Description: Multiple writable mappings exist for the
field [CTR_CLAIMS_DYR.VALUE_CHAR0]. Only one may be defined as
writable, all others must be specified read-only.
Mapping:
org.eclipse.persistence.mappings.DirectToFieldMapping[code-->CTR_CLAIMS_DYR.VALUE_CHAR0]
Descriptor:
RelationalDescriptor(com.oracle.healthinsurance.claims.domain.internal.ctr.entities.CtrClaimDyrDomain
--> [DatabaseTable(CTR_CLAIMS_DYR)])
I fixed it by adding the following, which doesn't seem to be working
DirectToFieldMapping directToFieldMapping = new
DirectToFieldMapping();
directToFieldMapping.setDescriptor(classDescriptor);.
VirtualAttributeAccessor virtualAttributeAccessor = new
VirtualAttributeAccessor();
virtualAttributeAccessor.setIsWriteOnly(false);
virtualAttributeAccessor.setIsReadOnly(true);
virtualAttributeAccessor.setAttributeName(attributeName);
virtualAttributeAccessor.setGetMethodName("get");
virtualAttributeAccessor.setSetMethodName("set");
On 26-07-2012 09:20 PM, Christopher
Delahunt wrote:
The
virtualAttributeAccessor.initializeAttributes() call being
necessary is a symptom of the current problem - which is the
mapping is not getting initialized.
You need to debug how/where the mapping method is being called
from, and verify that the session passed in is not logged in. As
mentioned before, the NPE should only occur if the mapping has not
been initialized. As initialization occurs when the session is
logged in, it means that either there is a problem with the
mappings you are adding, or the mappings are still being added to
a session after it has been logged in/initialized. The later is
more likely and needs to to be ruled out completely to be able to
proceed.
Please check that you still are not using the older code to add
mappings elsewhere in your application. Doing so would corrupt
active sessions and cause these sorts of problems.
Best Regards,
Chris
On 26/07/2012 3:10 PM, gaurav malhotra wrote:
Hi Tom,
Please find my replies inline in the mail below
On 26-07-2012 07:54 PM, Tom Ware wrote:
Hi Gaurav,
Chris just pointed out to me that you should not need to call
initialize if your SessionCustomizer is running on the correct
session.
We are wondering if the session you are running on is the one
you
expect. Can you try to get this test case down to a single
thread with
a single EntityManagerFactory and then run the refreshMetadata
and the
query and see if it still fails.
/GM >> My test test case is running in a single thread
(its an
Junitintegration test)/
Also, the
virtualAttributeAccessor.initializeAttributes(classDescriptor.getJavaClass());
call is unneccessary if the Customization is in the right
place.
/ GM > I am not sure whether the above call is not necessary.
I made a
prototype based on the OTN Grid cache example i.e. outside my
application, where I created the mapping in the
SessionCustomizer (no
refreshMetadata in that scenario). It didn't work without a call
to
initialize/
-Tom
On 26/07/2012 1:47 PM, Tom Ware wrote:
Hi Gaurav,
Try calling oneToManyMapping.initialize(session) just before
returning the mapping.
-Tom
On 26/07/2012 11:12 AM, gaurav malhotra wrote:
Hi tom,
What I found : I am creating 1-M relationship >
CtrClaim -
CtrClaimDyr (pc0017)
(mentioned below). So when I search on CtrClaim, at object
building
phase it
finds, 1-M relationship (pc0017), then if fires
ReadObjectQuery.
Unfortunately
the it tries to get descriptor
ReadObjectQuery.getDescriptor, it
comes NULL
/**
* INTERNAL:
* Return the value of the reference attribute or a value
holder.
* Check whether the mapping's attribute should be
optimized through
batch and
joining.
*/
protected Object valueFromRowInternal(AbstractRecord row,
JoinedAttributeManager
joinManager, ObjectBuildingQuery sourceQuery,
AbstractSession
executionSession)
throws DatabaseException {
// PERF: Direct variable access.
ReadQuery targetQuery = this.selectionQuery;
// Copy nested fetch group from the source query
_*if (targetQuery.isObjectLevelReadQuery() &&
targetQuery.getDescriptor().hasFetchGroupManager()) {*_
*NPE*
One to many mapping are created as follows
DatabaseMapping oneToManyMapping(ClassDescriptor
classDescriptor,
String
attributeName, Class<?> attributeType) {
*classDescriptor>>ClassDescriptor of
CtrClaim, attributeName = pc0017 and
attributeType=CtrClaimDyr.class*
OneToManyMapping _oneToManyMapping_ = new
OneToManyMapping();
oneToManyMapping.setDescriptor(classDescriptor);
oneToManyMapping.setCascadeAll(true);
oneToManyMapping.useTransparentList();
VirtualAttributeAccessor virtualAttributeAccessor = new
VirtualAttributeAccessor();
virtualAttributeAccessor.setAttributeName(attributeName);
virtualAttributeAccessor.setGetMethodName("get");
virtualAttributeAccessor.setSetMethodName("set");
virtualAttributeAccessor.initializeAttributes(classDescriptor.getJavaClass());
oneToManyMapping.setAttributeAccessor(virtualAttributeAccessor);
oneToManyMapping.setAttributeName(attributeName);
oneToManyMapping.setReferenceClass(attributeType);
oneToManyMapping.addTargetForeignKeyFieldName("ID",
"BASE_TABLE_ID");
return oneToManyMapping;
}
On 26-07-2012 03:44 PM, Tom Ware wrote:
Hi Gaurav,
I think Chris' quotes are a bit out of context here.
We're now
further along -
we are seeing the metadata refreshed.
Lets try to figure out which mapping is causing the
problem and why.
-Tom
On 26/07/2012 9:41 AM, gaurav malhotra wrote:
Hi Tom,
From the previous post by chris, I gathered that "We
are executing
the query on
the session and not entityManager, which was pointed
out is not
correct" Are we
doing something fundamentally wrong. It seems session
- return
((EntityManagerImpl)
em.getDelegate()).getActiveSession(); does
not contain
newly added mappings (OneToMany)
Chris says:-/
EclipseLink nightly testing verify that
refreshMetadata does work
in the manner
Tom described. What are variables that might be
causing you
problems are that I
see Spring is involved, and you are executing queries
directly on
Sessions as
shown in the few lines below from a stack trace you
sent in earlier:
at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1449)
at
com.oracle.healthinsurance.support.domain.service.GenericSearchDAOImpl$16.doInJpa(GenericSearchDAOImpl.java:623)
at
com.oracle.healthinsurance.support.domain.service.GenericSearchDAOImpl$16.doInJpa(GenericSearchDAOImpl.java:1)
at
org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate.java:183)
I would have expected to just see an EclipseLink
EntityManager
executing a
query, not a GenericSearchDAOImpl directly
accessing/holding a
session or a
Spring JpaTemplate being involved. /
On 26-07-2012 03:26 PM, Tom Ware wrote:
Hi Gaurav,
I can't tell much about your query from the code you
have sent
me. For the
most part, the required information exists in
variables being
passed to the
code below and in methods that are not included in
your snippet.
What I can tell you is this:
- The exception is occurring on a mapping that is a
relationship
(xToOne or
xToMany).
- It is occurring because the targetQuery for the
mapping is not
properly
setup
I suggest figuring out which entity is referenced by
the
ReadAllQuery and then
figuring out which relationship mappings that object
has. We need
to look at
those. I suggest starting with the relationships
your customizer
is adding.
Lets try to isolate the exception to a single
mapping and then
take a look at
the code that creates that mapping.
-Tom
On 26/07/2012 9:09 AM, gaurav malhotra wrote:
Hi Tom,
Now my question is regarding ReadAllQuery. Since
we use
ReadAllQuery and
serach
like below
Session session = getActiveSession(em);
>>>>
ReadAllQuery query = new ReadAllQuery();
// Create _expression_ from Search Criteria use
locale as set in
Context object
GenericSearchCriteria<?> gsc =
searchInput.getSearchCriteria();
gsc.setLocale(ohiBusinessContext.getLocale());
GenerateEclipseLinkExpression genExpression = new
GenerateEclipseLinkExpression(gsc,
dynamicSearchExpressionContextProvider);
ClassDescriptor cd =
session.getClassDescriptor(gsc.getPersistableClass());
// Setup how the query should be executed
setQueryExecutionConfiguration(searchInput,
session, query, gsc,
genExpression, cd);
_expression_ exp =
genExpression.buildSelectionCriteriaFromSearchCriteria(gsc.getSearchCriteria());
// ExampleObject
query.setReferenceClass(gsc.getPersistableClass());
if (exp != null) {
logger.debug("_expression_ is: {0}", exp);
query.setSelectionCriteria(exp);
}
NanoStopWatch swInner = new NanoStopWatch();
swInner.start();
// Execute the query
List<Object> results =
CastUtil.castToList(session.executeQuery(query));
- ------- - ------- - ------- - ------- - -------
- ------- -
------- -
-------
- ------- - ------- - ------- - ------- - -------
- ------- -
------- -
-------
_*Search Example*_ - To the entity CtrClaimDomain,
new mappings
have weaved.
With the call
_*nameOfField,ctrClaim.get(nameOfField) *_/I am
trying to fetch
them/
List<CtrClaim> ctrClaims = new
SearchBuilder(CtrClaim.class).execute();
for (CtrClaim ctrClaim : ctrClaims) {
Map<String, Object> dynRecs1 =
ctrClaim.getDynamicRecords();
if (dynRecs1.size() > 0) {
for (Map.Entry<String, Object> entry :
dynRecs1.entrySet()) {
String nameOfField = entry.getKey();
System.err.println(String.format("Name=%s
Value=%s"_*,
nameOfField,ctrClaim.get(nameOfField)*_));
}
}
}
}
I am getting the following exception
java.lang.NullPointerException
at
org.eclipse.persistence.mappings.ForeignReferenceMapping
.valueFromRowInternal(ForeignReferenceMapping.java:2019)
at
org.eclipse.persistence.mappings.ForeignReferenceMapping.valueFromRow(ForeignReferenceMapping.java:1987)
at
org.eclipse.persistence.mappings.ForeignReferenceMapping.buildCloneFromRow(ForeignReferenceMapping.java:276)
at
org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildAttributesIntoWorkingCopyClone(ObjectBuilder.java:1548)
at
org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildWorkingCopyCloneFromRow(ObjectBuilder.java:1694)
at
org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObjectInUnitOfWork(ObjectBuilder.java:664)
at
org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:601)
at
org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildObject(ObjectBuilder.java:560)
at
org.eclipse.persistence.queries.ObjectLevelReadQuery.buildObject(ObjectLevelReadQuery.java:717)
at
org.eclipse.persistence.queries.ReadAllQuery.registerResultInUnitOfWork(ReadAllQuery.java:769)
at
org.eclipse.persistence.queries.ReadAllQuery.executeObjectLevelReadQuery(ReadAllQuery.java:433)
at
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeDatabaseQuery(ObjectLevelReadQuery.java:1081)
at
org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:844)
at
org.eclipse.persistence.queries.ObjectLevelReadQuery.execute(ObjectLevelReadQuery.java:1040)
at
org.eclipse.persistence.queries.ReadAllQuery.execute(ReadAllQuery.java:392)
at
org.eclipse.persistence.queries.ObjectLevelReadQuery.executeInUnitOfWork(ObjectLevelReadQuery.java:1128)
at
org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2871)
at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1516)
at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1498)
at
org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1449)
at
com.oracle.healthinsurance.support.domain.service.GenericSearchDAOImpl$16.doInJpa(GenericSearchDAOImpl.java:623)
at
com.oracle.healthinsurance.support.domain.service.GenericSearchDAOImpl$16.doInJpa(GenericSearchDAOImpl.java:1)
|