有没有办法循环(例如通过for)所有类都在某个包中? 我要addAnnotatedClass(Class c)上AnnotationConfiguration。这样做:
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。
Tables.Informations
如评论中所述,使用AnnotationConfiguration API无法实现将所有类加载到包中的功能。这是您可以使用上述API进行的一些操作(请注意,“ addPackage”方法仅读取包元数据,例如在package-info.java类中找到的元数据,它不会加载包中的所有类):
http://docs.jboss.org/hibernate/annotations/3.5/reference/en/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();