enum « Map « JPA Q&A





1. JPA map collection of Enums    stackoverflow.com

Is there a way in JPA to map a collection of Enums within the Entity class? Or the only solution is to wrap Enum with another domain class and use it ...

2. Using an enum as a mapkey results in a RAW in the database    stackoverflow.com

I'm trying to use an enum as a mapkey for a map in Hibernate, but Hibernate stores my enum as a RAW: I have this enum:

public enum AccountType implements Serializable {
  ...

3. Mapping enum to a table with hibernate annotation    stackoverflow.com

I have a table DEAL and a table DEAL_TYPE. I would like to map this code:

public class Deal {
   DealType type;
}

public enum DealType {
   BASE("Base"), EXTRA("Extra");
}
The problem ...

4. How to map a set of enum type in Hibernate?    stackoverflow.com

In hibernate, is it possible to define a mapping for a class to a set of enums? I've been able to find examples of how to define mappings of Sets ...

5. Hibernate 'tableless' enum mapping?    stackoverflow.com

I am dealing with the following scenario: We use table-per-subclass inheritance, meaning the concrete tables' primary keys are foreign key references on the abstract table. Superclass is Product, subclasses are ...

6. Hibernate enum mapping    stackoverflow.com

I need to map the enums which didn't implement the interface beforehand to the existing database, which stores enums in the same table as the owner class using the @Enumerated(EnumType.STRING).

class A ...

7. Hibernate - how to map an EnumSet    stackoverflow.com


I've a Color Enum

public enum color { GREEN, WHITE, RED } 
and I have MyEntity that contains it.
public class MyEntity {
   private Set<Color> colors;
   ...
I already have ...

8. Mapping enum types with Hibernate Annotations    stackoverflow.com

I have an enum type on my Java model which I'd like to map to a table on the database. I'm working with Hibernate Annotations and I don't know how to ...

9. Hibernate Enum mapping using annotaions    stackoverflow.com

I have an existing database that I am now connecting to using hibernate. I cannot change the data in it at the moment and have everything working apart from a ...





10. Hibernate Mapping: Class having more than one possible value from an enum    stackoverflow.com

I am doing a simple web page and I have a NurseForm entity. When the nurse sees a patient he/she fills this form. One of this form field is "Actions done" which ...

11. Enums in NHibernate from Existing Table    stackoverflow.com

I have many tables in my schema design (legacy, cannot be changed) with the pattern:

Widget
-----------
WIDGET_ID (int, PK)
WIDGET_TYPE_ID (int, FK)

WidgetType
-----------
WIDGET_TYPE_ID (int, PK)
WIDGET_TYPE_NAME (varchar)
example Widget records:
WIDGET_ID | WIDGET_TYPE_ID (FK)
1     ...

12. JPA: Map a Map    stackoverflow.com

i want to Map a map in JPA, but I get a Exception: My java-code looks like that: Issue.java:

@ElementCollection
@CollectionTable(
    name="ISSUE_EMPLOYEE",
    joinColumns=@JoinColumn(name="ISSUE_ID", referencedColumnName="ID")
)
@MapKeyColumn(name="EMPLOYEEPOSITION_ID")
@MapKeyConvert("myEnumConverter")
@JoinColumn(name="EMPLOYEE_ID")
private Map<EmployeePosition, Employee> namedEmployees = new ...

13. Hibernate @Enumerated mapping    stackoverflow.com

Hibernate provides @Enumerated annotation which supports two types of Enum mapping either using ORDINAL or STRING. When we map using EnumType.STRING, it takes the "name" of the Enum and not the ...

14. Mapping Collection of Enum types that implement interface    stackoverflow.com

I've got a tricky thing I'm trying to map with Enums for storing static data. It starts off with enum classes declared as such:

interface MyInterface {
    String getName();
}

public enum ...

15. Enum Mapping in hibernate    stackoverflow.com

  public enum Sources {


      SOURCE_MANUAL("manual"),

      SOURCE_RE_EDITING("re editing");


      private String source;

     ...

16. enum vs typeId in hibernate    stackoverflow.com

I'm implementing a database table like the following:

Do_Something
------------
Id
Name
Frequency
Frequency can only be 1 of 3 values at the moment; immediate, daily or weekly. So I can implement the Frequency field as ...





17. Java enum overriding toString()    stackoverflow.com

I've never really made use of Java enum classes before for constant values, I've typically used the "public final" approach in the past. I've started using an enum now and ...

18. Map Map in JPA 2    stackoverflow.com

@Entity
public class Company {

    public enum CompanyMemberLevel {
        MEMBER, GAME_ADMIN, COMPANY_ADMIN
    }

    ...

   ...

20. JPA enum mapping by explicit getId()    coderanch.com

Hi, for enum type you can choose EnumType.ORDINAL or EnumType.STRING. Going for string is definetely better because ordinal mandates that you never ever change the order of definition of the enum-types. On the other hand string also makes the DB entry bigger as necessary (taking the constant name, which can be quite long). So I want to use an explicit mapping ...

21. Mapping enum in JPA/Hibernate    coderanch.com

To map enums in Hibernate you should use UserType. Here is already made class with UserType: import org.hibernate.HibernateException; import org.hibernate.usertype.EnhancedUserType; import org.hibernate.usertype.ParameterizedType; import java.io.Serializable; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Types; import java.util.EnumSet; import java.util.Properties; /** * from http://www.hibernate.org/312.733.html */ @SuppressWarnings("unchecked") public class EnumUserType implements EnhancedUserType, ParameterizedType { private Class enumClass; public void setParameterValues(Properties parameters) { String enumClassName = parameters.getProperty("enumClassName"); ...

23. Problems mapping enum    forum.hibernate.org

@ManyToMany (targetEntity=com.somecompany.SomeEnum.class) @JoinTable( name = "entity_enum", joinColumns = { @JoinColumn(name = "entity_id")}, inverseJoinColumns = { @JoinColumn(name = "enum_id") } ) private Set enums = new HashSet();

24. Mapping a Map<@Entity, enum> with @ManyToMany    forum.hibernate.org

Hello everybody I have a question concerning a mapping of Map<@Entity, enum>. My mapping is specified as: Code: public class MyEntityClass { private Map relatedEntities = new HashMap(); ... @ManyToMany @JoinTable(name="TBL_ASSOCIATED_ENTITIES", joinColumns=@JoinColumn(name="MY_ENTITY_ID"), ...

25. @Annotation for Map<[Enum], String>    forum.hibernate.org

@Entity public class QualityIndicator implements Serializable { ... @CollectionOfElements @JoinTable(name = "qproperty_weighting") @Enumerated(value = EnumType.STRING) @MapKey(columns = @Column(name = "qproperty"), type = @Type( ...

26. Enum mapping and criteria    forum.hibernate.org

Hi, I have two entities: "Parent" & "Child" Child is mapped in Parent like this: Code: and Child has an ...

27. Error mapping collection of Enums    forum.hibernate.org

28. Mapping Collection of Enum types that implement interface    forum.hibernate.org

I've got a tricky thing I'm trying to map with Enums for storing static data. It starts off with enum classes declared as such: Code: interface MyInterface { String getName(); } public enum A implements MyInterface { FIRST_A("First A"); private final String name; private A(String name) { this.name = name; } public String getName() { return name; } public String toString() ...

29. map an enum to a lookup table    forum.hibernate.org

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 ...

30. (Another) Enum Mapping Question    forum.hibernate.org

@Entity public class Comment { @Enumerated(EnumType.STRING) private CommentSource source; public void setSource(CommentSource s){ this.source = s; } public CommentSource getSource(){ return this.source; }

31. Should I use enum to mapping the column?    forum.hibernate.org

32. Mapping Java enum to discriminator column    forum.hibernate.org

Hi, I have a table (Items) which is mapped to three different java classes using a discriminator column and subclasses in the Items.hbm.xml mappings file. Until now the discriminator has been a (hibernate type) 'string' and java class implementation has had a 'private String type' to match the discriminator. This works fine. However, I wanted to change the 'private String type' ...

33. Enum Mapping    forum.hibernate.org

Hi, I am a new user of hibernate. My problem is that I have got a POJO from some other guy and now I have to persist that so how should I do it? I tried 2-3 ways but could not succeed and the challenge is that I can't make changes in that POJO so whatever I am to do is ...

34. type safe enum mapping    forum.hibernate.org

i have just one question, my bussines objects have some atributtes that are type safe enum (i.e. Sex) , my question is what is the way to map this with hibernate (the uggly solution is to have a boolean in my dataBase and construct the type safe after the session has loaded the object). Thanks.

35. mapping a foreign-key constrained one-to-one enum    forum.hibernate.org

Hibernate version:2.1 Mapping documents:unknown Name and version of the database you are using:MySQL 4.1 I'm having trouble figuring out how to map a foreign-key one-to-one typesafe relationship. The details are as follows: table message ----------------- message_id (primary key, auto_inc) message message_type table message_types ------------------------ message_type_id (primary key, auto_inc) message_type_name where message.message is a String containing a message message.message_type is an int ...

36. Mapping Java 5 enums    forum.hibernate.org

37. Enum entity mapping    forum.hibernate.org

I'm trying to map rows in a table as instances of a Java enum. Each row will be uniquely identified by a name column (values of which will be the names of the defined enum instances). Each enum will need to load a couple of other fields (including an ID, for use in associations) from the database. I've read all the ...

38. JDK 1.5 Enum mapping    forum.hibernate.org

Hi! I'm trying to create persistence objects using the new javax.persistence API (JSR 220) and Hibernate (3.2 RC1, EntityManager 3.1 Beta8). The problem is that I'm trying to map an entity to an existing DB2 table. Unfortunately, the table has a lot of 'Y'/'N' columns that where used for booleans. Ugly. I tried to build a clean API around this and ...

39. Any built in support for java 5 enum mapping?    forum.hibernate.org

40. Mapping a set of Enums    forum.hibernate.org

41. mapping an enum    forum.hibernate.org

42. problem in mapping enum    forum.hibernate.org

Hi, I followed the wiki ( http://www.hibernate.org/265.html ) in order to use enum object in my POJO. When I'm generating POJO classes, I get the MyEnumUserType instead of MyEnum in my getters and setters I'm using hibernate 3.1.3 and Hibernate tools 3.2.0beta7 I'm using an ant script to generate POJO Here is the target I'm using : Code:

43. mapping Java 5 enum with additional fields    forum.hibernate.org

public enum Transaction { TransactionAB("A", "B"), TransactionBA("B", "A"); private String from; private String to; Transaction(String from, String to) { this.from = from; this.to = to; ...

44. How to map a set of Enum's?    forum.hibernate.org

Newbie Joined: Thu Jun 15, 2006 8:32 am Posts: 6 Hibernate version: 3.1.3 I used the Enhanced UserType described in: http://www.hibernate.org/272.html . Mapping a Enum works fine. Now I want to map a set of Enum's. But I don't know how to do it. Mapping documents: Mapping file to store a Enum property Code:

45. Whats the best way to map an enum?    forum.hibernate.org

Using hibernate 3.2.0GA, and Java1.5, what's the best way to map an enum? I've had a heck of a time trying to find it in the documentation, but, basically, this is what I have: Code: public enum YesNoType { YES { public String getLabel() ...

46. Mapping Collection Enum    forum.hibernate.org

47. Java 5.0 enum as "map-key"    forum.hibernate.org

test.mapwithusertypekey.MapKeyEnum ...

48. How to map Map<[Enum], [Entity]> using XML mapping    forum.hibernate.org

CategoryProvider 12

50. mapping Java enum whitout annotation    forum.hibernate.org

Hi, Pretty simple question here. I've read tons of posts in the forum, but I can't believe It is impossible to do the mapping I want in the following the following context : I have the simplest mapping you can imagine (public enum MyEnum { EnumA, EnumB; }) I'm using Hibernate 3.1.3. I do not, nor I can, use annotations. I ...

51. Take 2 : mapping Java enum whitout annotation    forum.hibernate.org

Hi, Pretty simple question here. I've read lots of posts in the forum, but I did not find an explicit answer to this and I'm having a hard time believing there is none. I have the simplest mapping you can imagine (public enum MyEnum { EnumA, EnumB; }) I'm using Hibernate 3.1.3. I do not use annotations (cannot). I use mapping ...

52. Enum mapping with existing table    forum.hibernate.org

Hibernate version: 3.2.6 Hi everyone, I've tried to find a solution on the forum, there are a lot of enum discussions but i didn't find what I'm looking for. We have an existing dataBase with lots of tables representing enum, (customerType, productType, ...) which we are integrating with hibernate. for example, the customer table has a Long field "customerType" which is ...

53. MySQL enum Mapping    forum.hibernate.org

Hi. Ive got a MySQL table called "Computer" with a column "BLOQUEADO" type ENUM('No','Si'). Ive made a EnumUserType and my mapping file is like this MyProject.types.NO_SI But what I need is Hibernate to give me the index value of the enum type. For example, if a computer has BLOQUEADO='Si' I want to get ...

54. JPA mapping for enums    forum.hibernate.org

55. Mapping enums    forum.hibernate.org

Yes, you're right. Using @Enumerated you don't have to use an user type for saving an enumeration. But there are some caveats: 1) @Enumerated(EnumType.STRING) Saving an enumeration as string is little waste of storage space and you tying your database to the name of the enumeration constant. Refactoring a constants name breaks existing data. 2) @Enumerated(EnumType.ORDINAL) Saves an implementation detail of ...

56. How to store a Map using String or Ordinal    forum.hibernate.org

57. Mapping enum in JPA/Hibernate    forum.hibernate.org

Hi, I have an Enum StatusType [code]# public enum StatusType # { # PENDING, APPROVED # } [/code] In my entity class i am mapping as # @Enumerated(EnumType.STRING) # @Column(name ="status", nullable = false, length = 20) # public StatusType getStatus() { # return this.status; # } # # public void setStatus(StatusType status) { # this.status = status; # } I ...

58. mapping to sql enum    forum.hibernate.org

59. why MySql Enum mapping needs it's own table?    forum.hibernate.org

Hi Froestel, I see why someone would like to put the Enum details in another table. However, wouldn't that become expensive since it'll require you to perform a join? Sure, the Enum table is small, but still.. And even if it's wrong in principle, is there a way to achieve what the original poster asked? Since I'm sure my enum is ...