Named Queries in HIbernate 3.0

S

shaji

Hi,

I am facing tremendous difficulties in having Named Queries in
hibernate3.0.
Please help me out.
Following is a sample xml file in which I mentioned the named query
(NamedQuery.hbm.xml). It is mapped to the class
de.gloegl.road2hibernate.NamedQuery, and loading an instance is done
successfully.


<?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>
<class name="de.gloegl.road2hibernate.NamedQuery"
table="AUDIT_DETAILS">
<id name="timestamp" column="si_timestamp" >
<generator class="increment"/>
</id>
<property name="company_id" column="company_id"/>
<property name="claim_id" column="claim_id"/>
<property name="operation" column="operation"/>
<property name="details" column="details"/>

</class>

<sql-query name="audit_display" callable="true" >
<return alias="audit" class="de.gloegl.road2hibernate.NamedQuery">
<return-discriminator column="company_id"/>
<return-property name="company_id" />
<return-property name="claim_id" />
<return-property name="timestamp" />
<return-property name="operation" />
<return-property name="details" />
</return>
SELECT audit.company_id AS company_id,
audit.claim_id AS claim_id,
audit.timestamp AS timestamp,
audit.operation AS operation,
audit.details AS details
FROM NamedQuery audit WHERE audit.details LIKE 'test%'
</sql-query>

</hibernate-mapping>

--------------------------
I am getting exceptions like this.

INFO - Mapping resource: de/gloegl/road2hibernate/NamedQuery.hbm.xml
ERROR - Error parsing XML: XML InputStream(17) Attribute "callable"
must be declared for element type "sql-query".
ERROR - Error parsing XML: XML InputStream(19) Element type
"return-discriminator" must be declared.
ERROR - Error parsing XML: XML InputStream(20) Element type
"return-property" must be declared.
ERROR - Error parsing XML: XML InputStream(21) Element type
"return-property" must be declared.
ERROR - Error parsing XML: XML InputStream(22) Element type
"return-property" must be declared.
ERROR - Error parsing XML: XML InputStream(23) Element type
"return-property" must be declared.
ERROR - Error parsing XML: XML InputStream(24) Element type
"return-property" must be declared.
ERROR - Error parsing XML: XML InputStream(25) The content of element
type "return" must match "EMPTY".

<snip>

Caused by: org.xml.sax.SAXParseException: Attribute "callable" must be
declared for element type "sql-query".
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown
Source)
at
com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.handleStartElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.dtd.XMLDTDValidator.startElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown
Source)
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown
at
com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown
Source)
at
com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown
Source)
at org.dom4j.io.SAXReader.read(SAXReader.java:334)
at
org.hibernate.cfg.Configuration.addInputStream(Configuration.java:393)
... 8 more





I am not getting any hint, what is happening here. As you see, I have
declated element types return-property. I have followed steps according
to the one example cited at hibernate.org.

Thanks,
Shaji.
 
S

shaji

One sample named query worked fine for me.
Here is the xml mapping for that.

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.n et/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="de.gloegl.road2hibernate.NamedQuery"
table="AUDIT_DETAILS">
<id name="timestamp" column="si_timestamp" >
<generator class="increment"/>
</id>
<property name="company_id" column="company_id"/>
<property name="claim_id" column="claim_id"/>
<property name="operation" column="operation"/>
<property name="details" column="details"/>

</class>
<query name="audit_display">
<![CDATA[ from AuditClaim audit where audit.details LIKE 'test%' ]]>
</query>

</hibernate-mapping>

Any clues now?
Eager to hear from you.
 
Joined
Feb 17, 2009
Messages
1
Reaction score
0
just check the hibernate mapping dtd in u r hibernate jar file ,is there any string like callable is there or not,i am sure u r using old hibernate jar file ,plase update with lattest jar ,i hope this will resolve u r problem
 
Joined
Jun 23, 2011
Messages
1
Reaction score
0
hibernate named query

I have the following existing hibernate named query.Generally we write the field names or * followed by "select". But here it is ' Ti ' , the alias of the table. Can anyone kindly explain me what is its significance. What exactly it is returning.

<![CDATA[
select Ti
from TrnTransfer Ti
where Ti.calWeek.id = :weekId
]]>

Heartiest thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,782
Latest member
ThomasGex

Latest Threads

Top