如何解决通过在某个包中添加所有类,在Hibernate中添加带注释的类爪哇
如注释中所述,使用AnnotationConfiguration API无法将所有类加载到包中。这是您可以使用上述API进行的一些操作(请注意,“ addPackage”方法仅读取包元数据,例如在package-info.java类中找到的元数据,它不会加载包中的所有类):
http://docs.jboss.org/hibernate/annotations/3.5/reference/zh/html/ch01.html
sessionFactory = new AnnotationConfiguration()
.addPackage("test.animals") //the fully qualified package name
.addAnnotatedClass(Flight.class)
.addAnnotatedClass(Sky.class)
.addAnnotatedClass(Person.class)
.addAnnotatedClass(Dog.class)
.addResource("test/animals/orm.xml")
.configure()
.buildSessionFactory();
解决方法
有没有办法循环(例如通过for)所有类都在某个包中? 我要addAnnotatedClass(Class
c)
上AnnotationConfiguration
。这样做:
AnnotationConfiguration annotationConfiguration.addAnnotatedClass(AdditionalInformation.class);
annotationConfiguration.addAnnotatedClass(AdditionalInformationGroup.class);
annotationConfiguration.addAnnotatedClass(Address.class);
annotationConfiguration.addAnnotatedClass(BankAccount.class);
annotationConfiguration.addAnnotatedClass(City.class);
//et cetera
我所有的表都放在包中Tables.Informations
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。