错误提示类未与命名查询映射

时间:2019-04-25 10:01:43

标签: java hibernate spring-boot import spring-data-jpa

我使用的是Spring数据Jpa,我想使用我的名为ClientList的类映射一个名为Client的表,并且收到错误消息,指出未在命名查询中映射client [SELECT c FROM client c]。这是下面的代码

  

这是我的实体类,并且出现错误提示   HHH000177:命名查询中的错误:getAllClients   org.hibernate.hql.internal.ast.QuerySyntaxException:客户端未映射[SELECT c FROM client c]

package com.abc.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
@NamedQueries({
    @NamedQuery( name="getAllClients" , query="SELECT c FROM client c")
  })

@Entity
@Table(name="client")
public class ClientList {


@Id
@Column(name="ClientName")
 String clientName;

@Column(name="ClientId")
 String clientId;

@Column(name="ImplementationCode")
String implementationCode;

@Column(name="createddate")
String cretedDate;

public String getClientName() {
    return clientName;
}

public void setClientName(String clientName) {
    this.clientName = clientName;
}



public String getClientId() {
    return clientId;
}

public void setClientId(String clientId) {
    this.clientId = clientId;
}

public String getImplementationCode() {
    return implementationCode;
}

public void setImplementationCode(String implementationCode) {
    this.implementationCode = implementationCode;
}

public String getCretedDate() {
    return cretedDate;
}

public void setCretedDate(String cretedDate) {
    this.cretedDate = cretedDate;
}

@Override
public String toString() {
    return "ClientDetails [clientName=" + clientName + ", clientId=" + clientId + ", implementationCode="
            + implementationCode + ", cretedDate=" + cretedDate + "]";
}

public ClientList(String clientName, String clientId, String implementationCode, String cretedDate) {
    super();
    this.clientName = clientName;
    this.clientId = clientId;
    this.implementationCode = implementationCode;
    this.cretedDate = cretedDate;
}


@Id
@Column(name="ClientName")
 String clientName;

@Column(name="ClientId")
 String clientId;

@Column(name="ImplementationCode")
String implementationCode;

@Column(name="createddate")
String cretedDate;

public String getClientName() {
    return clientName;
}

public void setClientName(String clientName) {
    this.clientName = clientName;
}



public String getClientId() {
    return clientId;
}

public void setClientId(String clientId) {
    this.clientId = clientId;
}

public String getImplementationCode() {
    return implementationCode;
}

public void setImplementationCode(String implementationCode) {
    this.implementationCode = implementationCode;
}

public String getCretedDate() {
    return cretedDate;
}

public void setCretedDate(String cretedDate) {
    this.cretedDate = cretedDate;
}

@Override
public String toString() {
    return "ClientDetails [clientName=" + clientName + ", clientId=" + clientId + ", implementationCode="
            + implementationCode + ", cretedDate=" + cretedDate + "]";
}

public ClientList(String clientName, String clientId, String implementationCode, String cretedDate) {
    super();
    this.clientName = clientName;
    this.clientId = clientId;
    this.implementationCode = implementationCode;
    this.cretedDate = cretedDate;
}


@Id
@Column(name="ClientName")
 String clientName;

@Column(name="ClientId")
 String clientId;

@Column(name="ImplementationCode")
String implementationCode;

@Column(name="createddate")
String cretedDate;

public String getClientName() {
    return clientName;
}

public void setClientName(String clientName) {
    this.clientName = clientName;
}



public String getClientId() {
    return clientId;
}

public void setClientId(String clientId) {
    this.clientId = clientId;
}

public String getImplementationCode() {
    return implementationCode;
}

public void setImplementationCode(String implementationCode) {
    this.implementationCode = implementationCode;
}

public String getCretedDate() {
    return cretedDate;
}

public void setCretedDate(String cretedDate) {
    this.cretedDate = cretedDate;
}

@Override
public String toString() {
    return "ClientDetails [clientName=" + clientName + ", clientId=" + clientId + ", implementationCode="
            + implementationCode + ", cretedDate=" + cretedDate + "]";
}

public ClientList(String clientName, String clientId, String implementationCode, String cretedDate) {
    super();
    this.clientName = clientName;
    this.clientId = clientId;
    this.implementationCode = implementationCode;
    this.cretedDate = cretedDate;
 }
}

2 个答案:

答案 0 :(得分:1)

您的实体名称为ClientList,因此您的查询应为select c from ClientList c

答案 1 :(得分:0)

由于您没有将NamedQuery定义为本机,因此需要使用java类定义的名称(用于表和列),而不是JPA注释定义的名称。

在您的示例中,在“命名查询”定义中使用“ ClientList”作为表名。