[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,

On 08/12/2010 12:15 PM, Rohit Banga wrote:
I will try that once I am back on my development machine. Could you please explain the rationale behind this?


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?


Rohit Banga-2 wrote:
  Hello All

I am currently experimenting with eclipselink dynamic persistence:


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:

employeeTypeBuilder.getType(), "empinfo.depid");
departmentTypeBuilder.getType(), "empinfo.depid");

This is based on the explanation at the following page:

After this I add both the types as follows:

         helper.addTypes(false, true, departmentTypeBuilder.getType(), 
         helper.addTypes(false, true, employeeTypeBuilder.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 

         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().

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

Thanks in Advance.

Thanks and Regards
Rohit Banga
Software Developer
Oracle Server Technologies

eclipselink-users mailing list

http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
 EclipseLink ,  http://www.oracle.com/technology/products/ias/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