-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Crietria API returning same results
PostPosted: Wed Sep 05, 2007 8:59 pm 
Newbie

Joined: Thu Aug 23, 2007 9:52 pm
Posts: 9
I have a table T that has composite key (col1, col2)

I mapped it to Java class like following. Please note the use of @Id @GeneratedValue on one column while in DB the primary key is composed of both columns(can I do that ??)

Code:
@Entity
@Table(name="SSLast")

public class SSLast implements Serializable{

   
    @Id @GeneratedValue
    @Column(name="CID")   
    private int companyId;
   
    @Column(name="SID")   
    private Integer serverId;

    public int getCompanyId() {
        return companyId;
    }

    public void setCompanyId(int companyId) {
        this.companyId = companyId;
    }

    public Integer getServerId() {
        return serverId;
    }

    public void setServerId(Integer serverId) {
        this.serverId = serverId;
    }

}




Now I have following code in some other class

Code:
Criteria criteria = getSession().createCriteria(SSLast.class);
criteria.add(Expression.eq("serverId", 551492)); 


Now I expect 5 rows and I get 5 rows in fact but companyId is same for all records. It always fetches correct number of rows but some how companyId is same for all records irrespective of what I pass for serverId

Similarly if I do following then I get the correct no of rows for companyId but serverId for all records are same.


Code:
Criteria criteria = getSession().createCriteria(SSLast.class);
criteria.add(Expression.eq("companyId", 1)); 


If I specify both serverId and companyId as follows then I always get 1 record that is correct behavior because companyId and serverId combination is Primary key


Code:
Criteria criteria = getSession().createCriteria(SSLast.class);
criteria.add(Expression.eq("serverId", 551492)); 
criteria.add(Expression.eq("companyId", 1)); 


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.