How can I access the Hibernate mapping of my model to find out the column name of a property?
The column name is not specified in the mapping so Hibernate generates it automatically - I would like to create a native SQL statement including this column name.
In hibernate, the preffered way to do this is by annotations. Annotations are piece of code that eases our work in mapping classes with tables, and methods with coulmns. Also, rows of tables to the Objects of the classes.
Though many Hibernate users choose to write the XML by hand, but a number of tools exist to generate the mapping document. These include XDoclet, Middlegen and AndroMDA for the advanced Hibernate users.
Thanks to Jherico I found out how to do that:
((Column) sessionFactoryBean.getConfiguration().getClassMapping(Person.class.getName())
.getProperty("myProperty").getColumnIterator().next()).getName();
((AbstractEntityPersister) sessionFactory.getClassMetadata(o.getClass()))
.getPropertyColumnNames(property)[0];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With