persistence@glassfish.java.net

RE: Re: Named Queries

From: Trimble Daniel - dtrimb <Daniel.Trimble_at_acxiom.com>
Date: Fri, 25 Aug 2006 08:02:15 -0500

Thanks for the help.

I chaned orm.xml to look like the following and it fixed the errors.

<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
orm_1_0.xsd"
               version="1.0">
   <named-query
name="GetContactsForTeamLastNameDesc"><query>...</query></named-query>
   <named-query
name="GetContactsForTeamLastNameAsc"><query>...</query></named-query>
   <named-query
name="GetContactsForTeamFirstNameDesc"><query>...</query></named-query>
   <named-query
name="GetContactsForTeamFirstNameAsc"><query>...</query></named-query>
   <named-query
name="GetContactsForTeamUserIDDesc"><query>...</query></named-query>
   <named-query
name="GetContactsForTeamUserIDAsc"><query>...</query></named-query>
   <named-query
name="GetContactsForTeamCompanyNameDesc"><query>...</query></named-query
>
   <named-query
name="GetContactsForTeamCompanyNameAsc"><query>...</query></named-query>

</entity-mappings>

-----Original Message-----
From: Sanjeeb.Sahoo_at_Sun.COM [mailto:Sanjeeb.Sahoo_at_Sun.COM]
Sent: Thursday, August 24, 2006 9:28 PM
To: persistence_at_glassfish.dev.java.net
Subject: Re: Named Queries

1. The XML is incorrect. You should have got the following error message

provided you are using the default XML parser that JRE comes with:

(1. cvc-complex-type.2.3: Element 'named-query' cannot have character
[children], because the type's content type is element-only.)
(2. cvc-complex-type.2.4.b: The content of element 'named-query' is not
complete. One of '{"http://java.sun.com/xml/ns/persistence/orm":query}'
is expected.)

To fix it, put the query string in <query> element in the XML like this:
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
version="1.0">
<named-query name="GetContactsForTeamLastNameDesc">
<query>Select ...</query>
</named-query>
<named-query name="...">
<query>...</query>
</named-query>
...
</entity-mappings>

2. The error message /"Cannot find the declaration of element
'entity-mappings'/" that you are getting is not in reflecting the above
mistake, which means something more going wrong. Which XML file have you

used? I hope it is *META-INF/orm.xml* and not persistence.xml. Are you
running inside the container or outside the container?

Thanks,
Sahoo

Trimble Daniel - dtrimb wrote:
> Error: Cannot find the declaration of element 'entity-mappings'.
>
> What's going wrong?
>
> File:
> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
> version="1.0">
> <named-query
> name="GetContactsForTeamLastNameDesc">Select...</named-query>
> <named-query
> name="GetContactsForTeamLastNameAsc">Select...</named-query>
> <named-query
> name="GetContactsForTeamFirstNameDesc">Select...</named-query>
> <named-query
> name="GetContactsForTeamFirstNameAsc">Select...</named-query>
> <named-query
> name="GetContactsForTeamUserIDDesc">Select...</named-query>
> <named-query
> name="GetContactsForTeamUserIDAsc">Select...</named-query>
> <named-query
> name="GetContactsForTeamCompanyNameDesc">Select...</named-query>
> <named-query
> name="GetContactsForTeamCompanyNameAsc">Select...</named-query>
> </entity-mappings>
>
> -----Original Message-----
> From: Sanjeeb.Sahoo_at_Sun.COM [mailto:Sanjeeb.Sahoo_at_Sun.COM]
> Sent: Thursday, August 24, 2006 2:06 PM
> To: persistence_at_glassfish.dev.java.net
> Subject: Re: Named Queries
>
> Use META-INF/orm.xml.
> e.g.
> <entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
> version="1.0">
> <named-query name="query1">...</named-query>
> <named-query name="query2">...</named-query>
> </entity-mappings>
>
> Thanks,
> Sahoo
>
> Trimble Daniel - dtrimb wrote:
>
>> I am looking for a better way to organized Named Queries. I think
that
>>
>
>
>> putting them into a list at the top of a class is messy and makes the

>> code hard to read. Any suggestions would help.
>>
>>
>>
>> Daniel Trimble
>>
>>
>>
>
************************************************************************
> ***
>
>> The information contained in this communication is confidential, is
>> intended only for the use of the recipient named above, and may be
>>
> legally
>
>> privileged.
>>
>> If the reader of this message is not the intended recipient, you are
>> hereby notified that any dissemination, distribution or copying of
>>
> this
>
>> communication is strictly prohibited.
>>
>> If you have received this communication in error, please resend this
>> communication to the sender and delete the original message or any
>>
> copy
>
>> of it from your computer system.
>>
>> Thank You.
>>
>>
>
************************************************************************
> ****
>
>>
>>