首页 > Web开发 > 详细

Hibernate使用注解时的问题

时间:2015-01-30 17:15:16      阅读:434      评论:0      收藏:0      [点我收藏+]

在使用注解进行Hibernate开发时、报了一个如下的错误

Exception in thread "main" org.hibernate.AnnotationException: No identifier specified for entity: com.eyang.hibernate.model.Qygd
	at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:277)
	at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:224)
	at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:775)
	at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:3788)
	at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3742)
	at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1410)
	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
	at QygdTest.main(QygdTest.java:23)

经查证是在Model类中没有给主键添加注解、也就是说在使用Hibernate进行开发时必须指定表的主键才能正常运行、

在对应属性的get方法上添加@Id注解即可

 

另外还发现了一个现象、即使用xml配置文件和注解进行数据的添加时

若表中有10个字段、Model中也有十个属性与之对应、

在xml文件中、我们可以只写其中的3个或者几个字段则生成的sql中只有对应的这几个字段的值、而没有配置的则不会在sql中生成、

在使用注解时、Model中的十个属性也会全部在sql中生成、

Hibernate使用注解时的问题

原文:http://www.cnblogs.com/keryang/p/4262696.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!