-->
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: Avoiding duplicate aliases
PostPosted: Fri Dec 17, 2010 7:24 am 
Newbie

Joined: Fri Dec 17, 2010 7:05 am
Posts: 5
Hi,

I'm using Hibernate 3.2.6. I have a search form in a web app which has lots of fields, they're all optional so you can search for something in many ways. Behind this, I have a method with lots of if statements that say things like "if this field isn't empty then add this criterion". I sometimes need to use Criteria Aliases for joins but someone might fill in two fields that both need the same alias to be created. In this case I would get a duplicate Alias exception. The best I have come up with so far was from someone somewhere on the internet suggesting you create a list and keep track of the Aliases in there. So I have created the following method to help with this:

Code:
private void createAlias(ArrayList list, Criteria criteria, String propertyName, String aliasName) {
   if (!list.contains(propertyName)) {
      criteria.createAlias(propertyName, aliasName);
      list.add(propertyName);
   }
}


This isn't great though, you have to keep track of the List and which Criteria it is associated with. Surely there must be a much better way of doing this. Is there no way I can check the criteria to see if the alias has been created instead of using my own list or, even better, is there something built into Hibernate that creates an alias if it doesn't exist?


Top
 Profile  
 
 Post subject: Re: Avoiding duplicate aliases
PostPosted: Mon Feb 23, 2015 8:09 pm 
Newbie

Joined: Mon Feb 23, 2015 8:08 pm
Posts: 1
bump, I have same exact question. Of course one should use hashset or map instead of list to keep track, but the question remains, why should we need to keep track? we should be able to call hibernate criteri.doesAliasExist("alias")


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.