aspose file tools
The moose likes Object Relational Mapping and the fly likes [JPA - Hibernate] Mapping Enum to Column Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Databases » Object Relational Mapping
Reply Bookmark "[JPA - Hibernate] Mapping Enum to Column" Watch "[JPA - Hibernate] Mapping Enum to Column" New topic
Author

[JPA - Hibernate] Mapping Enum to Column

Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

I have an Enum:



And then I have the following Entity class:



In order for the productAttributeFormType to just have its value in a column is it as simple as:

@Column(name="FormType")
private ProductAttributeFormType productAttributeFormType;

Or is there more to it?

Thanks,
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

Ran across this. A bit more to it than I though but makes sense.
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

On further inspection, I'm not sure that will work for my use case. So still looking for answers.
Gregg Bolinger
Ranch Hand

Joined: Jul 11, 2001
Posts: 15230

Ok, after some testing, this appears to work...

@Enumerated(value = EnumType.STRING)
private ProductAttributeType productAttributeType;
Rodrigo Lopes
Ranch Hand

Joined: Feb 29, 2008
Posts: 118
Yes, that's the way
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: [JPA - Hibernate] Mapping Enum to Column
 
Similar Threads
Best practice of mapping collection of enum
Can I create a drop down menu from an enum
JPA - Hibernate - query.getResultList() returns 3 null values.
Problem Persisting Entity In Hibernate
Mapping enum in JPA/Hibernate