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

Thanks Chris and James!

Another problem that I am facing is while configuring a many-to-many mapping between employee and project table through a relation table.

Instead of using a Many-To-Many relationship (because it assumes that field names will be the same between the source and relation table or target and relation table), I have established two One-To-Many relationships.

I then query the dynamic type corresponding to the relation table with both fields of the relation table as join attributes. The SQL query that is generated is correct, i.e., when I run it on SQL*Plus, I get the all employees with their projects. (an employee can work on multiple projects).

However the each dynamic entity in the list of d! ynamic entities returned during execution of query with eclipselink, corresponds to a unique employee, i.e., multiple projects for each employee are not reported as separate dynamic entities. I have specified both the fields of the relation table as the primary key fields in the dynamic type. Can't understand why entities corresponding to each employee-project combination is not returned even though the generated query is correct.

Thanks and Regards
Member Technical Staff
Oracle India Private Limited
91 80 41085685


----- Original Message -----
From: christopher.delahunt@xxxxxxxxxx
To: eclipselink-users@xxxxxxxxxxx
Sent: Wednesday, December 8, 2010 10:53:52 PM GMT +05:30 Chennai, Kolkata, Mumbai, New Delhi
Subject: Re: [eclipselink-users] Which dynamic type to query?

Hello Rohit,

The query.addJoinedAttribute(String) is a convenience method that turns into query.addJoinedAttribute(query.getExpressionBuilder().get(String));
Since your "id1" string represents a OneToMany, it needs to use anyOf instead of get as the exception states. 

Best Regards,
Chris




On 08/12/2010 12:15 PM, Rohit Banga wrote:
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