gpt4 book ai didi

java - Caused by : org. hibernate.property.access.spi.PropertyAccessException: 访问字段时出错

转载 作者:行者123 更新时间:2023-11-29 04:22:31 24 4
gpt4 key购买 nike

这段执行 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)

最佳答案

我有一个类似的问题,已通过删除此依赖项得到解决:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>

关于java - Caused by : org. hibernate.property.access.spi.PropertyAccessException: 访问字段时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48217195/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com