[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