-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: Problem with named query
PostPosted: Thu Mar 09, 2006 10:26 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
I have this simple named query:

Code:
<query name="Fairs.GetOngoing">from Fair where starting_date <= ? and end_date >= ?</query>


And i get this error

Quote:
Exception Details: System.Xml.XmlException: This is an unexpected token. The expected token is 'NAME'. Line 31, position 64.


I cant see where the problem is, what am i missing?


Top
 Profile  
 
 Post subject: Re: Problem with named query
PostPosted: Thu Mar 09, 2006 10:42 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
bosh wrote:
I have this simple named query:

Code:
<query name="Fairs.GetOngoing">from Fair where starting_date <= ? and end_date >= ?</query>


And i get this error

Quote:
Exception Details: System.Xml.XmlException: This is an unexpected token. The expected token is 'NAME'. Line 31, position 64.


I cant see where the problem is, what am i missing?


XML is case sensitive - so maybe the case of "NAME"


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 10:46 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
Hi gert

NAME doesnt feature anywhere in the mapping (apart from the xml attiributes)

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
   <class name="vcf.code.entites.Fair,vcf" table="vcfFairs">

      <id name="Code" column="code" type="Int32" unsaved-value="0">
         <generator class="native"/>
      </id>
      <bag name="Stands" inverse="true" lazy="false" >
         <key column="fair_code" />
         <one-to-many class="vcf.code.entites.Stand,vcf" />
      </bag>
      <property column="starting_date" type="DateTime" name="StartingDate" not-null="true" />
      <property column="end_date" type="DateTime" name="EndDate" not-null="true" />
      <property column="title" type="String" name="Title" not-null="true" length="50" />
      <property column="description" type="String" name="Description" not-null="true" length="1500" />
      <property column="sponsor_code" type="Int32" name="SponsorCode" />   
   </class>
   
   <query name="Fair.GetAll">from Fair order by starting_date</query>
   
   <query name="Fair.GetAttending">select fair from Fair fair inner join fair.Stands stands where stands.Exhibitor.VcfUser.Id = ?</query>
   
   <query name="Fair.GetNotAttending">
   from Fair fair
   where not exists( select stand from Stand stand where stand.Fair.Code = fair.id and
   stand.Exhibitor.VcfUser.id = ?)
   </query>
   
   <query name="Fairs.GetOngoing">from Fair where starting_date <= ? and end_date >= ?</query>
   <query name="Fairs.GetFuture">from Fair where starting_date > ? and end_date > ?</query>
   <query name="Fairs.GetPast">from Fair where starting_date < ? and end_date < ?</query>
   
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 10:52 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
bosh wrote:
NAME doesnt feature anywhere in the mapping (apart from the xml attiributes)

UPS

The problem is probably the usage of XML reserved characters inside SQL text ("<" at least). So, either quote text for XML or use <![CDATA[]]> for text.

Gert


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 11:18 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
But < and > are valid in named queries i have used them before!?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 11:25 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
bosh wrote:
But < and > are valid in named queries i have used them before!?

Maybe, but "<" is not valid inside xml document AFAIK. Try using &lt; and &gt; instead of them for example.

Gert


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 11:31 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
i agree but...if you look at the Hibernate 2.1 docs:

http://www.hibernate.org/hib_docs/refer ... ryhql.html

Section 11.8 says both < and > are valid


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 11:34 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
bosh wrote:
i agree but...if you look at the Hibernate 2.1 docs:

http://www.hibernate.org/hib_docs/refer ... ryhql.html

Section 11.8 says both < and > are valid


Yes, but it talks about HQL. I am talking about XML. If XML contains literal "<", it will most likely result in invalid XML and hence not loadable. (If it is valid XML, it has altered the meaning of xml)

Try renaming Your mapping file to .xml and open it with Interent Explorer. It will complain something like "A name was started with an invalid character. Error processing resource 'file:///C:/"

Gert


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 09, 2006 12:47 pm 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
your right get ecaping wiht &lt; and &gt; seems to have done the trick


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.