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

OK
I will try that once I am back on my development machine. Could you please explain the rationale behind this?

Thanks

Member Technical Staff 
Oracle India Private Limited 
91 80 41085685 

----- Original Message -----
From: jamesssss@xxxxxxxxx
To: eclipselink-users@xxxxxxxxxxx
Sent: Wednesday, December 8, 2010 9:59:25 PM GMT +05:30 Chennai, Kolkata, Mumbai, New Delhi
Subject: Re: [eclipselink-users] Which dynamic type to query?


Use,
query.addJoinedAttribute(query.getExpressionBuilder().anyOf("id1"));


Rohit Banga-2 wrote:
> 
>   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
> 
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> 
> 


-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
Blog:  http://java-persistence-performance.blogspot.com/ Java Persistence
Performance 
-- 
View this message in context: http://old.nabble.com/Which-dynamic-type-to-query--tp30403159p30407038.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.

_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users