Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create foreign key in Hibernate on Integer column

I have an entity in Java and I would like Hibernate to create a foreign key from an Integer field (since I don't have an object reference):

@Entity
public class Invoice {

    ...
    @Column(nullable = true)
    private Integer generatedBy;
    ...

I think I'd like to do something like this with an attribute:

    @ForeignKey(name="FK_Invoice_GeneratedBy", references="UserTable.UserId")
    @Column(nullable = true)
    private Integer generatedBy;

What is the best way to achieve this? I would preferably not have to maintain these relationships in a separate file (if possible).

like image 974
AtliB Avatar asked Nov 05 '22 01:11

AtliB


1 Answers

There doesn't seem to be a solution to this, thus accepting this as an answer.

like image 154
AtliB Avatar answered Nov 09 '22 11:11

AtliB