There is a way to do this, but it is not very nice ...
You can have your integer attribute, and the object attribute is displayed as follows:
@Column(ame = "GENERATED_BY", nullable = true) private Integer generatedBy; @ForeignKey(name="FK_Invoice_GeneratedBy") @JoinColumn(name = "GENERATED_BY", nullable = false, updatable = false, insertable = false) private User generatedByUser;
You cannot support external access to your generated ByUser field, it will only show sleep mode, that there is a connection. You can set the Integer field as you wish, when you load this object from the database later, you will have a link to the user.
Again, not very pretty, but can be useful sometimes.
source share