File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Hibernate: Executing stored procedure using hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate: Executing stored procedure using hibernate" Watch "Hibernate: Executing stored procedure using hibernate" New topic

Hibernate: Executing stored procedure using hibernate

sachin Misurkar

Joined: Jul 24, 2008
Posts: 5
I am trying to execute stored procedure using execute but it giving this Exception.

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Exception in thread "main" org.hibernate.MappingException: Error reading resource: Insurance.hbm.xml
at org.hibernate.cfg.Configuration.addResource(
at org.hibernate.cfg.Configuration.parseMappingElement(
at org.hibernate.cfg.Configuration.parseSessionFactory(
at org.hibernate.cfg.Configuration.doConfigure(
at org.hibernate.cfg.Configuration.doConfigure(
at org.hibernate.cfg.Configuration.configure(
at org.hibernate.cfg.Configuration.configure(
at com.test.SPExec.main(
Caused by: org.hibernate.MappingException: invalid mapping
at org.hibernate.cfg.Configuration.addInputStream(
at org.hibernate.cfg.Configuration.addResource(
... 7 more
Caused by: org.xml.sax.SAXParseException: Attribute "callable" must be declared for element type "sql-query".
at org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
at org.apache.xerces.util.ErrorHandlerWrapper.error(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.XMLErrorReporter.reportError(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.addDTDDefaultAttrsAndValidate(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.handleStartElement(Unknown Source)
at org.apache.xerces.impl.dtd.XMLDTDValidator.startElement(Unknown Source)
at org.apache.xerces.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl$FragmentContentDispatcher.dispatch(Unknown Source)
at org.apache.xerces.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XML11Configuration.parse(Unknown Source)
at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown Source)
at org.hibernate.cfg.Configuration.addInputStream(
... 8 more

I am using MySQL5

My hbm mapping file-

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
<!-- Generated Aug 1, 2008 12:33:30 PM by Hibernate Tools 3.2.1.GA -->
<class name="com.test.Insurance" table="insurance">
<id name="iid" type="java.lang.Integer">
<column name="iid" />
<generator class="identity" />
<property name="insuranceName" type="string">
<column name="insurance_name" length="45" not-null="true" />
<property name="investedAmount" type="int">
<column name="invested_amount" not-null="true" />
<loader query-ref="sp_select" />
<sql-query name="sp_select" callable="true">
<return alias="ins" class="com.test.Insurance">
<return-property name="iid" column="iid" />
<return-property name="insuranceName" column="insurance_name" />
<return-property name="investedAmount" column="invested_amount" />
{? =call sp_select()}


My Stored procedure-


DROP PROCEDURE IF EXISTS `demo`.`sp_select` $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_select`()
update insurance set value="xxxx" where insurance_name='sachin';
END $$


Please suggest me where i m missing...
Thanks in advance
v srinibas rao

Joined: Feb 17, 2009
Posts: 1
just check hibernate-mapping dtd file in the hibernate jar ,do the dtd file contains the string callable ,i hope it is not there in the dtd file,plese take the lattest hibernate jar file ,then try to run,i hope this will resolve your problem
I agree. Here's the link:
subject: Hibernate: Executing stored procedure using hibernate
jQuery in Action, 3rd edition