如注释中所述,使用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();


