-->
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: Hibernate 3.0.5 and JDK 1.5 enum -> map to int/string in
PostPosted: Mon Jul 11, 2005 7:46 am 
Beginner
Beginner

Joined: Fri Jul 08, 2005 8:55 pm
Posts: 37
Hello

I've looked at the reference manual for "enum" and the forums and it seems that the persistence of JDK5.0 enums is still not answered to a level I can understand...

Hibernate seems to map basic enums to a tinyblob... which is not great if one has some need to access the values via SQL outside hibernate...

Is there an easy way to map an enum to say a string, int or sql-enum in the database?

Code:
public enum ContractType {
    BORROW,
    LEND
}


and the Contract:
Code:
public class Contract {
...
    private ContractType type;
    public void setType(ContractType type) {
        this.type = type;
    }
    public ContractType getType() {
        return type;
    }
}


Mapping documents:
and Contract.hbm.xml
Code:
<class name="Contract" lazy="true">
<id name="id">
  <generator class="native"/>
</id>
<property name="type"/>
....


and the table created:
Code:
create table Contract (
    id integer not null auto_increment,
    type tinyblob
    primary key (id)
)


How could I simply change the tinyblob to a string/int something non-java in the database? I can change the enum code if required...

May be could it be mapped to an sql-enum type?

Any pointer or examples would be most welcomed!
Many thanks in advance!

Benoit.

Hibernate version: 3.0.5

Name and version of the database you are using: MySQL4.1


Top
 Profile  
 
 Post subject: OK found one and contributed one...
PostPosted: Sat Jul 16, 2005 5:50 am 
Beginner
Beginner

Joined: Fri Jul 08, 2005 8:55 pm
Posts: 37
http://www.hibernate.org/265.html for mapping an enum to VARCHAR

But we have contributed a template for mapping an jdk 1.5 enum to an SMALLINT (it may sometimes be useful for say, legacy DB or critical space optimization...)

see:
http://www.hibernate.org/312.html

Regards

Benoit


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.