xwhyz
xwhyz

Reputation: 1514

Hibernate entity with enum foreign key

I'm not sure if the topic name makes sense. Anyway, the problem is that in my table I have column which stores fk to dictionary table and I want to map it in hibernate in a way that getType will return a value from this dictionary. As an example I have row with type id = 1 which in dictionary corresponds to HIGH, and I have such enum declared in java as ProductType, I want to have method ProductType getType() which will automatically map values from column type to my enum.

If something's not clear, please let me know. Thanks in advance!

Upvotes: 2

Views: 1306

Answers (1)

xwhyz
xwhyz

Reputation: 1514

This is the answer to my question

@Column(name="TYPE_ID") 
@Enumerated(EnumType.ORDINAL) 
private MyType myType;

Of course my enum looks as follows:

public enum MyType {

HIGH(1),
LOW(2); 

Upvotes: 1

Related Questions