Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Virtual Metlhods | questions

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)






Back to the top