This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes [JPA - Hibernate] Mapping Enum to Column Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
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
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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,


GenRocket - Experts at Building Test Data
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

Joined: Jul 11, 2001
Posts: 15299
    
    6

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

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

Joined: Feb 29, 2008
Posts: 119
Yes, that's the way
 
Don't get me started about those stupid light bulbs.
 
subject: [JPA - Hibernate] Mapping Enum to Column
 
Similar Threads
JPA - Hibernate - query.getResultList() returns 3 null values.
Mapping enum in JPA/Hibernate
Can I create a drop down menu from an enum
Best practice of mapping collection of enum
Problem Persisting Entity In Hibernate