Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Which dynamic type to query?

Hello All

I am currently experimenting with eclipselink dynamic persistence:

http://wiki.eclipse.org/EclipseLink/Development/JPA/Dynamic

I am creating an Employee and a Department class with a One-To-Many mapping from the department to employee tables using the following code:

        departmentTypeBuilder.addOneToManyMapping("id1", employeeTypeBuilder.getType(), "empinfo.depid");
        employeeTypeBuilder.addOneToOneMapping("id1", departmentTypeBuilder.getType(), "empinfo.depid");

This is based on the explanation at the following page:
http://wiki.eclipse.org/Introduction_to_Relational_Mappings_(ELUG)

After this I add both the types as follows:

        helper.addTypes(false, true, departmentTypeBuilder.getType(), employeeTypeBuilder.getType());
        helper.addTypes(false, true, employeeTypeBuilder.getType(), departmentTypeBuilder.getType());

 //        helper.addTypes(false, false, employeeTypeBuilder.getType());
 //        also works, but don't know why? which one is correct?

After this I create a ReadAllQuery:

        ReadAllQuery query = new DynamicHelper(session).newReadAllQuery(employeeTypeBuilder.getType().getDescriptor().getAlias());
        query.addJoinedAttribute("id1");

        query.prepareCall(session, new DatabaseRecord());

The above code works. However if I create a query using "departmentTypeBuilder.getType().getDescriptor().getAlias()", I get the following exception:

Exception Description: Invalid use of a query key [org.eclipse.persistence.mappings.OneToManyMapping[id1]] representing a "to-many" relationship in an _expression_.  Use anyOf() rather than get().
    at org.eclipse.persistence.exceptions.QueryException.invalidUseOfToManyQueryKeyInExpression(QueryException.java:735)
    at org.eclipse.persistence.internal.expressions.QueryKeyExpression.validateNode(QueryKeyExpression.java:887)
    at org.eclipse.persistence.expressions._expression_.normalize(_expression_.java:3009)
    at org.eclipse.persistence.internal.expressions.DataExpression.normalize(DataExpression.java:342)
...

Can you please tell me why this fails? Are there any rules regarding which DynamicType to query for various type of mappings possible between tables?

Thanks in Advance.

--
Thanks and Regards
Rohit Banga
Software Developer
Oracle Server Technologies

Back to the top