This can be achieved with this approach.
1. List where you can store the identifier
public enum Gender{ MALE(1L), FEMALE(2L); private final Long id; Gender(Long id) { this.id= id; } public Long getId(){ return id; }
2. Related Entum Separate Entity
public class RefGenderEntity { private Long id; private String value; ...... }
3. Look at EntityManager # findById
MyObjectThatStoreIdForGender val = ...... ; RefGenderEntity gender = em.find(RefGenderEntity.class, val.getGenderId());
Of course, the RefGenderEntity table can now be pre-populated with two values, and yours will be fine with foreign keys and regular normal working connections.
source share