执行Hibernate查询的代码作为Java程序运行正常,但如果我将其作为Spring Boot运行则失败 由于Hibernate 5.1中的错误,我可能会在某处读到它。可能是吗? 我使用的是Spring Boot 2.0。这会是一个问题吗?
@SpringBootApplication
public class SpringCd244ManyToManyBootApplication {
public static void main(String[] args) {
SpringApplication.run(SpringCd244ManyToManyBootApplication.class, args);
// create session factory
SessionFactory factory = new Configuration()
.configure("hibernate.cfg.xml")
.addAnnotatedClass(Instructor.class)
.addAnnotatedClass(InstructorDetail.class)
.addAnnotatedClass(Course.class)
.addAnnotatedClass(Review.class)
.addAnnotatedClass(Student.class)
.buildSessionFactory();
// create session
Session session = factory.getCurrentSession();
try {....
在Spring Boot中运行它时出错。有什么想法吗?
2018-01-11 20:45:33.261 INFO 5772 --- [ restartedMain] org.hibernate.orm.connections.pooling : HHH10001008: Cleaning up connection pool [jdbc:mysql://localhost:3306/webapp?useSSL=false]
Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private io.scalando.Instructor io.scalando.Course.instructor] by reflection for persistent property [io.scalando.Course#instructor] : Course [id=0, title=Pacman - How To Score One Million Points]
at org.hibernate.property.access.spi.GetterFieldImpl.get(GetterFieldImpl.java:74)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplizer.java:626)
答案 0 :(得分:2)
我有一个类似的问题,通过删除此依赖关系修复:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>