Is there a class that I could use in Hibernate so that I could pass in a class and it would return the appropriate database type name?
For example,
String type = HibernateTypeGod.getTypeName(String.class);
Hibernate would determine the dialect I specified and return me VARCHAR2 in the case of Oracle.
It's not that easy. All the mapping stuff is in the classes Configuration, Table, Column and Dialect, so you will need some kind of valid config to query this from Hibernate. But you can for example use:
String s = myDialect.getTypeName(sqlType,length,precision,scale);
Of course you need to find the dialect and the sqlType, but this isn't fixed in Hibernate on a class basis, but can be configured per column anyway, so what is the reason to ask by Class and not by column name?
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