Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/70.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 JPA+Hibernate+Mysql的查询语言问题_Java_Mysql_Spring_Hibernate_Spring Data Jpa - Fatal编程技术网

Java JPA+Hibernate+Mysql的查询语言问题

Java JPA+Hibernate+Mysql的查询语言问题,java,mysql,spring,hibernate,spring-data-jpa,Java,Mysql,Spring,Hibernate,Spring Data Jpa,我已经开发了一个java独立应用程序java+hibernate,现在我正在重新移植到Java8+springboot+jpa+hibernate+mysql框架。我在我的旧项目中使用了HQL,但在新框架中SQL语句似乎存在一些问题,例如,我必须通过删除括号从p where id=:parameter更改为Select*From p where id=:parameter 豆子 @抑制警告未检查 public ArrayList Simply_get_thing_list 字符串查询\u字符串,

我已经开发了一个java独立应用程序java+hibernate,现在我正在重新移植到Java8+springboot+jpa+hibernate+mysql框架。我在我的旧项目中使用了HQL,但在新框架中SQL语句似乎存在一些问题,例如,我必须通过删除括号从p where id=:parameter更改为Select*From p where id=:parameter

豆子

@抑制警告未检查 public ArrayList Simply_get_thing_list 字符串查询\u字符串, ArrayList参数_列表, 课堂上的事情 { Query q=实体\管理器。createNativeQueryQuery\字符串,对象\类; ……. 归还物品清单; }

SQL语句

"SELECT * FROM Place p WHERE p.Groupunit_Definer.Classification='Jurisdiction'"
休眠配置

spring.jpa.database = MYSQL
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = update
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5Dialect
错误消息

:: Spring Boot ::       (v1.5.21.RELEASE)

2019-09-04 05:28:11.851  INFO 2508 --- [           main] c.s.mirrorworld.mirrorworldApplication   : Starting mirrorworldApplication on LAPTOP-FAS0SHLM with PID 2508 (C:\Users\yueho\eclipse-workspace\mirrorworld\target\classes started by yueho in C:\Users\yueho\eclipse-workspace\mirrorworld)
2019-09-04 05:28:11.859  INFO 2508 --- [           main] c.s.mirrorworld.mirrorworldApplication   : No active profile set, falling back to default profiles: default
2019-09-04 05:28:12.066  INFO 2508 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2f217633: startup date [Wed Sep 04 05:28:12 CST 2019]; root of context hierarchy
2019-09-04 05:28:15.937  INFO 2508 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2019-09-04 05:28:15.994  INFO 2508 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2019-09-04 05:28:16.257  INFO 2508 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2019-09-04 05:28:16.260  INFO 2508 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2019-09-04 05:28:16.263  INFO 2508 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2019-09-04 05:28:16.559  INFO 2508 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2019-09-04 05:28:17.740  INFO 2508 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2019-09-04 05:28:19.002  WARN 2508 --- [           main] o.h.b.i.SessionFactoryBuilderImpl        : Unrecognized hbm2ddl_auto value : update  .  Supported values include create, create-drop, update, and validate.  Ignoring
2019-09-04 05:28:20.031  INFO 2508 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-09-04 05:28:24.577  INFO 2508 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2019-09-04 05:28:24.607  INFO 2508 --- [           main] c.s.mirrorworld.mirrorworldApplication   : Started mirrorworldApplication in 13.439 seconds (JVM running for 24.733)
2019-09-04 05:28:33.326  INFO 2508 --- [WT-EventQueue-0] o.h.h.i.QueryTranslatorFactoryInitiator  : HHH000397: Using ASTQueryTranslatorFactory
2019-09-04 05:28:33.844  WARN 2508 --- [WT-EventQueue-0] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 1054, SQLState: 42S22
2019-09-04 05:28:33.845 ERROR 2508 --- [WT-EventQueue-0] o.h.engine.jdbc.spi.SqlExceptionHelper   : Unknown column 'p.Groupunit_Definer.Classification' in 'where clause'
Exception in thread "AWT-EventQueue-0" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    at ……
org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:375)
    at ……
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    at …...
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'p.Groupunit_Definer.Classification' in 'where clause'

通过将createNativeQuery更改为createQuery,问题已经解决,谢谢您

这里真的需要targetEntity=Place\u Definer.class吗?如果GROUPUNIT_DEFINER列在PLACE表中,我通常不会显式给出它,它将使用当前表PLACE中的列。类中是否缺少@Tablename=PLACE…或者类似的东西?不确定是否需要它,或者Spring是否可以从类名中检测表名?您混淆了JPQL和SQL。SQL使用表名和列名,并具有select*。JPAL使用实体名称及其属性,没有select*。谢谢JB Nizet,我将句子改为从p处选择p.*,p.Groupunit_Definer.Classification='Judiction',但没有使用。关于EntityManager的createNativeQuery方法,我想知道SQL语句是否可以是任何SQL语言,如SQL、JPQL或HQL?
:: Spring Boot ::       (v1.5.21.RELEASE)

2019-09-04 05:28:11.851  INFO 2508 --- [           main] c.s.mirrorworld.mirrorworldApplication   : Starting mirrorworldApplication on LAPTOP-FAS0SHLM with PID 2508 (C:\Users\yueho\eclipse-workspace\mirrorworld\target\classes started by yueho in C:\Users\yueho\eclipse-workspace\mirrorworld)
2019-09-04 05:28:11.859  INFO 2508 --- [           main] c.s.mirrorworld.mirrorworldApplication   : No active profile set, falling back to default profiles: default
2019-09-04 05:28:12.066  INFO 2508 --- [           main] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@2f217633: startup date [Wed Sep 04 05:28:12 CST 2019]; root of context hierarchy
2019-09-04 05:28:15.937  INFO 2508 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2019-09-04 05:28:15.994  INFO 2508 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2019-09-04 05:28:16.257  INFO 2508 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate Core {5.0.12.Final}
2019-09-04 05:28:16.260  INFO 2508 --- [           main] org.hibernate.cfg.Environment            : HHH000206: hibernate.properties not found
2019-09-04 05:28:16.263  INFO 2508 --- [           main] org.hibernate.cfg.Environment            : HHH000021: Bytecode provider name : javassist
2019-09-04 05:28:16.559  INFO 2508 --- [           main] o.hibernate.annotations.common.Version   : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2019-09-04 05:28:17.740  INFO 2508 --- [           main] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2019-09-04 05:28:19.002  WARN 2508 --- [           main] o.h.b.i.SessionFactoryBuilderImpl        : Unrecognized hbm2ddl_auto value : update  .  Supported values include create, create-drop, update, and validate.  Ignoring
2019-09-04 05:28:20.031  INFO 2508 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2019-09-04 05:28:24.577  INFO 2508 --- [           main] o.s.j.e.a.AnnotationMBeanExporter        : Registering beans for JMX exposure on startup
2019-09-04 05:28:24.607  INFO 2508 --- [           main] c.s.mirrorworld.mirrorworldApplication   : Started mirrorworldApplication in 13.439 seconds (JVM running for 24.733)
2019-09-04 05:28:33.326  INFO 2508 --- [WT-EventQueue-0] o.h.h.i.QueryTranslatorFactoryInitiator  : HHH000397: Using ASTQueryTranslatorFactory
2019-09-04 05:28:33.844  WARN 2508 --- [WT-EventQueue-0] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 1054, SQLState: 42S22
2019-09-04 05:28:33.845 ERROR 2508 --- [WT-EventQueue-0] o.h.engine.jdbc.spi.SqlExceptionHelper   : Unknown column 'p.Groupunit_Definer.Classification' in 'where clause'
Exception in thread "AWT-EventQueue-0" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    at ……
org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:375)
    at ……
Caused by: org.hibernate.exception.SQLGrammarException: could not extract ResultSet
    at …...
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'p.Groupunit_Definer.Classification' in 'where clause'