4

休止状態の基準を使用して、結合句に条件を追加しようとしています。実際、これを可能にするいくつかの方法があります。

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

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

それらは、1 対 1 および 1 対多の関係で適切に機能します。しかし、多対多の関係を持つエンティティでそれらを使用しようとすると、次のエラーが発生します。

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

誰でも私を助けることができますか?失礼な例は次のとおりです。

@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 and ( name1_.name=? ) 
    left outer join person_name name1_ on personname3_.person_name_id=name1_.id and ( name1_.name=? )

ご覧のとおり、結合条件が 2 回追加されていますが、これは明らかに間違っています。

前もって感謝します。

ところで、私はpostgresql 9、Hibernate 3.6.3を使用しています

4

1 に答える 1