persistence@glassfish.java.net

query returns null values after 1st record

From: rmmora159 <rmmora159_at_hotmail.com>
Date: Tue, 6 May 2008 08:02:43 -0700 (PDT)

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

-- 
View this message in context: http://www.nabble.com/query-returns-null-values-after-1st-record-tp17084846p17084846.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.