-->
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.  [ 3 posts ] 
Author Message
 Post subject: Select by List of primary keys
PostPosted: Thu Jun 21, 2007 11:13 am 
Newbie

Joined: Thu Jun 21, 2007 9:24 am
Posts: 7
Hello,

I want to read a List of Objects from DB by List of primary keys.

Primary key is composite:

Code:
@Embeddable
public class ProjectPK implements Serializable {

  @Column(name="prj_id", nullable=false)
  private Integer prjID;

  @Column(name="prj_supp_id", nullable=false, length=150)
  private String prjSuppID;

...
}


I want to do something like this:
Code:
  private List<Project> readByPKs(List<ProjectPK> projectPKs)
  {

    String sql = "from Project p where p.projectPK = :projectPKs";

    Query query = em.createQuery(sql)
    .setParameter("projectPKs", projectPKs);
   
   ...
}


I have tried queries:
Quote:
from Project p where p.projectPK = :projectPKs
from Project p where p.projectPK in :projectPKs


but without success.

It is possible to read Objects from database by multiplecomposite keys?

Thanks


Top
 Profile  
 
 Post subject: updarte
PostPosted: Thu Jun 21, 2007 11:55 am 
Newbie

Joined: Thu Jun 21, 2007 9:24 am
Posts: 7
When in List is one PK, then query pass.

When in List are two projctsPKs, then exception is thrown:


Code:
org.hibernate.hql.ast.QuerySyntaxException: unexpected token: , near line 1, column 110 [from cz.test.ProjectBean p where p.projectPK = :projectPKs0_, :projectPKs1_]
        at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:31)
        at org.hibernate.hql.ast.QuerySyntaxException.convert(QuerySyntaxException.java:24)
        at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 22, 2007 6:53 am 
Newbie

Joined: Thu Jun 21, 2007 9:24 am
Posts: 7
I have tried to use Criteria, but still without success ...

Code:
List<ProjectPK> pks = ...
Criteria criteria = session.createCriteria(Project.class);
criteria.add(Exppresion.in("projectPK", pks));
criteria.list();


Returns one object .. (and this object doesn't correspond any primary key given)


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

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.