views:

89

answers:

3

Hi,

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 please?

Thanks

+1  A: 

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

Bartek Jablonski
great thanks. but which methods do i need to call on the ClassMetadata object?
Michael Jones
+1  A: 

My best recommendation is to use plain JDBC DatabaseMetaData

DatabaseMetaData.getCrossReference

DatabaseMetaData.getImportedKeys

DatabaseMetaData.getExportedKeys

Examples

stacker
A: 

I guess the following thread answers your question: http://stackoverflow.com/questions/1374748/determining-manytomany-vs-onetomany-using-classmetadata

vincent