Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在Spring JpaRepository中使用鉴别器列的JPQL查询导致QuerySyntaxException:xxx未映射_Java_Mysql_Hibernate_Jpa_Spring Data Jpa - Fatal编程技术网

Java 在Spring JpaRepository中使用鉴别器列的JPQL查询导致QuerySyntaxException:xxx未映射

Java 在Spring JpaRepository中使用鉴别器列的JPQL查询导致QuerySyntaxException:xxx未映射,java,mysql,hibernate,jpa,spring-data-jpa,Java,Mysql,Hibernate,Jpa,Spring Data Jpa,我想选择具有客户端角色的用户,但出现以下错误: 原因:org.hibernate.hql.internal.ast.QuerySyntaxException: 未映射利用率用户[从利用率用户中选择用户,其中 u、 角色=:客户端]位于 org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79) ~[hibernate-core-5.3.10.Fin

我想选择具有客户端角色的用户,但出现以下错误:

原因:org.hibernate.hql.internal.ast.QuerySyntaxException: 未映射利用率用户[从利用率用户中选择用户,其中 u、 角色=:客户端]位于 org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]at org.hibernate.hql.internal.ast.QueryTranslatorImpl.docomFile(QueryTranslatorImpl.java:219) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:143) ~[hibernate-core-5.3.10.Final.jar:5.3.10.Final]

usilizateur.java:

//为简洁起见省略导入
@实体
@表(name=“提款人”)
@继承(策略=InheritanceType.SINGLE_表)
@鉴别器列(name=“ROLE”)
公共类利用器实现可序列化
{
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
私人长代码用户;
私有字符串;
私有字符串名称;
私有字符串prenom;
私有字符串用户名;
私有字符串密码;
专用串电话;
私家侦探;
私有布尔活动;
私人字符串地址;
@日期时间格式(pattern=“dd/MM/yyyy”)
私人日期出生;
私人字符串电子邮件;
私有字符类型;
公共用途{
超级();
}
公用事业单位(长代码){
this.CodeUsilizateur=代码;
}
公共应用程序(字符串cin、字符串nom、字符串prenom、字符串电话、字符串电子邮件、字符类型、布尔活动){
超级();
this.cin=cin;
this.nom=nom;
this.prenom=prenom;
这个电话;
this.email=电子邮件;
这个。流派=流派;
this.actif=actif;
}
公用用户(字符串cin、字符串nom、字符串prenom、字符串用户名、字符串密码、字符串电话、,
字符串ville、字符串地址、日期出生、字符串电子邮件、字符类型、布尔活动){
超级();
this.cin=cin;
this.nom=nom;
this.prenom=prenom;
this.username=用户名;
this.password=密码;
这个电话;
this.ville=ville;
this.adrese=adrese;
this.dateNaissance=dateNaissance;
this.email=电子邮件;
这个。流派=流派;
this.actif=actif;
}
//为简洁起见省略了getter/setter
}
利用urrepository.java:

//为简洁起见省略导入
公共接口利用Urrepository扩展了JpaRepository{
@查询(“从用户中选择用户,其中用户角色=:客户”)
公共列表getClients();
}

我发现您的存储库存在几个问题

  • 您在JPQL查询中使用的是表名而不是
    实体
    名称
  • 您正试图选择
    列表
    使用对象
    getClients()
    的签名返回
    列表
    ,而不是
    列表
  • 您正在尝试将角色与不属于
    getClients()
    签名的替换值(
    :CLIENT
    )匹配
  • 您正在使用以下注释将
    usilizateur
    配置为父级:

    继承(策略=InheritanceType.SINGLE_表) @鉴别器列(name=“ROLE”) 因此,我假设您至少有一个子类
    usilizateur
    Client
    ,您正在尝试查询该子类:

    @实体
    公共类客户端扩展利用率{…}
    
    在这种情况下,请尝试以下操作:

    公共接口利用Urrepository扩展了JpaRepository{
    @查询(“从用户中选择用户,其中类型(u)=客户”)
    公共列表getClients();
    }
    
    否则,您可能希望有一个单独的ClientRepository:

    公共接口ClientRepository扩展了JpaRepository{
    //在这种情况下,你可以利用findAll
    //这已经由JpaRepository提供
    }
    
    代码太多了!请把你的答案删减到最短。阅读