-->
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.  [ 4 posts ] 
Author Message
 Post subject: Mapping exception thrown by sql-query
PostPosted: Tue Aug 07, 2007 1:54 pm 
Newbie

Joined: Wed Jul 18, 2007 3:09 pm
Posts: 4
When I used the column name twice in a query, the mapping file throws org.hibernate.MappingException.

Here is my mapping document:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="com.amg.brides.local.model">

<class name="VendorListingProperties" table="vendor_listing">

<cache usage="read-write" />

<id name="id" column="content_id" unsaved-value="0">
<generator class="foreign">
<param name="property">vendorListing</param>
</generator>
</id>

<one-to-one name="vendorListing" class="VendorListing" constrained="true" />

<property name="remarks" column="remarks" />
<property name="openSunday" column="is_open_sunday" />
<property name="price" column="price" />
<property name="contactName" column="contact_name" />
<property name="contactEmail" column="contact_email" />
<property name="contactPhone" column="contact_phone" />
<property name="alternatePhone" column="alternate_phone" />
<property name="contactFax" column="contact_fax" />
<property name="vendorWWW" column="vendor_www" />
<property name="linkVW" column="link_vw" />
<property name="showMap" column="show_map" />
<property name="notes" column="notes" />
<many-to-one name="localAccount" class="com.amg.brides.local.model.LocalAccount" column="user_id" />
<many-to-one name="address" class="com.amg.brides.contact.model.Address" column="address_id" cascade="all"/>
<set name="vendorPlacements" lazy="true" cascade="all">
<cache usage="read-write" />
<key column="content_id" />
<one-to-many
class="com.amg.brides.local.model.VendorPlacement" />
</set>

</class>

<query name="vendorListing.byIds">
<![CDATA[
From VendorListing where id in (:ids)
]]>
</query>

<sql-query name="vendorListing.getVendorListingsByEndDate">
<return-scalar type="long" column="id" />
select distinct(vl.content_id) as id
from vendor_placement vp, vendor_listing vl
where vl.content_id=vp.content_id
and to_char(vp.end_date, 'MM/DD/YYYY') = :aDate
</sql-query>
<sql-query name="vendorListing.getVendorListingsByEndDates">
<return-scalar type="long" column="id" />
select distinct (placement_id) as id from vendor_placement
where end_date > :aDate
and end_date < :bDate
order by id
</sql-query>

</hibernate-mapping>

The last part is what I added:
<sql-query name="vendorListing.getVendorListingsByEndDates">
<return-scalar type="long" column="id" />
select distinct (placement_id) as id from vendor_placement
where end_date > :aDate
and end_date < :bDate
order by id
</sql-query>


It seems that because I used end_date twice. It throws the following mapping error:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletC ontext resource [/WEB-INF/spring-base.xml]: Initialization of bean failed; nested exception is org.hibernate.MappingExcepti on: org.dom4j.DocumentException: Error on line 92 of document : The content of elements must consist of well-formed charac ter data or markup. Nested exception: The content of elements must consist of well-formed character data or markup.
org.hibernate.MappingException: org.dom4j.DocumentException: Error on line 92 of document : The content of elements must c onsist of well-formed character data or markup. Nested exception: The content of elements must consist of well-formed chara cter data or markup.
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:408)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:679)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireC apableBeanFactory.java:1091)


But I do need to select before and after certain dates.

Is there a solution for this?

Thanks





Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 07, 2007 4:13 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
The characters < and > are special in xml files - you have them in your query which is causing the error. Best thing is to put your named queries into CDATA sections so the xml parser just takes it as is.
Code:
<sql-query name="vendorListing.getVendorListingsByEndDates">
<return-scalar type="long" column="id" />
<![CDATA[
select distinct (placement_id) as id from vendor_placement
where end_date > :aDate
and end_date < :bDate
order by id
]]>
</sql-query>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 07, 2007 6:54 pm 
Newbie

Joined: Wed Jul 18, 2007 3:09 pm
Posts: 4
Thank you very much for your help. That was it!

Another question , what is the difference between
<query> tag and <sql-query> tag ?


I noticed that sql-query is when you need capture returns, is that it or there is anything else?

The following are two examples of <query> and <sql-query>:
<query name="vp.vendorListing.by.placement.attribute">
<![CDATA[
select vp.vendorListing From VendorPlacement vp
where vp.vendorListing.attributes.id = :attribute
and vp.placement in (:placements)
]]>
</query>


<sql-query name="vp.search.filterby.attributes">
<return-scalar type="long" column="vendor_placement_id"/>
select vendor_placement_id
from vendor_placement vp, placement_local p, content c, content_attribute ca
where p.placement_id=vp.placement_id and vp.content_id = c.content_id and c.content_id=ca.content_id
and current_date > start_date AND (end_date is null OR end_date > current_date)
and ca.attribute_id in (:attributes)
and vp.placement_id in (:placements)
having count(ca.attribute_id)=:size
group by vp.vendor_placement_id
</sql-query>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 08, 2007 8:16 am 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
<query> is for HQL queries
<sql-query> is for SQL queries


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.