org.hibernate.QueryException: duplicate association path: metaData

7.8k views Asked by At

I'm doing something like :

        Criteria criteria = getSession().createCriteria(Employee.class);
        Criteria metaDataCriteria = criteria.createCriteria("metaData");
        Criteria contractCriteria = metaDataCriteria.createCriteria("currentRunningContract");

        if (key.equals("directorate")) {
            contractCriteria.createCriteria(key).add(Restrictions.in("id", (Long[])parameters.get(oKey)));
        }

        if (key.equals("grade")) {
            contractCriteria.createCriteria(key).add(Restrictions.in("id", (Long[])parameters.get(oKey)));
        }

        if (key.equals("gradeLevel")) {
            contractCriteria.createCriteria(key).add(Restrictions.in("id", (Long[])parameters.get(oKey)));
        }

What I'm clearly doing here is add sub criterias to the contractCriteria depending on wheter the key if found in the associative array I pass through the function, but I get the exception : org.hibernate.QueryException: duplicate association path: on the metaData class , but I don't think I need any aliases here because I'm using the same criteria, can you help me please...?

Thanks!!!

1

There are 1 answers

0
Akyo On BEST ANSWER

I got the answer thanks Pritesh Shah, here is the solution

    Criteria criteria = getSession().createCriteria(Employee.class, "employee").createCriteria("metaData", "mData").createCriteria("currentRunningContract", "currentContract");
        if (key.equals("directorate")) {
            criteria.createCriteria("currentContract."+key).add(Restrictions.in("id", (Long[])parameters.get(oKey)));
        }Blahblah etc...

I used the aliases that I created in one shot at the firs lone :)

Cya all :)