Thank you for your very quick reply. I had hoped to avoid all of the ugly
details, but here goes.
I simplified some things. In particular the package with the BaseObject
class is net.morphbank.object, not "a". Also, I'd like to tell you the exact
version of toplink that I'm using, but I'm not sure how to tell.
The stack trace does not change when I remove the property from
persistence.xml. Is the use of DirectQueryKey correct in the
DescriptorCustomizer or should it be some other subclass of QueryKey?
Exception stack trace (partial)
Exception in thread "main" java.lang.IllegalArgumentException: An exception
occured while creating a query in EntityManager
at
oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImpl.createQuery(EntityManagerImpl.java:209)
at net.morphbank.search.ChangeSearch.getNumChanges(ChangeSearch.java:114)
at net.morphbank.search.ChangeSearch.getNumChanges(ChangeSearch.java:104)
at
net.morphbank.webtest.TestSearchChanges.doChangeSearch(TestSearchChanges.java:45)
at net.morphbank.webtest.TestSearchChanges.run(TestSearchChanges.java:37)
at net.morphbank.webtest.TestSearchChanges.main(TestSearchChanges.java:31)
Caused by: Exception [TOPLINK-8030] (Oracle TopLink Essentials - 2.0 (Build
b58g-fcs (09/07/2007))): oracle.toplink.essentials.exceptions.EJBQLException
Exception Description: Error compiling the query [select count(b.id) from
BaseObject b where b.dateLastModified > :date and (b.objectTypeId='Image'
or b.objectTypeId='Specimen') ], line 1, column 81: unknown state or
association field [objectTypeId] of class [net.morphbank.object.BaseObject].
at
oracle.toplink.essentials.exceptions.EJBQLException.unknownAttribute(EJBQLException.java:474)
at
oracle.toplink.essentials.internal.parsing.DotNode.validate(DotNode.java:101)
at oracle.toplink.essentials.internal.parsing.Node.validate(Node.java:115)
at
oracle.toplink.essentials.internal.parsing.BinaryOperatorNode.validate(BinaryOperatorNode.java:58)
at
oracle.toplink.essentials.internal.parsing.EqualsNode.validate(EqualsNode.java:65)
at
oracle.toplink.essentials.internal.parsing.OrNode.validate(OrNode.java:72)
at oracle.toplink.essentials.internal.parsing.Node.validate(Node.java:118)
at
oracle.toplink.essentials.internal.parsing.LogicalOperatorNode.validate(LogicalOperatorNode.java:63)
at
oracle.toplink.essentials.internal.parsing.WhereNode.validate(WhereNode.java:58)
at
oracle.toplink.essentials.internal.parsing.ParseTree.validate(ParseTree.java:235)
...
Christopher Delahunt wrote:
>
> Hello,
>
> Can you post the full exception stack trace, and the query that you are
> using the "type" query key in? The exception is complaining about the
> query key, so the property tag must be working or the customize method
> would not
> be adding it.
>
> Best Regards,
> Chris
>
> griccardi wrote:
>> I am trying unsuccessfully to use the quoted example from Mr. Sutherland.
>> I
>> am otherwise using with toplink essentials with great success.
>> Unfortunately, the full class names are missing, the method
>> addQueryKey(String, String) is not part of toplink essentials, and the
>> details of the representation in persistence.xml is unclear to me.
>>
>> What I found on the Web about toplink essentials allowed me to create the
>> following class and persistence.xml property. My inheritance base class
>> is
>> "a.BaseObject" and the discriminator field is "objectTypeId". I found no
>> information on how to create a QueryKey and so made up something.
>>
>> package a;
>> import oracle.toplink.essentials.descriptors.ClassDescriptor;
>> import
>> oracle.toplink.essentials.tools.sessionconfiguration.DescriptorCustomizer;
>> import oracle.toplink.essentials.querykeys.*;
>>
>> public class MDescriptorCustomizer implements DescriptorCustomizer {
>> public void customize(ClassDescriptor descriptor) throws Exception {
>> DirectQueryKey queryKey = new DirectQueryKey(); // error very likely
>> here!
>> queryKey.setName("type");
>> queryKey.setFieldName("a.BaseObject.objectTypeId");
>> descriptor.addQueryKey(queryKey);
>> }
>> }
>>
>> to my persistence.xml file I add:
>>
>> <property name="toplink.descriptor.customizer.BaseObject"
>> value="a.MyDescriptorCustomizer"/>
>>
>> The error I see on my query is " unknown state or association field
>> [objectTypeId] of class [a.BaseObject]."
>>
>> I suspect the <property ... /> is incorrect, although a change in the
>> value
>> to make it an invalid class name does cause an error.
>>
>> Please steer me onto the correct path,
>>
>> Greg Riccardi
>>
>>
>> James Sutherland wrote:
>>
>>> I do not think there is support for this in the JPA/JPQL spec, however
>>> in
>>> TopLink Essentials you can use a DescriptorCustomizer to add a QueryKey
>>> to
>>> your TopLink descriptor for the type field. You will then be able to
>>> query on this query key in JPQL.
>>>
>>> i.e.
>>> public class MyDescriptorCustomizer implements DescriptorCustomizer {
>>> public void customize(ClassDescriptor descriptor) {
>>> descriptor.addQueryKey("type",
>>> "ABSTRACT_ENTITY.ABSTRACT_ENTITY_TYPE");
>>> }
>>> }
>>>
>>> You can add the customizer in your persistence.xml.
>>>
>>>
>>> Shelley wrote:
>>>
>>>> I have an abstract entity class which defines a joined inheritance
>>>> type,
>>>> using a discriminator column. I would like to create a JPQL query
>>>> which
>>>> allows for dynamic inclusion/exclusion of specific entity subtypes.
>>>>
>>>>
>>>>
>>>>
>>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/JPQL-and-Inheritance-tp13304803p18388329.html
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.