dinesh707
dinesh707

Reputation: 12582

How to set foreign key constraint name in hibernate

When I annotate a object inside my entity class as following

@ManyToOne
private User creator;

SchemaExport ends up creating "creator_id" in the entity table. (Which is good). But

 alter table Voucher 
        add constraint FK2DF5CE507B0A07EF 
        foreign key (creator_id) 
        references User;

the constraint name is randomly generated string. Which changers. Is there any annotation where I can set this constraint name ? (if there is such way I would like to know both annotation and hbm.xml configuration)

Upvotes: 0

Views: 2311

Answers (1)

JB Nizet
JB Nizet

Reputation: 691715

Use the @ForeignKey annotation.

Upvotes: 3

Related Questions