Skip to main content

Posts

Showing posts from September, 2013

How to rename hibernate auto generated Foreign key constraint names

When using hibernate maven plugin to generate your tables you may have noticed hibernate generates obfuscated foreign key constraint names which are unreadable. In order to change the constraint names you can apply the @ForeignKey annotation to give your foreign keys more meaningful names as shown below. Take note if you take this approach you will need to take by insuring no duplicate constraint names are created. import @org.hibernate.annotations.ForeignKey;   @ForeignKey( name = "FK_PI_COMPANY_ID" ) @ManyToOne(targetEntity = Company.class, fetch = FetchType.EAGER) @JoinColumn(name = "COMPANY_ID", nullable = true) private Company company;