permaculture playing cards
The moose likes Object Relational Mapping and the fly likes Find @Entity classes in current project Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Find @Entity classes in current project" Watch "Find @Entity classes in current project" New topic

Find @Entity classes in current project

Mahesh Kedari
Ranch Hand

Joined: Nov 28, 2009
Posts: 111
Is there any way to get a list of all classes with @Entity annotation in current project?
I am using Netbeans IDE. In netbeans when i open persistence.xml in design mode, and click on Add Class button, i get a list of all classes in current project with @Entity annotation.
I wanted to get a similar list to manually configure Hibernate. Can anyone help me for this?

Thank you
Mahesh Kedari
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 423
If Netbeans does it, then you already have the list. And if your project is corrected structured, then all entities are in the model package.
Wouter Oet
Saloon Keeper

Joined: Oct 25, 2008
Posts: 2700

At runtime you can ask the provider all the entity classes for a given persistence-unit by invoking:

I do believe that this is JPA 2.0 only. Not sure.

"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
I agree. Here's the link:
subject: Find @Entity classes in current project
It's not a secret anymore!