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)
|