春季启动hibernate查询无效的用户错误

春季启动hibernate查询无效的用户错误

本文介绍了春季启动hibernate查询无效的用户错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 您好,我是Spring Boot的新手。我尝试连接到Oracle并列出相关记录。我的代码工作在一个存根环境,这是没有连接到数据库。当我试图从Spring连接到数据库时,出现了EDIT 2中给出的错误: $ b HomeController package blog.controllers; 导入blog.models.Post; 导入blog.services.PostService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import java.util.List; import java.util.stream.Collectors; @Controller public class HomeController { @Autowired PostService postService; @RequestMapping(/) public String index(Model model){ List< Post> latest5Posts = postService.findLatest5(); model.addAttribute(latest5posts,latest5Posts); 列表< Post> latest3Posts = latest5Posts.stream() .limit(3).collect(Collectors.toList()); model.addAttribute(latest3posts,latest3Posts); 返回index; $ b 文章实体类 package blog.models; import javax.persistence。*; import java.util.Date; @Entity @Table(name =POSTS) public class Post { @Id @GeneratedValue(strategy = GenerationType.IDENTITY)私人长ID; @Column(nullable = false,长度= 300)私有字符串标题; @Lob @Column(nullable = false)私人字符串正文; @ManyToOne(可选= false,fetch = FetchType.LAZY)私人用户作者; @Column(nullable = false)私有日期creation_date = new Date(); public long getId(){return id;} public void setId(Long id){this.id = id;} public String getTitle(){return title; } public void setBit(String title){this.title = title;} public String getBody(){return body;} public void setBody(String body){this.body = body;} public User getAuthor(){return author;} public void setAuthor(User author){this.author = author;} public Date getCreation_date(){return date;} public void setCreation_date(Date creation_date){this.creation_date = creation_date;} public Post(){} $ b $ public Post(Long id,String title,字符串正文,用户作者){ this.id = id; this.title =标题; this.body =主体; this.author =作者; } @Override public String toString(){ returnPost {+id =+ id +,title ='+ title +'\''+ ,body ='+ body +'\''+ ,author ='+ author +'\''+ ,date =+ Creationdate + '}'; $ b 用户实体类 package blog.models; import javax.persistence。*; import java.util.HashSet; import java.util.Set; @Entity @Table(name =users) public class User { @Id @ GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(nullable = false,长度= 30,unique = true)私人字符串用户名; @Column(length = 60) private String passwordHash; @Column(length = 100) private String fullName; @OneToMany(mappedBy =author) private Set< Post> posts = new HashSet<>(); $ b $ public long getId(){return id;} public void setId(Long id){this.id = id;} public String getUsername(){return username;} $ b $ public void setUsername(String username){this.username = username;} $ b $ public String getPasswordHash(){返回passwordHash;} public void setPasswordHash(String passwordHash){this.passwordHash = passwordHash;} public String getFullName(){return fullName;} public void setFullName(String fullName){this.fullName = fullName;} public Set< Post> getPosts(){return posts;} public void setPosts(Set< post> posts){this.posts = posts;} $ b $ public User(){} public User(Long id,String username,String fullName){ this.id = id; this.username = username; this.fullName = fullName; $ b @Override public String toString(){ returnUser {+id =+ id +,username ='+ username +'\''+ ,passwordHash ='+ passwordHash +'\''+ ,fullName ='+ fullName +'\''+'}'; } } 存储库 package blog.repositories; 导入blog.models.Post; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; import org.springframework.stereotype.Repository; 导入org.springframework.data.domain.Pageable; import java.util.List; @Repository 公共接口PostRepository扩展JpaRepository< Post,Long> { @Query(SELECT p FROM Post p LEFT JOIN FETCH p.author ORDER BY p.creation_date DESC) List< Post> findLatest5Posts(可分页); } 服务 package blog.services; 导入blog.models.Post; import org.springframework.stereotype.Service; import java.util.List; @Service public interface PostService { List< Post>找到所有(); 列表< Post> findLatest5(); 发布findById(Long id); 发布创建(发布帖子); 发布编辑(发布帖子); void deleteById(Long id); } 服务实施 $ b package blog.services; 导入blog.models.Post; 导入blog.repositories.PostRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Primary; import org.springframework.data.domain.PageRequest; import org.springframework.stereotype.Service; import java.util.List; @Service @Primary 公共类PostServiceJpaImpl实现PostService { @Autowired 私有PostRepository postRepository; @Override public List< Post> findAll(){ return this.postRepository.findAll(); } @Override public List< Post> findLatest5(){ return this.postRepository.findLatest5Posts(new PageRequest(0,5)); } @Override public Post findById(Long id){ return this.postRepository.findOne(id); } @Override public Post创建(Post post){ return this.postRepository.save(post); } @Override public Post(发布){ return this.postRepository.save(post); } @Override public void deleteById(Long id){ this.postRepository.delete(id); 至于db中的表格: create table users( id number, username varchar2(30), passwordHash varchar2(60 ), fullName varchar2(100),约束users_pk主键(id)); 创建表格帖子( id号码, author_id号码, title varchar2(300), body clob, creation_date timestamp, 主键(id)); p.s。通过更改存储库,我也尝试了以下方法: @Query(value =SELECT * FROM POSTS aa LEFT JOIN USERS bb ON aa.AUTHOR_ID = bb.ID,nativeQuery = true) 以下错误: org.springframework.beans.factory.BeanCreationException:创建名为'entityManagerFactory'的bean时出错在类路径资源[org / springframework / boot / autoconfigure / orm / jpa / HibernateJpaAutoConfiguration.class]中定义:调用init方法失败;嵌套异常是javax.persistence.PersistenceException:[PersistenceUnit:default]无法构建Hibernate SessionFactory ... 引起:org.hibernate.tool.schema.spi.SchemaManagementException:无法执行纲要管理到JDBC目标[alter table posts add constraint FK6xvn0811tkyo3nfjk2xvqx6ns foreign key(author_id)references users] at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:59)〜[hibernate-core- 5.0.9.Final.jar:5.0.9.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlString(SchemaMigratorImpl.java:431)〜[hibernate-core-5.0.9.Final .jar:5.0.9.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlStrings(SchemaMigratorImpl.java:420)〜[hibernate-core-5.0.9.Final.jar:5.0。 9.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applyForeignKeys(SchemaMigratorImpl.java:386)〜[hibernate-core-5.0.9.Final.jar:5.0.9.Final] A t org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:214)〜[hibernate-core-5.0.9.Final.jar:5.0.9.Final] org.hibernate。 tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:60)〜[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.tool.hbm2ddl.SchemaUpdate .execute(SchemaUpdate.java:134)〜[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java: 101)〜[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.internal.SessionFactoryImpl。< init>(SessionFactoryImpl.java:470)〜[hibernate- core-5.0.9.Final.jar:5.0.9.Final] 在org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)〜[hibernate-core-5.0.9.Final .jar:5.0.9.Final] 在org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)〜[hibernate-entity manager-5.0.9.Final.jar:5.0.9.Final] ...省略了27个常见框架导致:java.sql.SQLSyntaxErrorException:ORA-02268:引用的表没有主键 at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle。 jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395)〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802 )〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)〜[ojdbc6-11.2.0.4.jar:11.2。 0.1.0] at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc。 driver.T4C8Oall.doOALL(T4C8Oall.java:521)〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:194)〜 [ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:1 000)〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1307)〜[ojdbc6-11.2.0.4.jar:11.2 .0.1.0] at oracle.jdbc.driver.OracleStatement.executeUpdateInternal(OracleStatement.java:1814)〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc .driver.OracleStatement.executeUpdate(OracleStatement.java:1779)〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.OracleStatementWrapper.executeUpdate(OracleStatementWrapper.java:277) 〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:56)〜[hibernate-core-5.0.9 .Final.jar:5.0.9.Final] ... 37个常见框架省略 我缺少什么? 预先感谢! 编辑: POM.XML < ?xml version =1.0encoding =UTF-8?> < project xmlns =http://maven.apache.org/POM/4.0.0 xmlns:xsi =http://www.w3.org/2001/XMLSchema-instance xsi:schemaLocation =http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\"> < modelVersion> 4.0.0< / modelVersion> < groupId> softuni< / groupId> < artifactId> mvc-blog< / artifactId> < version> 1.0-SNAPSHOT< / version> < parent> < groupId> org.springframework.boot< / groupId> < artifactId> spring-boot-starter-parent< / artifactId> < version> 1.4.0.RELEASE< / version> < / parent> <依赖关系> < dependency> < groupId> org.springframework.boot< / groupId> < artifactId> spring-boot-starter-thymeleaf< / artifactId> <排除项> <排除> < artifactId> jackson-databind< / artifactId> < groupId> com.fasterxml.jackson.core< / groupId> < /排除> < /排除> < /依赖关系> < dependency> < groupId> org.springframework.boot< / groupId> < artifactId> spring-boot-devtools< / artifactId> < /依赖关系> < dependency> < groupId> org.scala-lang< / groupId> < artifactId> scala-library< / artifactId> < version> 2.10.0< / version> < /依赖关系> < dependency> < groupId>余弦-lsh< / groupId> < artifactId> cosinelsh< / artifactId> < version> 1.0< / version> < /依赖关系> < dependency> < groupId> org.springframework.data< / groupId> < artifactId> spring-data-jpa< / artifactId> < /依赖关系> < dependency> < groupId> org.springframework.boot< / groupId> < artifactId> spring-boot-starter-data-jpa< / artifactId> < /依赖关系> < dependency> < groupId> com.oracle< / groupId> < artifactId> ojdbc6< / artifactId> < version> 11.2.0.4< / version> < /依赖关系> < /依赖关系> <属性> < java.version> 1.8< /java.version> < spark.version> 1.4.1< /spark.version> <! - < scala.version> 2.10.0< /scala.version> - > < / properties> < / project> application.properties #关闭Thymeleaf缓存 spring.thymeleaf.cache = false spring.datasource.driver-class-name = oracle.jdbc .driver.OracleDriver spring.datasource.url = jdbc:oracle:thin:@ ... spring.datasource.username = usrnm spring.datasource.password = psswrd #配置Hibernate DDL模式:创建/更新 spring.jpa.properties.hibernate.hbm2ddl.auto =更新 #hibernate配置 spring.jpa.database-platform = org .hibernate.dialect.Oracle10gDialect spring.jpa.hibernate.naming.physical-strategy = org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl spring.data.jpa .repositories.enabled = true #显示或不记录每个sql查询 spring.jpa.show-sql = true 用户存储库 包博客.repositories; 导入blog.models.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; @Repository public interface UserRepository扩展JpaRepository< User,Long> {} 用户服务 package blog.services; 导入blog.models.User; import java.util.List; public interface UserService { List< User>找到所有(); 用户findById(Long id); 用户创建(用户用户); 用户编辑(用户用户); void deleteById(Long id); 用户服务实施 package blog.services; 导入blog.models.User; 导入blog.repositories.UserRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Service; import java.util.List; @Service @Primary public class UserServiceJpaImpl实现UserService { @Autowired private UserRepository userRepository; @Override public List< User> findAll(){ return this.userRepository.findAll(); } @Override public User findById(Long id){ return this.userRepository.findOne(id); } @Override public User(User user){ return this.userRepository.save(user); } @Override public用户编辑(用户用户){返回this.userRepository.save(user); } @Override public void deleteById(Long id){ this.userRepository.delete(id); @SpringBootApplication p> package blog; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class BlogMvcApplication { public static void main(String [] args){ SpringApplication .run(BlogMvcApplication.class,args);编辑2: $ b编辑2: / strong> JPA查询的错误行(未使用本机查询时) java.sql.SQLSyntaxErrorException:ORA-01747:无效的user.table.column,table.column或列规范 at oracle.jdbc.driver .T4CTTIoer.processError(T4CTTIoer.java:439)〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395)〜[ ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802)〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0 ] at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CTTIfun .doRPC(T4CTTIfun.java:186)〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521)〜[ojdbc6- 11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CPreparedStatement.doO all8(T4CPreparedStatement.java:205)〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:861)〜[ojdbc6-11.2 .0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1145)〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1267)〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.OraclePreparedStatement.executeInternal( OraclePreparedStatement.java:3449)〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3493)〜[ojdbc6-11.2.0.4 .jar:11.2.0.1.0] at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1491)〜[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70)〜[hi bernate-core-5.0.9.Final.jar:5.0.9.Final] 在org.hibernate.loader.Loader.getResultSet(Loader.java:2117)〜[hibernate-core-5.0.9.Final .jar:5.0.9.Final] 在org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1900)〜[hibernate-core-5.0.9.Final.jar:5.0.9.Final] 在org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1876)〜[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate。 loader.Loader.doQuery(Loader.java:919)〜[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java :336)〜[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.loader.Loader.doList(Loader.java:2617)〜[hibernate-core- 5.0.9.Final.jar:5.0.9.Final] 在org.hibernate.loader.Loader.doList(Loader.java:2600)〜[hibernate-core-5.0.9.Final.jar:5.0 .9.Final] 在org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2429)〜[hibernate-core-5.0.9.Final.jar:5。 0.9.Final] 在org.hibernate.loader.Loader.list(Loader.java:2424)〜[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:501)〜[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.hql.internal .ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371)〜[hibernate-core-5.0.9.Final.jar:5.0.9.Final] 位于org.hibernate.engine.query.spi.HQLQueryPlan。执行列表(HQLQueryPlan.java:216)〜[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1326)〜 [hibernate-core-5.0.9.Final.jar:5.0.9.Final] 在org.hibernate.internal.QueryImpl.list(QueryImpl.java:87)〜[hibernate-core-5.0.9。 Final.jar:5.0.9.Final] 在org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:606)〜[hibernate-entitymanager-5.0.9.Final.jar:5.0.9 .Final] 在org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:483)〜[hibernate-entitymanager-5.0 .9.Final.jar:5.0.9.Final] at org.springframework.data.jpa.repository.query.JpaQueryExecution $ CollectionExecution.doExecute(JpaQueryExecution.java:114)〜[spring-data-jpa- 1.10.2.RELEASE.jar:na] 在org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:78)〜[spring-data-jpa-1.10.2.RELEASE .jar:na] at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:102)〜[spring-data-jpa-1.10.2.RELEASE.jar:na] at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:92)〜[spring-data-jpa-1.10.2.RELEASE.jar:na] at org.springframework.data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:482)〜[spring-data-commons-1.12.2.RELEASE.jar:na] at org.springframework .data.repository.core.support.RepositoryFactorySupport $ QueryExecutorMethodInterceptor.invoke(RepositoryFact orySupport.java:460)〜[spring-data-commons-1.12.2.RELEASE.jar:na] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)〜[spring -aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61)〜[spring-data-commons-1.12。 2.RELEASE.jar:na] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)〜[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE ] at org.springframework.transaction.interceptor.TransactionInterceptor $ 1.proceedWithInvocation(TransactionInterceptor.java:99)〜[spring-tx-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:280)〜[spring-tx-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.transaction.intercepto r.TransactionInterceptor.invoke(TransactionInterceptor.java:96)〜[spring-tx-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation .java:179)〜[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136)〜[ spring-tx-4.3.2.RELEASE.jar:4.3.2.RELEASE] 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)〜[spring-aop-4.3.2 .RELEASE.jar:4.3.2.RELEASE] at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor $ CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133)〜[spring-data-jpa-1.10。 2.RELEASE.jar:na] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)〜[spring-aop-4.3.2.RELEAS E.jar:4.3.2.RELEASE] 在org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)〜[spring-aop-4.3.2.RELEASE.jar:4.3.2 .RELEASE] 在org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)〜[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] 在com.sun.proxy上的org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)〜[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] 。 $ Proxy87.findLatest5Posts(Unknown Source)〜[na:na] at blog.services.PostServiceJpaImpl.findLatest5(PostServiceJpaImpl.java:23)〜[classes /:na] at blog.controllers.HomeController .index(HomeController.java:26)〜[classes /:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)〜[na:1.8.0_31] at sun.reflect.NativeMethodAccessorImpl .invoke(NativeMethodAccessorImpl.java:62)〜[na:1.8.0_31] at sun.reflect.DelegatingMethodAcce ssorImpl.invoke(DelegatingMethodAccessorImpl.java:43)〜[na:1.8.0_31] at java.lang.reflect.Method.invoke(Method.java:483)〜[na:1.8.0_31] 在org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)〜[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] 在org.springframework .web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)〜[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] 在org.springframework.web.servlet。 mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)〜[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.servlet.mvc .method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)〜[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.servlet.mvc。 method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMa ppingHandlerAdapter.java:738)〜[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java :85)〜[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE] 在org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)〜[spring- webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE] 在org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)〜[spring-webmvc-4.3.2.RELEASE .jar:4.3.2.RELEASE] 在org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)〜[spring-webmvc-4.3.2.RELEASE.jar:4.3.2。 at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)〜[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)〜[tomcat-embed-core-8.5.4.jar:8.5.4] at org.springframework.web.ser vlet.FrameworkServlet.service(FrameworkServlet.java:846)〜[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java :729)〜[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)〜[tomcat-embed- core-8.5.4.jar:8.5.4] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)〜[tomcat-embed-core-8.5.4.jar:8.5 .4] 在org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)〜[tomcat-embed-websocket-8.5.4.jar:8.5.4] 在org.apache.catalina.core上的org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)〜[tomcat-embed-core-8.5.4.jar:8.5.4] 。 ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)〜[tomcat-embed-core-8.5.4.jar:8.5.4] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(Reques tContextFilter.java:99)〜[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)〜 [spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)〜[tomcat-embed-core- 8.5.4.jar:8.5.4] 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)〜[tomcat-embed-core-8.5.4.jar:8.5.4 ] at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87)〜[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org .springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)〜[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.apache.catalina.core。 ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)〜[tomcat-embed-core-8.5.4.jar:8.5.4] 在org.apache.catalina。 core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)〜[tomcat-embed-core-8.5.4.jar:8.5.4] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java :77)〜[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)〜[spring- web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)〜[tomcat-embed-core-8.5.4 .jar:8.5.4] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)〜[tomcat-embed-core-8.5.4.jar:8.5.4] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197)〜[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] 解决方案 因为... e这个属性: pre $ spring.jpa.properties.hibernate.hbm2ddl.auto =更新 事实上,Posts实体已经被更改为引用User,Hibernate尝试添加一个外键约束: alter table posts添加约束FK6xvn0811tkyo3nfjk2xvqx6ns外键(author_id)引用用户 但是得到这个错误: ORA-02268:被引用的表没有主键 不知道为什么hibernate没有为该表添加主键,因为@Id注释是显然有。 尝试手动添加主键约束到Users.id列: ALTER TABLE用户 ADD CONSTRAINT users_pk PRIMARY KEY(id); 更新 文档说: $ b $ b 必须为持久字段或类型为java.util.Date和java.util.Calendar的属性指定此注释。它可能只是为这些类型的字段或属性指定的。 当您使用java.util.Date时,那么你需要添加这个: @Temporal(TemporalType.DATE) private date date = new Date() ; Hi I am new to Spring Boot. I try to connect to Oracle and list related records. My code worked in a stub environment, that is without connecting to a db. When I tried to connect to the db from Spring, I got the error as given in EDIT 2:HomeControllerpackage blog.controllers;import blog.models.Post;import blog.services.PostService;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;import java.util.List;import java.util.stream.Collectors;@Controllerpublic class HomeController { @Autowired private PostService postService; @RequestMapping("/") public String index(Model model){ List<Post> latest5Posts = postService.findLatest5(); model.addAttribute("latest5posts", latest5Posts); List<Post> latest3Posts = latest5Posts.stream() .limit(3).collect(Collectors.toList()); model.addAttribute("latest3posts", latest3Posts); return "index"; }}Posts Entity classpackage blog.models;import javax.persistence.*;import java.util.Date;@Entity@Table(name = "POSTS")public class Post { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(nullable = false, length = 300) private String title; @Lob @Column(nullable = false) private String body; @ManyToOne(optional = false, fetch = FetchType.LAZY) private User author; @Column(nullable = false) private Date creation_date = new Date(); public Long getId() {return id;} public void setId(Long id) {this.id = id;} public String getTitle() {return title;} public void setTitle(String title) {this.title = title;} public String getBody() {return body;} public void setBody(String body) {this.body = body;} public User getAuthor() {return author;} public void setAuthor(User author) {this.author = author;} public Date getCreation_date() {return date;} public void setCreation_date(Date creation_date) {this.creation_date = creation_date;} public Post() { } public Post(Long id, String title, String body, User author) { this.id=id; this.title=title; this.body=body; this.author=author; } @Override public String toString() { return "Post{" + "id=" + id + ", title='" + title + '\'' + ", body='" + body + '\'' + ", author='" + author + '\'' + ", date=" + Creationdate + '}'; }}Users Entity classpackage blog.models;import javax.persistence.*;import java.util.HashSet;import java.util.Set;@Entity@Table(name = "users")public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; @Column(nullable = false, length = 30, unique = true) private String username; @Column(length = 60) private String passwordHash; @Column(length = 100) private String fullName; @OneToMany(mappedBy = "author") private Set<Post> posts = new HashSet<>(); public Long getId() {return id;} public void setId(Long id) {this.id = id;} public String getUsername() {return username;} public void setUsername(String username) {this.username = username;} public String getPasswordHash() {return passwordHash;} public void setPasswordHash(String passwordHash) {this.passwordHash = passwordHash;} public String getFullName() {return fullName;} public void setFullName(String fullName) {this.fullName = fullName;} public Set<Post> getPosts() {return posts;} public void setPosts(Set<Post> posts) {this.posts = posts;} public User() { } public User(Long id, String username, String fullName) { this.id = id; this.username = username; this.fullName = fullName; } @Override public String toString() { return "User{" + "id=" + id + ", username='" + username + '\'' + ", passwordHash='" + passwordHash + '\'' + ", fullName='" + fullName + '\'' + '}'; }}Repositorypackage blog.repositories;import blog.models.Post;import org.springframework.data.jpa.repository.JpaRepository;import org.springframework.data.jpa.repository.Query;import org.springframework.stereotype.Repository;import org.springframework.data.domain.Pageable;import java.util.List;@Repositorypublic interface PostRepository extends JpaRepository<Post, Long> { @Query("SELECT p FROM Post p LEFT JOIN FETCH p.author ORDER BY p.creation_date DESC") List<Post> findLatest5Posts(Pageable pageable);}Servicepackage blog.services;import blog.models.Post;import org.springframework.stereotype.Service;import java.util.List;@Servicepublic interface PostService { List<Post> findAll(); List<Post> findLatest5(); Post findById(Long id); Post create(Post post); Post edit(Post post); void deleteById(Long id);}Service Implementationpackage blog.services;import blog.models.Post;import blog.repositories.PostRepository;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Primary;import org.springframework.data.domain.PageRequest;import org.springframework.stereotype.Service;import java.util.List;@Service@Primarypublic class PostServiceJpaImpl implements PostService { @Autowired private PostRepository postRepository; @Override public List<Post> findAll() { return this.postRepository.findAll(); } @Override public List<Post> findLatest5() { return this.postRepository.findLatest5Posts(new PageRequest(0, 5)); } @Override public Post findById(Long id) { return this.postRepository.findOne(id); } @Override public Post create(Post post) { return this.postRepository.save(post); } @Override public Post edit(Post post) { return this.postRepository.save(post); } @Override public void deleteById(Long id) { this.postRepository.delete(id); }}As for my tables in the db:create table users (id number,username varchar2(30),passwordHash varchar2(60),fullName varchar2(100),constraint users_pk primary key (id));create table posts (id number,author_id number,title varchar2(300),body clob,creation_date timestamp,primary key (id));p.s. I have also tried the following by changing the repository:@Query(value = "SELECT * FROM POSTS aa LEFT JOIN USERS bb ON aa.AUTHOR_ID=bb.ID", nativeQuery = true)This time I had the following error: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory at ...Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Unable to execute schema management to JDBC target [alter table posts add constraint FK6xvn0811tkyo3nfjk2xvqx6ns foreign key (author_id) references users] at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:59) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlString(SchemaMigratorImpl.java:431) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applySqlStrings(SchemaMigratorImpl.java:420) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.applyForeignKeys(SchemaMigratorImpl.java:386) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:214) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:60) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:134) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:101) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:470) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.9.Final.jar:5.0.9.Final] ... 27 common frames omittedCaused by: java.sql.SQLSyntaxErrorException: ORA-02268: referenced table does not have a primary key at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CStatement.doOall8(T4CStatement.java:194) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CStatement.executeForRows(T4CStatement.java:1000) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1307) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.OracleStatement.executeUpdateInternal(OracleStatement.java:1814) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.OracleStatement.executeUpdate(OracleStatement.java:1779) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.OracleStatementWrapper.executeUpdate(OracleStatementWrapper.java:277) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at org.hibernate.tool.schema.internal.TargetDatabaseImpl.accept(TargetDatabaseImpl.java:56) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] ... 37 common frames omittedWhat am I missing?Thanks in advance!EDIT:POM.XML<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>softuni</groupId> <artifactId>mvc-blog</artifactId> <version>1.0-SNAPSHOT</version> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.4.0.RELEASE</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> <exclusions> <exclusion> <artifactId>jackson-databind</artifactId> <groupId>com.fasterxml.jackson.core</groupId> </exclusion> </exclusions> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> </dependency> <dependency> <groupId>org.scala-lang</groupId> <artifactId>scala-library</artifactId> <version>2.10.0</version> </dependency> <dependency> <groupId>cosine-lsh</groupId> <artifactId>cosinelsh</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>com.oracle</groupId> <artifactId>ojdbc6</artifactId> <version>11.2.0.4</version> </dependency> </dependencies> <properties> <java.version>1.8</java.version> <spark.version>1.4.1</spark.version> <!--<scala.version>2.10.0</scala.version>--> </properties></project>application.properties#Turn off Thymeleaf cachespring.thymeleaf.cache = falsespring.datasource.driver-class-name = oracle.jdbc.driver.OracleDriverspring.datasource.url = jdbc:oracle:thin:@...spring.datasource.username = usrnmspring.datasource.password = psswrd# Configure Hibernate DDL mode: create / updatespring.jpa.properties.hibernate.hbm2ddl.auto = update#hibernate configspring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialectspring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImplspring.data.jpa.repositories.enabled=true# Show or not log for each sql queryspring.jpa.show-sql = trueuser repositorypackage blog.repositories;import blog.models.User;import org.springframework.data.jpa.repository.JpaRepository;import org.springframework.stereotype.Repository;@Repositorypublic interface UserRepository extends JpaRepository<User, Long> {}user servicepackage blog.services;import blog.models.User;import java.util.List;public interface UserService { List<User> findAll(); User findById(Long id); User create(User user); User edit(User user); void deleteById(Long id);}user service implementationpackage blog.services;import blog.models.User;import blog.repositories.UserRepository;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Primary;import org.springframework.stereotype.Service;import java.util.List;@Service@Primarypublic class UserServiceJpaImpl implements UserService { @Autowired private UserRepository userRepository; @Override public List<User> findAll() { return this.userRepository.findAll(); } @Override public User findById(Long id) { return this.userRepository.findOne(id); } @Override public User create(User user) { return this.userRepository.save(user); } @Override public User edit(User user) { return this.userRepository.save(user); } @Override public void deleteById(Long id) { this.userRepository.delete(id); }}@SpringBootApplicationpackage blog;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplicationpublic class BlogMvcApplication { public static void main(String[] args) { SpringApplication.run(BlogMvcApplication.class, args); }}EDIT 2:Error lines for JPA query (when native query is not used)java.sql.SQLSyntaxErrorException: ORA-01747: invalid user.table.column, table.column, or column specification at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:205) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:861) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1145) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1267) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3449) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3493) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1491) ~[ojdbc6-11.2.0.4.jar:11.2.0.1.0] at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:70) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.loader.Loader.getResultSet(Loader.java:2117) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1900) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1876) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.loader.Loader.doQuery(Loader.java:919) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.loader.Loader.doList(Loader.java:2617) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.loader.Loader.doList(Loader.java:2600) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2429) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.loader.Loader.list(Loader.java:2424) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:501) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:371) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:216) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1326) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.internal.QueryImpl.list(QueryImpl.java:87) ~[hibernate-core-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:606) ~[hibernate-entitymanager-5.0.9.Final.jar:5.0.9.Final] at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:483) ~[hibernate-entitymanager-5.0.9.Final.jar:5.0.9.Final] at org.springframework.data.jpa.repository.query.JpaQueryExecution$CollectionExecution.doExecute(JpaQueryExecution.java:114) ~[spring-data-jpa-1.10.2.RELEASE.jar:na] at org.springframework.data.jpa.repository.query.JpaQueryExecution.execute(JpaQueryExecution.java:78) ~[spring-data-jpa-1.10.2.RELEASE.jar:na] at org.springframework.data.jpa.repository.query.AbstractJpaQuery.doExecute(AbstractJpaQuery.java:102) ~[spring-data-jpa-1.10.2.RELEASE.jar:na] at org.springframework.data.jpa.repository.query.AbstractJpaQuery.execute(AbstractJpaQuery.java:92) ~[spring-data-jpa-1.10.2.RELEASE.jar:na] at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:482) ~[spring-data-commons-1.12.2.RELEASE.jar:na] at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:460) ~[spring-data-commons-1.12.2.RELEASE.jar:na] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:61) ~[spring-data-commons-1.12.2.RELEASE.jar:na] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99) ~[spring-tx-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:280) ~[spring-tx-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:136) ~[spring-tx-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:133) ~[spring-data-jpa-1.10.2.RELEASE.jar:na] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213) ~[spring-aop-4.3.2.RELEASE.jar:4.3.2.RELEASE] at com.sun.proxy.$Proxy87.findLatest5Posts(Unknown Source) ~[na:na] at blog.services.PostServiceJpaImpl.findLatest5(PostServiceJpaImpl.java:23) ~[classes/:na] at blog.controllers.HomeController.index(HomeController.java:26) ~[classes/:na] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_31] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_31] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_31] at java.lang.reflect.Method.invoke(Method.java:483) ~[na:1.8.0_31] at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.5.4.jar:8.5.4] at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846) ~[spring-webmvc-4.3.2.RELEASE.jar:4.3.2.RELEASE] at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) ~[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52) ~[tomcat-embed-websocket-8.5.4.jar:8.5.4] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4] at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4] at org.springframework.web.filter.HttpPutFormContentFilter.doFilterInternal(HttpPutFormContentFilter.java:87) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4] at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar:8.5.4] at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar:8.5.4] at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:197) ~[spring-web-4.3.2.RELEASE.jar:4.3.2.RELEASE] 解决方案 It seems that the problem is following:Because of this property:spring.jpa.properties.hibernate.hbm2ddl.auto = updateAnd the fact that the Posts entity has been changed to reference the User, Hibernate tries to add a foreign key constraint:alter table posts add constraint FK6xvn0811tkyo3nfjk2xvqx6ns foreign key (author_id) references usersBut gets this error:ORA-02268: referenced table does not have a primary keyNot sure why hibernate does not add a primary key to this table as the @Id annotation is clearly there.Try to add a primary key constraint manually to the Users.id column:ALTER TABLE users ADD CONSTRAINT users_pk PRIMARY KEY (id);UpdateThe problem might with the Post.data mapping as you are using it in the order by clause.The doc says: This annotation must be specified for persistent fields or properties of type java.util.Date and java.util.Calendar. It may only be specified for fields or properties of these types.As you are using java.util.Date, then you need to add this:@Temporal(TemporalType.DATE)private Date date = new Date(); 这篇关于春季启动hibernate查询无效的用户错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-04 21:50