enum « Data Type « JPA Q&A

1. How to use enums with JPA    stackoverflow.com

I have an existing database of a film rental system. Each film has a has a rating attribute. In SQL they used a constraint to limit the allowed values of this ...

2. Hibernate/JPA/HSQLDB Enum issues    stackoverflow.com

I am using Hibernate annotations and entity manager (JPA) with HSQLDB. So I have an entity with an enum field:

@Column(name = "access_level")
public AccessLevel getAccessLevel() {
    return accessLevel;
Where AccessLevel ...

3. State pattern and Hibernate without Enum    stackoverflow.com

I've searched for the implementation of the State pattern in Java with Hibernate and found several references to a solution using Enums in order to provide a flexible way to add ...

4. How can I access enum atributes in HQL?    stackoverflow.com

I have an Enum like this:

TicketPriority {


private Integer index;

TicketPriority (Integer index){
    this.index = index;

public Integer getIndex(){
    return this.index;

public void setIndex(Integer index){
    this.index ...

5. How do I control column size for enums?    stackoverflow.com

This is with EclipseLink via JPA, where I let it create the tables for me. The back end data base is Derby for development mode, and I expect to use ...

6. Enum - Quantity - Hibernate    stackoverflow.com

please excuse my bad English... In my database there are stored article sets. In every article sets there are several different articles in it. Each article has a different demand with ...

7. Implementing enum based dictionary in JPA 2    stackoverflow.com

Suppose I have a dictionary (i.e. gender: MALE, FEMALE) used in my application. I'd wish to use this dictionary as a Java enum. Moreover, this dictionary values are referenced from a ...

8. Java 5, ENUM and Hibernate    coderanch.com

hi all i have some problems with the flexible enum solutiion described here: http://hibernate.org/272.html The following error occurs when calling the nullSafeGet method: java.lang.IllegalArgumentException: object is not an instance of declaring class my method looks like that: public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException { Object identifier=type.get(rs, names[0]); try { return valueOfMethod.invoke(enumClass, new Object [] {identifier}); } ...

9. Porting my enum type from Hibernate2 to Hibernate3    coderanch.com

Hi. I'm port my own enumerated type in hibernate (a type like Rating class in Hibernat In Action) from Hibernate2 to Hibernate3.2.2 Well, I got tons of errors and a bunch of unimplemented methods. I override these methods in this way : public Serializable disassemble(Object value) throws HibernateException { return (Serializable) value; } public Object assemble(Serializable cached, Object owner) throws HibernateException ...

10. Hibernate enum question    coderanch.com

Sorry but a bit new to this! I'm trying to persist an enum type to Oracle using Hibernate - I've followed the procedure as shown here http://www.hibernate.org/312.html but what I can't get my head around is how use it in my case - rather than store the ordinal position of the string I'd like to store the enum's id value ? ...

11. Hibernate - Enum    coderanch.com

I'm dealing with some model classes with some fields that have been declared as enum's. Allis well and happy in my little application world - _however_ we are not the sole users of the database and as such, other status's may appear in those enumerated fields. Using @Enumerated(EnumType.STRING) with the proper enum type causes an exception. In a number of places ...

12. Ordinal Value of ENUM and JPA    coderanch.com

13. Enum and JPA    coderanch.com

Hi I am using Enumerated.oridnal in the PK class to insert an integer field in the mysql database. Now i read somewhr that enum sholud not used to build the composite primary key.. Can any one suggest me whtr i can use enum as one of the datatype to build composite primary key...

14. [3.5.0-SNAPSHOT] Bug: Need to trim() enum names    forum.hibernate.org

Again, following the protocol to post here first: EnumType.nullSafeGet calls Enum.valueOf(enumClass,name) (line 132 of EnumType.java) That needs to be: Enum.valueOf(enumClass,name.trim()), because if the enum is stored in a CHAR() instead of a VARCHAR like the DDL generation tends to do, "USER" comes in from the database as "USER " which doesn't map.

15. Reverse engineering enum    forum.hibernate.org

My scenario is the following. We use reverse engineering to generate both mapping and POJO files. It worked flawless, but now we have to create an enum, which holds the type of the event. An event then has a foreign key for the ID of that, and an enum in the POJO object. What can I do to achieve this? I ...

16. HQL + Enum    forum.hibernate.org

It is possibile to execute an hql query to retrieve the name of "enumerated" entity column, stored in the db as "ordinal".. Example: @Entity @Table(name = "someentity", schema = "someschema") public class Someentity{ [...] @Column(name = "enumcol") @Enumerated(EnumType.ORDINAL) public enumTypeXX getEnumcol() { return this.enumcol; } public void setEnumcol(enumTypeXX enumcol) { this.enumcol = enumcol; } [...] } in the query I need ...

17. Unknown name value for enum class    forum.hibernate.org

Author Message MNHib Post subject: Unknown name value for enum class Posted: Wed Dec 08, 2010 11:22 am Newbie Joined: Tue Nov 30, 2010 8:18 am Posts: 8 I've got a class named DepenseBeneficiaire.java, which primary key is composed of attributes from the class DepenseBeneficiaireId.java. One of DepenseBeneficiaireId attributes is an enumeration, to determine which type of DepenseBeneficiaire we ...

18. many-to-many between object and enum    forum.hibernate.org

I wonder if it is possible to create a many-to-many relationship between an object type and an enum type. There seems to be a more general obstruction with retrieving the list of enum values bound to object, because we cannot have a public constructor in enum type --- My Hibernate version is 3.6.3. When I access the roles enum set in ...

20. java.lang.IllegalArgumentException: No enum const class    forum.hibernate.org

I am getting started with Hibernate, and I am getting the following error for an entity which is supposed to have an enum type. java.lang.IllegalArgumentException: No enum const class app.entity.ObjType. java.lang.Enum.valueOf(Enum.java:214) org.hibernate.type.EnumType.nullSafeGet(EnumType.java:125) org.hibernate.type.CustomType.nullSafeGet(CustomType.java:109) org.hibernate.type.AbstractType.hydrate(AbstractType.java:104) org.hibernate.persister.entity.AbstractEntityPersister.hydrate(AbstractEntityPersister.java:2283) I have the following enum type defined: @Enumerated(EnumType.STRING) private ObjType type; And the defined Enum class is as follows: package app.entity; public enum ObjType { typeA, ...

21. Type safe enum storage, base class    forum.hibernate.org

Newbie Joined: Tue Aug 24, 2004 8:41 am Posts: 15 Location: Amersfoort, the Netherlands Hibernate version: 2.1 I tried to search for storage of type-safe enums as var-chars. I found some code, but it seemed like overkill to me. So, I wrote this base class, its quite simple to extend. You can use it to easly store and load enums. Code: ...

22. Are JDK 1.5 enums supported yet?    forum.hibernate.org

23. ENUM Datatypes    forum.hibernate.org

24. findByPk with a pk enum    forum.hibernate.org

Hello folks, i am trying to do a findByPk with a pk that have one of his attributes an enum, so when hibernate do the load he throws a exception, because the field in the database is an Integer an the enum is sending a String org.hibernate.exception.SQLGrammarException: could not load an entity: [com.waybrasil.model.persistence.servicocontratado.ServicoContratado#component[codigoReceita,codigoGrupoServico,ponto,codigoServico,cidade,contrato]{contrato=367971, codigoGrupoServico=291, [size=18][b]codigoReceita=Internet[/b][/size], codigoServico=238, cidade=50, ponto=1}] see codigoReceita= Internet ...

25. Java 5 enums and typedef    forum.hibernate.org

Hi After going through the online documentation for how to map enum property of a java object to hibernate this is what I have done: in the hbm file I have Code: net.hoike.bluetropics.simulator.types.DestinationType Now, I am using MySQL... at present the datatype for the variable is varchar... ...

26. GenericEnumUserType for nested enum classes    forum.hibernate.org

27. Unknown name value for enum class ...    forum.hibernate.org

public enum CreditCardType { MASTERCARD("Mastercard"), VISA("Visa"), AMEX("American Express"); private final String cardType; private CreditCardType(String cardType) { this.cardType = cardType; } public String toString() { ...

28. newbie: enum EnumType.STRING wrong columnlength (oracle)?    forum.hibernate.org

private WebUserStatus status; @Enumerated(EnumType.STRING) public WebUserStatus getStatus() { return status; } public void setStatus(WebUserStatus status) { this.status = status; }

29. Hibernate and Enums    forum.hibernate.org

30. Enums: Back to JDK 1.4 from Java 5    forum.hibernate.org

31. JPA/Hibernate postgres enum    forum.hibernate.org

ok so I am totally stumped here, I have created some tables in postgres 8.3 (and JPA, with hibernate as the provider) and some entities, one of my entities has a column of type "game_type" which i created in postgres as follows Code: CREATE TYPE game_type AS ENUM('forward','backward'); so i created an enum and set the @Enumerated in the anotations like ...