为了账号安全,请及时绑定邮箱和手机立即绑定

Hibernate 查询班级中包含的学生 出错

http://img1.sycdn.imooc.com//59310d4c00016e8211880149.jpg


控制台详细信息

Exception in thread "main" org.hibernate.InstantiationException: No default constructor for entity:  : com.imooc.entity.Student

at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:120)

at org.hibernate.tuple.PojoInstantiator.instantiate(PojoInstantiator.java:136)

at org.hibernate.tuple.entity.AbstractEntityTuplizer.instantiate(AbstractEntityTuplizer.java:737)

at org.hibernate.persister.entity.AbstractEntityPersister.instantiate(AbstractEntityPersister.java:4755)

at org.hibernate.internal.SessionImpl.instantiate(SessionImpl.java:1387)

at org.hibernate.internal.SessionImpl.instantiate(SessionImpl.java:1375)

at org.hibernate.loader.plan.exec.process.internal.EntityReferenceInitializerImpl.hydrateEntityState(EntityReferenceInitializerImpl.java:235)

at org.hibernate.loader.plan.exec.process.internal.AbstractRowReader.readRow(AbstractRowReader.java:107)

at org.hibernate.loader.plan.exec.process.internal.ResultSetProcessorImpl.extractResults(ResultSetProcessorImpl.java:129)

at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:138)

at org.hibernate.loader.plan.exec.internal.AbstractLoadPlanBasedLoader.executeLoad(AbstractLoadPlanBasedLoader.java:102)

at org.hibernate.loader.collection.plan.AbstractLoadPlanBasedCollectionInitializer.initialize(AbstractLoadPlanBasedCollectionInitializer.java:102)

at org.hibernate.persister.collection.AbstractCollectionPersister.initialize(AbstractCollectionPersister.java:693)

at org.hibernate.event.internal.DefaultInitializeCollectionEventListener.onInitializeCollection(DefaultInitializeCollectionEventListener.java:92)

at org.hibernate.internal.SessionImpl.initializeCollection(SessionImpl.java:1893)

at org.hibernate.collection.internal.AbstractPersistentCollection$4.doWork(AbstractPersistentCollection.java:555)

at org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:260)

at org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:551)

at org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:140)

at org.hibernate.collection.internal.PersistentSet.iterator(PersistentSet.java:180)

at com.imooc.entity.Test.findStudentsByGrade(Test.java:42)

at com.imooc.entity.Test.main(Test.java:14)


正在回答

1 回答

实体类没有空的构造方法

添加一下代码 就解决了

http://img1.sycdn.imooc.com//593112ee0001861f05310384.jpg

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
Hibernate初探之一对多映射
  • 参与学习       42171    人
  • 解答问题       295    个

Hibernate中一对多关联映射配置,以及cascade和inverse属性作用

进入课程

Hibernate 查询班级中包含的学生 出错

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信