-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Can I map a Java enum without using a user type?
PostPosted: Wed Sep 21, 2005 12:15 pm 
Beginner
Beginner

Joined: Wed Sep 21, 2005 11:52 am
Posts: 43
I'm using HIbernate 3 running against DB2.

I wonder if there is a way to map an enum without creating a user type, for instance, could I use a component mapping?

I have a Java enum defined thus:

Code:
public class NormalizedRecord {
...
[b]public enum RecordType {BIRTH_INDEX_RECORD, BIRTH_MASTER_RECORD, DEATH_INDEX_RECORD, DEATH_MASTER_RECORD, FAMILY_RECORD, MARRIAGE_RECORD;[/b]
...
}

I tried the following mapping:

Code:
<class name="org.egcrc.cfr.normalized.NormalizedRecord"
      table="NORM_REC"
      lazy="true">
...
[b]  <component name="myRecordType" class="org.egcrc.cfr.normalized.NormalizedRecord.RecordType">
    <property name="value" type="string"/>
  </component>[/b]
...
</class>


This compiled correctly and generated the following table definition:

create table PSD.NORM_REC (
NORM_REC_ID bigint generated by default as identity,
myCreateDate timestamp,
EVENT_DATE_IS_APPROX smallint,
EVENT_MAX_DATE timestamp,
EVENT_MIN_DATE timestamp,
EVENT_DATE timestamp,
myId integer,
value varchar(255),
mySourceId varchar(255),
primary key (NORM_REC_ID)
);

I'm just not sure if this will correctly store and retrieve the enum value.

TIA.

Larry


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2005 12:36 pm 
Beginner
Beginner

Joined: Thu Sep 15, 2005 4:16 pm
Posts: 29
I don't know if this will help, but I took a different approach. I mapped the enumerated value to an int, and then created an accessor to make the enum available (I'm obviously using annotations, but it would work with mappings the same way):

Code:
   /**
    * The aa type
    */
   @Basic
   @Column(name = "AATYPE")
   private int aaType;


Now the accessor translates:

Code:
   public AAType getActiveAssemblyType()
   {
      return AAType.valueOf(aaType);
   }


IMO it may be awhile before frameworks start fully integrating Java 5 concepts and types. As another example, I needed to work around the enumerations in betwixt as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.