-->
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.  [ 4 posts ] 
Author Message
 Post subject: Using a PersistentEnum in find() / a query
PostPosted: Tue Nov 18, 2003 6:54 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Hi,

I have a class (Status) which implements PersistentEnum, providing both fromInt() and toInt() methods. This 'enumerated type' is a property of a class, say Message.

I need to query the database to return all queries with a given status. i.e.

Code:
List messages = session.find(
    "FROM Message AS message WHERE " +
    "message.status = Status.UNSENT");


This generates sql:
Code:
... from Message incoming0_ where (incoming0_.status=Status.UNSENT )


and gives the exception:
Code:
Unknown table 'Status' in where clause


I have tried all sorts of combinations of the query method signature (using Hibernate.custom(clazz), Hibernate.OBJECT, etc, etc). All seem to give a different exception.

What is the correct what to use a PersistentEnum in a query?

Thanks

Justin


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 7:03 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
BTW I know it works if I do:
Code:
List messages = session.find(
    "FROM Message AS message WHERE " +
        "message.status = ?",
    new Integer(Status.UNSENT.toInt()),
    Hibernate.INTEGER
);


... but surely there is way that Mr Hibernate takes care of the conversion?

Justin


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 7:08 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Use a fully-qualified class name.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 7:44 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Great - working 100%.

I had (erroneously) assumed that because I had used Message unqualified I could used Status unqualified in the query.

Thanks Gavin !


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