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