• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

COLLECTION_VALUED_PATH Exception

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!
Could anyone tell me what is wrong with EJB-Ql? I am using JBoss jboss-3.2.2RC2.
I am always getting the following exception:
Depends On Me: org.jboss.deployment.DeploymentException: Error compiling EJB-QL
statement 'SELECT OBJECT(a) FROM Account a, IN (a.customer) AS c WHERE c.id = ?
1>'; - nested throwable: (org.jboss.ejb.plugins.cmp.ejbql.ParseException: Encoun
tered "a.customer" at line 1, column 40.
Was expecting:
<COLLECTION_VALUED_PATH> ...
)]
******************ejb-jar.xml*************************************
<query>
<query-method>
<method-name>findByCustomer</method-name>
<method-params>
<method-param>java.lang.String</method-param>
</method-params>
</query-method>
<ejb-ql>SELECT OBJECT(a) FROM Account a, IN (a.customer) AS c WHERE c.id = ?1></ejb-ql>
</query>
...
<ejb-relation>
<ejb-relation-name>CustomerHasAccounts</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>Customer</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<ejb-name>Customer</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>accounts</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>Account</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source>
<ejb-name>Account</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>customer</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
*******************************************************

Thank you!
 
Author
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to your mapping you have it defined where one customer as many
accounts and every account has one customer.
In your EJB-QL you are trying to traverse a many relationship for a customer: (note, I think the extra '>' at the end of your query is an error, I've removed it here)
SELECT OBJECT(a) FROM Account a, IN (a.customer) AS c WHERE c.id = ?1
IN traverses a many relationship. That's why the EJB-QL complains:

Was expecting:
<COLLECTION_VALUED_PATH> ...

a.customer doesn't refer to a memeber of a collection, but to a single entity. You can simply refer to it using something like this:

SELECT OBJECT(a) FROM Account a WHERE a.customer.id = ?1
 
Andrei Douglas
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for your help!
Will it be correct if I want:
Customer 1----------* Account
select all accounts by customer id.
SELECT OBJECT(a) FROM Customer c, IN (c.accounts) AS a WHERE c.id = ?1
 
norman richards
Author
Posts: 367
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That looks correct to me.
If you can navigate from account to customer, another possibility is:
(by object) : SELECT OBJECT (a) from Accounts a where a.customer = ?1
(by id) : SELECT OBJECT (a) from Accounts a where a.customer.id = ?1
I think those work. I didn't actually try any them though...
 
reply
    Bookmark Topic Watch Topic
  • New Topic