-->
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: Why do you need to use strings in criterias?
PostPosted: Thu Oct 29, 2009 4:55 am 
Newbie

Joined: Wed Oct 28, 2009 5:14 am
Posts: 2
I want to sort with the Order class in a criteria, like:

criteria.addOrder(Order.asc("myColumn"));

But why do I need to enter the string name of the column in a non type-safe way? What if I change the name of that column in my database? I guess its ok to update the hibernate bean but I dont wanna keep track of all those loose strings. Is there any other way then using my own enums?

/Br joynes


Top
 Profile  
 
 Post subject: Re: Why do you need to use strings in criterias?
PostPosted: Thu Oct 29, 2009 8:57 am 
Senior
Senior

Joined: Tue Oct 28, 2008 10:39 am
Posts: 196
If you use your own enum you have to change the enum when you change fieldnames. Somewhere you have to keep the info. We use Constant-Classes for that - generated when generating the entities.


Top
 Profile  
 
 Post subject: Re: Why do you need to use strings in criterias?
PostPosted: Thu Oct 29, 2009 3:22 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
We also generate constants for our column names (and also the associations) so we don't have to hard code the names in the various queries. That way you can rename the constants if you need to and it's way easier to refactor than trying to hunt down a piece of text.

_________________
Some people are like Slinkies - not really good for anything, but you still can't help but smile when you see one tumble down the stairs.


Top
 Profile  
 
 Post subject: Re: Why do you need to use strings in criterias?
PostPosted: Fri Oct 30, 2009 3:44 am 
Newbie

Joined: Wed Oct 28, 2009 5:14 am
Posts: 2
Do you use any automic tool for generation and do you set some parameters to also add theese constants?
Im using annotated hibernate beans that I create manually for each table.

/Br joynes


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.