1

I'm using Hibernate and I need to find a way of retrieving the relations for an object dynamically at run-time. I can't find this in the API.

Can anyone point me in the right direction?

tshepang
  • 12,111
  • 21
  • 91
  • 136
Michael Jones
  • 115
  • 2
  • 9
  • What do you mean by "relations for an object dynamically"? criteria API ? – khmarbaise May 18 '10 at 14:08
  • e.g. given a Person object that I could find out that there is a one-to-many relationship to PhoneNumber, and a one-to-one relationship to HomeTown – Michael Jones May 18 '10 at 14:32
  • I guess the following thread answers your question: http://stackoverflow.com/questions/1374748/determining-manytomany-vs-onetomany-using-classmetadata – luxerama May 19 '10 at 18:24

2 Answers2

1

What You look for is SessionFactory's getClassMetadata() method. It returns ClassMetadata object describing given entity.

Bartek Jablonski
  • 2,649
  • 24
  • 32
1

My best recommendation is to use plain JDBC DatabaseMetaData

DatabaseMetaData.getCrossReference

DatabaseMetaData.getImportedKeys

DatabaseMetaData.getExportedKeys

Examples

stacker
  • 68,052
  • 28
  • 140
  • 210