Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » CreateNativeQuery ResultSet mapping
CreateNativeQuery ResultSet mapping [message #531509] Wed, 05 May 2010 09:40 Go to next message
Pavel Zelenka is currently offline Pavel ZelenkaFriend
Messages: 61
Registered: July 2009
Member
Hi,

I have problem running native query. The getSingleResult fills only datum filed and the ks field is always null. No exception is thrown. Can anybody help?

Thanks

Pavel

private Stat getExpediceData(Vykladka vykladka, Date datum)
         queryString = "select datum, ks from vykaz v join expedice e on v.idexpedice=e.idexpedice where e.datum = ? and v.idvykladka=?";
        Query q = em.createNativeQuery(queryString, Stat.class);
        q.setParameter(1, datum, TemporalType.DATE);
        q.setParameter(2, vykladka.getIdvykladka());
        Stat stat = (Stat) q.getSingleResult();
        return stat;


@Entity
public class Stat implements Serializable {
    @Id
    @Temporal(TemporalType.DATE)
    @Column(name = "datum")
    private Date datum;
    @Column(name = "ks")
    private Integer ks;
    @Column(name = "remitenda")
    private Integer remitenda;
    @Column(name = "cas_zavozu")
    private String casZavozu;

    getters and setters
    }


Re: CreateNativeQuery ResultSet mapping [message #531961 is a reply to message #531509] Thu, 06 May 2010 15:25 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Probably a case issue. Try using upper case in your @Column and SQL.

What database are you using?


James : Wiki : Book : Blog : Twitter
Re: CreateNativeQuery ResultSet mapping [message #532078 is a reply to message #531961] Fri, 07 May 2010 06:01 Go to previous messageGo to next message
Pavel Zelenka is currently offline Pavel ZelenkaFriend
Messages: 61
Registered: July 2009
Member
James wrote on Thu, 06 May 2010 11:25
Probably a case issue. Try using upper case in your @Column and SQL.

What database are you using?



Uppercase didn't help. The database is MS SQL2000.
Re: CreateNativeQuery ResultSet mapping [message #532153 is a reply to message #532078] Fri, 07 May 2010 11:08 Go to previous messageGo to next message
Pavel Zelenka is currently offline Pavel ZelenkaFriend
Messages: 61
Registered: July 2009
Member
I think the problem is in resultset mapping. If I parse the resultset (see code below) then I see the expected values.
But I still don't know where the problem is. Any idea?

private Stat getExpediceData(Vykladka vykladka, Date datum) {
        String queryString = "select datum, ks from vykaz v join expedice e on v.idexpedice=e.idexpedice where e.datum = ? and v.idvykladka=?";
        Query q = em.createNativeQuery(queryString);
        q.setParameter(1, datum, TemporalType.DATE);
        q.setParameter(2, vykladka.getIdvykladka());

        List<Object[]> result = q.getResultList();
        for (Object[] o : result){
            System.out.println(o[0]);
            System.out.println(o[1]);
        }



Re: CreateNativeQuery ResultSet mapping [message #532276 is a reply to message #532153] Fri, 07 May 2010 18:35 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1039
Registered: July 2009
Senior Member
Hello,

Native queries that return entities will return managed entities. Could the entities being queried exist in the cache or already be managed? Try to use the em.find api to return a Stat entity that would be returned and see if it has the ks field set or not. If it is null, then you will need to see why entities are being returned only partially populated - some users mistakenly use native queries to return entities but do not select all the fields, corrupting the cache with partially populated entities.

Best Regards,
Chris
Re: CreateNativeQuery ResultSet mapping [message #532375 is a reply to message #532276] Sun, 09 May 2010 09:22 Go to previous message
Pavel Zelenka is currently offline Pavel ZelenkaFriend
Messages: 61
Registered: July 2009
Member
Thanks Chris you were right. There already were entities with datum field filled only. So I made some code change and used QueryHints.REFRESH and now everything works.
So many thanks for help to all.
Previous Topic:dynamically configure javax.persistence.jdbc.url?
Next Topic:Is it possible to run a @TableGenerator in a separate transaction?
Goto Forum:
  


Current Time: Thu Dec 18 12:31:51 GMT 2014

Powered by FUDForum. Page generated in 0.01887 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software