I'm a beginning hibernate user, searching around through the forum is leaving me a little confused how to map an enum in an entity class that is represented in the database as a simple lookup table. I'm looking for a solution using annotations. I'm sure somebody must have solution for this. How do I finish off writing the Address class to have hibernate directly map the addressType property to the enum when I grab a record from the database using annotations? Any pointers would be appreciated.
public enum AddressType { BILLING, SHIPPING; }
@Entity public class Address implements Serializable { @Id private Integer id; private AddressType addressType }
Database tables: Address ( id int not null, address_type_id int not null, primary key (`id`), foreign key (`address_type_id`) references address_type (`id`) )
AddressType ( id int not null, name varchar(25) not null, primary key (`id`) )
insert into AddressType values (1, 'BILLING'),(2,'SHIPPING');
|