繁体   English   中英

JPA 1.2 createQuery Where子句条件

[英]JPA 1.2 createQuery Where Clause Criteria

嗨,我是JPA的新手。 我正在尝试使用一个列作为条件来选择一组特定的记录。 我的实体代码是根据表结构自动生成的,如下所示:

create table TEST.COMPUTERS(
       "COLUMN1" VARCHAR2(6) not null,
       "COLUMN2" VARCHAR2(10) not null,
       "COLUMN3" VARCHAR2(5) not null,
       "COLUMN4" VARCHAR2(8) not null,
       "COLUMN5" VARCHAR2(48),
        constraint "PK" primary key ("COLUMN1","COLUMN2")
    );

工程师职业等级代码:

@Table(name = "COMPUTERS", schema = "TEST") 
public class Computers implements java.io.Serializable {


 /** full constructor */
        public Computers(ComputersId id, String column3, String column4,
                String column5) {
            this.id = id;
            this.column3 = column3;
            this.column4 = column4;
            this.column5 = column5;
        }

          @EmbeddedId
          public ComputersId getId() {
            return this.id;
       }

      public void setId(ComputersId id) {
        this.id = id;
      }
        // and then ....getter and setter methods for Column 3-5

然后,我执行以下操作:

Query query  =   EntityManagerHelper.getEntityManager().createQuery("SELECT s from Computers s where s.column1 = :column1").setParameter("column1", "SONY LAPTOPS");

运行以上命令后,出现以下错误:

An error occurred while parsing the query filter "SELECT s from Computers where s.column1 = :column1". Error message: No field named "column1" in class "class Computers".

请问对此有何建议? 非常感谢..

由于Column1是embededId的一部分,所以您必须通过id字段:

Query query  =   EntityManagerHelper.getEntityManager().createQuery("SELECT s from Computers s where s.id.column1 = :column1").setParameter("column1", "SONY LAPTOPS");

PS:您的栏目名称选择似乎不正确。 也许您应该给他们一些更具描述性的名称?

暂无
暂无

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

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