A few minute ago get an error "duplicate alias" and I started the think about "Can we check alias was already created? alias was already exists."
Do you know about this? Can we check this?
for example :
Criteria criteria = getSeession().createCriteria(Example.class,"example");
criteria.createAlias("example.test","test");
Now I want this, I'll check if this "test" alias is already created I won't create not I create.
Is that possible? If is that possible how? If Is not possible, Could you offer any other solution?
We have encountered a similar issue with the complex search criteries. A possible workaround is having an additional criteria building infrastructure to ignore alias duplicates. For an example, using such classes: Aliases, Alias .
Criteria criteria = getSeession().createCriteria(Example.class, "example");
Aliases aliases = Aliases.create()
.add("example.test", "test", JoinType.INNER);
criteria.add(Restrictions.eq("test", "test_value"));
aliases.addToCriteria(criteria); // add aliases to the criteria
List<Example> examples = criteria.list();
To use Aliases
class you can just download this library (it doesn't need additional jars): fluent-hibernate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With