English 中文(简体)
JOIN+附加条件(有条款)不与许多对许多协会合作
原标题:Hibernate criteria JOIN + additional condition (with clause) don t work with many-to-many association

我试图用冬眠标准给加入条款增加附加条件。 事实上,有些方法允许这样做:

createCriteria(String associationPath, String alias, int joinType, Criterion withClause)

createAlias(String associationPath, String alias, int joinType, Criterion withClause) 

They work properly with one-to-one 和one-to-many relations. But when I m trying to use them with entities having many-to-many relations, I m getting following error:

Caused by: org.postgresql.util.PSQLException: No value specified for parameter 1.

Can anybody help me? The rude example is below:

@Entity
public class Person {

@Id
@GeneratedValue
private Long id;

@ManyToMany
private Set<PersonName> names;

}

public class PersonName {

@Id
@GeneratedValue
private Long id;

@Column
private String name;

}
public class PersonDao extends HibernateDaoSupport {

public List<Person> findByName() {
    Criteria criteria = getSession().createCriteria(Person.class, "p");
    criteria.createCriteria("p.names", "names", JoinType.INNER_JOIN, Restrictions.eq("name", "John"));
    return criteria.list();
}
}

正在生成查询

select this_.id as y0_ from person this_ 
    inner join debtor_info this_1_ on this_.id=this_1_.id 
    left outer join person_person_name personname3_ on this_.id=personname3_.person_id 和( name1_.name=? ) 
    left outer join person_name name1_ on personname3_.person_name_id=name1_.id 和( name1_.name=? )

如你所见,加入条件增加两次,明显不正确

提前感谢。

BTW Im 使用后gresql 9, Hhibernate 3.6.3

问题回答

This is a bug HHH-7355 Hibernate criteria JOIN + additional condition (with clause) don t work with many-to-many association and it will not be fixed because Hibernate Criteria API is deprecated and you should use JPA Crtiterias. You can try to use HQL with clause

from Cat as cat
left join cat.kittens as kitten
    with kitten.bodyWeight > 10.0




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签