-->
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.  [ 36 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject:
PostPosted: Sat Dec 17, 2005 12:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
sounds good - lets have a look and see if it works without breaking compability.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 27, 2005 1:16 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 10:20 am
Posts: 32
Location: Brazil
max wrote:
What is the difference between *true* jdk5 support and you writing:

<property name="anEnum">
<type="org.hibernate.type.EnumType">
<param name="enumclass">YourEnumClass</param>
</type>
</property>
?!

For me, the difference is that I can't use a typedef'd type as parameter to a query.
In your example, how can I find objects
Code:
where anEnum == anEnum.SOME_VALUE
? And what if "SOME_VALUE" is a query parameter, not a constant?

Thank you for your time,
Daniel Serodio


Top
 Profile  
 
 Post subject: Type Converter Lost when enum used in where clause
PostPosted: Thu Jan 26, 2006 2:34 pm 
Newbie

Joined: Thu May 26, 2005 12:21 pm
Posts: 1
DanielSerodio wrote:
For me, the difference is that I can't use a typedef'd type as parameter to a query.
In your example, how can I find objects
Code:
where anEnum == anEnum.SOME_VALUE
? And what if "SOME_VALUE" is a query parameter, not a constant?


I am running into exactly this problem. The type converter used for my enum is not found when the enum is used in a "where" clause.

Has anyone else run into this?

Scott Smith

_________________
J2EE/.NET Senior Developer/Architect


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 01, 2006 8:21 am 
Beginner
Beginner

Joined: Fri Jun 09, 2006 4:21 pm
Posts: 23
Location: Reading
Hi,

It's been more than a year since the last reply. Hibernate 3.2 is out now.
Does using Annotations remain the best way of handling java 5 enums?

Apart from Annotations people write their one smart UserTypes to be used in typedef tags. I wonder if Hibernate team would approve one of those possible implementations available (particularly in community area) or provided their own?

Cheers,


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 01, 2006 5:31 pm 
Beginner
Beginner

Joined: Mon Aug 15, 2005 10:20 am
Posts: 32
Location: Brazil
I wholeheartedly agree, it's a real shame that Java5 enums are still not supported out-of-the-box in Hibernate 3.2. It seems that XML mapping files are "out of fashion".
I've been using the typedef'ed UserTypes (from the community area), and using an enum as a parameter to a query is a royal pain:

Code:
Properties queryProperties = new Properties();
queryProperties.put("enumClassName", "org.foobar.MyEnum");
queryProperties.put("columnType", "string");

Query query = session.getNamedQuery("my.named.query");
query.setParameter("enumParameter", MyEnum.SOME_VALUE, Hibernate.custom(EnumUserType.class, queryProperties));
return query.list();


It seems that using an abstract EnumUserType (like this one) is less painful. Instead of typedef'ing UserTypes, you define separate concrete user types for each concrete type, so you can avoid the queryProperties in the code above, but not the Hibernate.custom part. I haven'd had time to try it thou.

_________________
Don't forget to rate!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 17, 2007 10:10 pm 
Newbie

Joined: Wed Jan 17, 2007 9:48 pm
Posts: 9
We've got a situation where we'd like to be able to natively persist Enum objects to the DB so I'm very interested to hear when it'll be available.

We've got about 250 tables of which about 50 are purely lookup type values. For ease of programmability we'd like those lookup tables to be managed via Enums. Most contain 3 fields (per value) but some are much more involved with nested Enums etc.

e.g.

Code:
public enum Blah {
  FOO( 1, "Foo", "This is a foo", Colour.SILVER),
  BAR( 2, "Bar", "This is a bar", Colour.GOLD);

  private Integer id;
  private String value;
  private String description;
  private Colour colour;

  Blah(Integer id, String value, String description, Colour colour) {
    this.id = id;
    this.value = value;
    this.description = description;
    this.colour = colour;
  }

  public Integer getId() { return id; }
  public String getValue() { return value; }
  public String getDescription() { return value; }
  public Colour getColour() { return colour; }
   
}



By exposing the fields with getter methods it is possible to persist like any other class however it fails on the retrieve with a "no default constructor" error. If it is possible to "plugin" a new constructor e.g. based on an approach similar to the nullSafeGet(s) on http://www.hibernate.org/272.html then please let me know.

Is there any other way to use Enums to represent DB tables and participate in all mappings (property, one-to-one, one-to-many, many-to-many, many-to-one)?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 36 posts ]  Go to page Previous  1, 2, 3

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.