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.