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.  [ 2 posts ] 
Author Message
 Post subject: Collections of value types and Criteria queries
PostPosted: Fri Jun 22, 2007 4:12 pm 
Newbie

Joined: Thu May 18, 2006 2:49 pm
Posts: 5
Hi everybody,

I've been trying to get Criteria queries working with collections of value types, but I got stuck at a very simple use case. Here is what I am trying to get done:

Code:
@Entity
public class Test {
   @Id @GeneratedValue @Column(name = "ids")
   private Long id;

   @CollectionOfElements(targetElement = String.class, fetch = FetchType.EAGER)
   @JoinTable(name = "test_names", joinColumns = @JoinColumn(name = "ids"))
   @org.hibernate.annotations.IndexColumn(name = "position", base = 1)
   @Column(name = "names")
   private List<String> names = new ArrayList<String>();

   public Long getId() {return id;   }

   public void setId(Long id) {this.id = id;}

   public List<String> getNames() {return names;}

   public void setNames(List<String> names) {this.names = names;}

   public static void main(String[] args) {
      Criteria c = PersistenceFactory.getSession().createCriteria(Test.class);
      c.add(Restrictions.eq("names", "Test"));
      for (Object o : c.list())
         System.out.println(o);
   }
}


At the point when I try listing the criteria query results I get a

Code:
Hibernate: select this_.ids as ids0_0_, names2_.ids as ids2_, names2_.names as names2_, names2_.position as position2_ from Test this_ left outer join test_names names2_ on this_.ids=names2_.ids where this_.ids=?
WARN  SQL Error: 0, SQLState: 22023 in logExceptions (JDBCExceptionReporter.java:77)
ERROR No value specified for parameter 1. in logExceptions (JDBCExceptionReporter.java:78)


I've been trying to use different annotations for that collection, starting from just CollectionOfElements to what's here now and using different Criteria options to perform a join, like createAlias() / createCriteria() / setFetchMode(), etc, but none of those seem to help.

An HQL query like

Code:
"from " + Test.class.getName()
   + " as t join t.names as name where name='Test'"


seem to work just fine.

I would appreciate it greately, if someone can point out where there is a flaw in my code of if that's a bug. I use Postgres 8.2 with Hibernate 3.2.4

Thank you very much in advance.

Best regards,
Nick.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 25, 2007 9:26 am 
Newbie

Joined: Thu May 18, 2006 2:49 pm
Posts: 5
Hi,

Wonder why people would not reply to this one :(, but I think I got a solution, sort of. Looks like criteria API doesn't support queries:

http://opensource.atlassian.com/project ... se/HHH-869

Hope it gets implemented soon :)

Regards,
Nick.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.