• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can I specify a directory to add all JPA annotated classes to Hibernate configuration?

 
david zhang
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hello, I am learning Hibernate and JPA Annotation. The following is what I use to make Hibernate be aware of JPA-annotated classes:

......
config.addAnnotatedClass(Thing.class);
config.addAnnotatedClass(Fracture.class);
config.addAnnotatedClass(Interest.class);
config.addAnnotatedClass(Ancestor.class);
config.addAnnotatedClass(Parent.class);
......

It is very tedious to add every class like the above.

Is there any way I can use to specify all JPA-annotated classes in a directory?

Thanks for your help!

 
Ulas Ergin
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
adding the line
<property name="hibernate.archive.autodetection" value="class, hbm"/>
to your persistence.xml might help
 
david zhang
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ulas, thanks so so much for the tip!

I already use hibernate.cfg.xml. Can I use it together with persistence.xml or I have to use only one of them?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic