【发布时间】:2018-01-11 23:01:20
【问题描述】:
这个执行 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)
【问题讨论】:
-
尝试添加Course和Instructor的映射类
-
不明白你的意思。就像在这个例子中:stackoverflow.com/questions/20680859/…
-
有人报告了这个问题,我发布链接供您参考。 github.com/spring-projects/spring-boot/issues/7906