zwwcn

Just another WordPress.com site

Hibernate exception: duplicate association path

Hibernate doesn’t provide function to check existing alias. If you try to add the same alias to the criteria, you will get exception: duplicate association path.

The solution is to create a set and record all exisitng alias. We only add new alias if it’s not in the set.

private List<String> aliasValues = new ArrayList<>();
if(!aliasValues.contains("invoice")){
    aliasValues.add("invoice");
    finalCriteria.createAlias("activity.invoices","invoice");
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: