简体   繁体   English

具有EmbeddedId的休眠条件无法生成正确的SQL查询

[英]Hibernate Criteria with EmbeddedId not generate correct sql query

I have the following mapping of my classes: 我的班级有以下映射:

@Entity
Class A{
    @EmbeddedId 
    B id;
    String notImportant;
}

@Entity
Class B {
    C c;
}

Class C {
String name;
}

When i use the follow criteria: 当我使用以下条件时:

Criteria criteria = getCurrentSession().createCriteria(A.class);
criteria.createAlias("id.c", "c");
criteria.add(Restrictions.eq("c.name", "Whatever"));
criteria.list();

Hibernate: 
    /* criteria query */ select
        this_.notImportant as DOAT2_77_0_ 
    from
        A this_ 
    where
        c.name=?

2017-04-15 21:03:02,211 ERROR [org.hibernate.util.JDBCExceptionReporter] - ORA-00904: "c"."name": identificador inválido

So i understand that the "c" identified would be defined by a Inner join... As the criteria use this identifier without declaration... 因此,我知道所标识的“ c”将由内部联接定义...由于条件使用此标识符而无需声明...

  • The class B must be annotated with @Embeddable ; B类必须使用@Embeddable进行注释;
  • Also check if the class B has the getC and setC methods; 还要检查类B是否具有getCsetC方法;

If the error persist, please post your full code. 如果错误仍然存​​在,请发布完整代码。 :-) :-)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM