Hello,
Could the objects being read exist in the cache when you are executing
the query? If so, then the objects with those primary keys would be
returned as they exist in the cache. You can check by doing a find on
each of the 3 id's you expect to be returned from the native query
before executing the query. If they do have null values, try doing a
refresh on them. TopLink has the refresh query hint which can be used
to force a refresh of the entities if this is the case.
Best Regards,
Chris
rmmora159 wrote:
> Hi, I´m using the latest build of toplink (v2ur1-b09d), Tomcat 6, Eclipse.
>
> I am using a native query against an MS SQL 2000 server, the sql links four
> different tables, no query parameters used (WHERE condition built into the
> sql string).
>
> The query returns three records, which is correct. The same sql statement
> in MS SQL server returns all of the data correctly. The list returned is
> parsed using an iterator and cast into an entity which has 3 secondary
> tables added to the primary one. There are no entities for these secondary
> tables. When casting from the List returned by the query, only the first
> cast entity has all of the data, the next two only store the primary key
> value, all other fields are null. Only two of the fields in the entity
> (Coverage) are actually from other tables. Why does it do this?
>
> Query getCoverage = em.createNativeQuery(S_GET_INS_COV + " a.insured_id="
> + insured_id +
> " and w.work_id =" + work_id ,Coverage.class);
>
> List<Coverage> coverages = getCoverage.getResultList();
>
> Iterator it = coverages.iterator();
>
> StringBuffer res = new StringBuffer();
>
> while (it.hasNext()) {
>
> *** this cast only works the first time, the next time all fields will be
> null with the
> *** exception of cov_id, the primary key
>
> Coverage cov = (Coverage)it.next();
>
> res.append("cov_id" + valSep + cov.getCov_id() + pairSep );
> res.append("code" + valSep + cov.getCode() + pairSep );
> res.append("dentistId" + valSep + cov.getDentistId() + pairSep );
> res.append("dentistName" + valSep + cov.getDentistName() + pairSep );
>
>