1

I've seen many examples and real-life projects where database table columns have a unique prefix that corresponds to the table name. Small example:

CREATE TABLE customers (cus_id BIGINT, cus_name VARCHAR(255), cus_adr_id BIGINT);
CREATE TABLE addresses (adr_id BIGINT, adr_postcode CHAR(5));

How can I accomplish this in Hibernate or JPA?

I already tried to implement PhysicalNamingStrategy but that doesn't seem to have access to the entity itself so I have no way to know the entity when setting the column name.

I now hope that there is a better way than placing annotations above every single variable declaration. That's pretty verbose and doesn't fit to my expectations to ORM which in my eyes should ideally provide an automatic way of mapping. Moreover, the ID and other properties that are shared among entities I have to keep in a base-class entity which makes the annotations even more complicated.

FarwoodHill
  • 552
  • 1
  • 9
  • 18
  • No, You have to create a custom naming strategy. You should refer to the post http://stackoverflow.com/questions/4313095/jpa-hibernate-and-custom-table-prefixes – David Pham Feb 07 '17 at 12:34
  • The mentioned post does not address the same situation: They have a constant prefix while I have a prefix that is based on the table name. Moreover, I'm using Hibernate 5 and that means I cannot use ImprovedNamingStrategy. I have to create an implementation of PhysicalNamingStrategy or ImplicitNamingStrategy instead. – FarwoodHill Feb 07 '17 at 13:34

0 Answers0