-->
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.  [ 3 posts ] 
Author Message
 Post subject: how to map Integer or Enum Ordinals to small int
PostPosted: Fri Feb 26, 2010 12:48 am 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
For example,

public Integer getValue() {
}

the value range is from 0 to 10.

public enum Color {
RED,
BLUE,
YELLOW
}

@Enumerated(EnumType.ORDINAL)
public Color getColor() {
}

For mysql, it is mapped to int(11).
I can use columnDefinition="smallint(2)". But it is not portable to other databases.

How to map it to a small integer type in database?

Thanks,
Dave


Top
 Profile  
 
 Post subject: Re: how to map Integer or Enum Ordinals to small int
PostPosted: Fri Feb 26, 2010 2:57 am 
Senior
Senior

Joined: Wed Sep 19, 2007 9:31 pm
Posts: 191
Location: Khuntien (Indonesia)
You should define your own type and store the value as short instead of int.
Hope this link can help you.
https://www.hibernate.org/172.html


Top
 Profile  
 
 Post subject: Re: how to map Integer or Enum Ordinals to small int
PostPosted: Fri Feb 26, 2010 3:46 am 
Senior
Senior

Joined: Tue Sep 13, 2005 2:01 am
Posts: 137
I am wondering if the annotation "length" should apply to Integer type.
@Column(length=2)

The length is currently for string.

Thanks,
Dave


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.