Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML

Tutorial Categories: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML


Java Tutorials



Struts Tutorials

Struts Resources

Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Hibernate Hibernate How To Index

User Comments
Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl
  Blink   Furl   Simpy   Y! MyWeb 

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

23 comments so far (post your own) View All Comments Latest 10 Comments:

i want store procedure example

Posted by vijay on Thursday, 11.5.09 @ 09:45am | #92342

from User as u where ((u.firstName like '%" + firstName +
"%') " + logicalOperator + " (u.lastName like '%" + lastName +
"%') " + logicalOperator + " (u.nickname like '%" + nickname +
"%')) AND (u.role.role like '%" + role + "%')";

Posted by Anrew on Tuesday, 04.7.09 @ 18:37pm | #86610


I wanna call an sql function that does some formatting in a column which has xml data. The column is to be set from java inside a pojo, but my hbm has to call the sql function, which will format the xml.

What I set in java in inputXml colums: <name>Some string</name>

And what is stored in inputXml column:
Some string

This formatting is to be done automatically, with the hbm calling the function itself.
Is it doable?

Posted by Varun Pant on Sunday, 03.8.09 @ 09:35am | #85606


I am new to Hibernate, Can you please provide any example to store the DB values getting from the Stored procedure using Hibernate. It would be great if you provide the complete sample code like mapping file, Stored procedure and java class(Client class).

Please help on this


Posted by Gajendra on Wednesday, 02.18.09 @ 00:14am | #84952

this is my mapping file & I got error

org.hibernate.MappingException: Error reading resource: org/base/application/common/business/userMapping.hbm.xml
Caused by: org.hibernate.MappingException: invalid mapping
Caused by: org.xml.sax.SAXParseException: Attribute "callable" must be declared for element type "sql-query".

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

<class name="org.base.application.common.business.MasterTableUserEntity" table="master_table_user" >

<id name="susercode" type="java.lang.String">
<column name="SUSERCODE"/>
<generator class="assigned"/>

<many-to-one name="address" class="org.base.application.common.business.MasterTableAddressEntity" column="iaddressseq" cascade="all" />

<property name="sorgcode" type="java.lang.String">
<column name="SORGCODE" length="25" not-null="true"/>

<property name="sbranchcode" type="java.lang.String">
<column name="SBRANCHCODE" length="25" not-null="false"/>

<property name="sgroupcode" type="java.lang.String">
<column name="SGROUPCODE" length="25" not-null="false"/>

<property name="susername" type="java.lang.String">
<column name="SUSERNAME" length="25" not-null="false"/>

<property name="spassword" type="java.lang.String">
<column name="SPASSWORD" length="25" not-null="false"/>

<property name="iaddressseq" type="java.lang.Long">
<column name="IADDRESSSEQ" length="10" not-null="false"/>

<property name="inooflasttrials" type="java.lang.Long">
<column name="INOOFLASTTRIALS" length="10" not-null="false"/>

<property name="caccountlockedyn" type="java.lang.String">
<column name="CACCOUNTLOCKEDYN" length="1" not-null="false"/>

<property name="cloggedyn" type="java.lang.String">
<column name="CLOGGEDYN" length="1" not-null="false"/>

<property name="dtlastlogin" type="java.sql.Date">
<column name="DTLASTLOGIN" length="10" not-null="false"/>

<property name="dtlastlogout" type="java.sql.Date">
<column name="DTLASTLOGOUT" length="10" not-null="false"/>

<property name="dtpwdexpiry" type="java.sql.Date">
<column name="DTPWDEXPIRY" length="10" not-null="false"/>

<property name="slangpreference" type="java.lang.String">
<column name="SLANGPREFERENCE" length="3" not-null="false"/>

<property name="scssname" type="java.lang.String">
<column name="SCSSNAME" length="10" not-null="false"/>

<property name="slayout" type="java.lang.String">
<column name="SLAYOUT" length="5" not-null="false"/>

<property name="caccountactivatedyn" type="java.lang.String">
<column name="CACCOUNTACTIVATEDYN" length="1" not-null="false"/>

<property name="susercreatedby" type="java.lang.String">
<column name="SUSERCREATEDBY" length="15" not-null="false"/>

<property name="dtusercreated" type="java.sql.Date">
<column name="DTUSERCREATED" length="10" not-null="false"/>

<property name="saccesscode" type="java.lang.String">
<column name="SACCESSCODE" length="20" not-null="false"/>

<property name="iinvpwdchgtrials" type="java.lang.Long">
<column name="IINVPWDCHGTRIALS" length="10" not-null="false"/>

<property name="dtupdtimestamp" type="java.sql.Date">
<column name="DTUPDTIMESTAMP" length="10" not-null="false"/>

<property name="cisdeletedyn" type="java.lang.String">
<column name="CISDELETEDYN" length="1" not-null="false"/>

<property name="cuserlevel" type="java.lang.String">
<column name="CUSERLEVEL" length="1" not-null="false"/>
<loader query-ref="getUserDetails" />


<class name="org.base.application.common.business.MasterTableAddressEntity" table="master_table_address" >
<id name="iaddressseq">
<column name="IADDRESSSEQ" sql-type="mediumint" length="9" precision="0" not-null="true"/>
<list name="users" cascade="all">
<key column="iaddressseq"/>
<index column="susercode"/>
<one-to-many class="org.base.application.common.business.MasterTableUserEntity"/>
<property name="saddresstype">
<column name="SADDRESSTYPE" sql-type="varchar" length="2" precision="0" not-null="true"/>
<property name="saddress1">
<column name="SADDRESS1" sql-type="varchar" length="50" precision="0" not-null="false"/>
<property name="saddress2">
<column name="SADDRESS2" sql-type="varchar" length="50" precision="0" not-null="false"/>
<property name="saddress3">
<column name="SADDRESS3" sql-type="varchar" length="50" precision="0" not-null="false"/>
<property name="scity">
<column name="SCITY" sql-type="varchar" length="30" precision="0" not-null="false"/>
<property name="sstate">
<column name="SSTATE" sql-type="varchar" length="30" precision="0" not-null="false"/>
<property name="scountry">
<column name="SCOUNTRY" sql-type="varchar" length="30" precision="0" not-null="false"/>
<property name="szip">
<column name="SZIP" sql-type="varchar" length="15" precision="0" not-null="false"/>
<property name="sphone1">
<column name="SPHONE1" sql-type="varchar" length="30" precision="0" not-null="false"/>
<property name="sphone2">
<column name="SPHONE2" sql-type="varchar" length="30" precision="0" not-null="false"/>
<property name="sphone3">
<column name="SPHONE3" sql-type="varchar" length="30" precision="0" not-null="false"/>
<property name="sfax">
<column name="SFAX" sql-type="varchar" length="20" precision="0" not-null="false"/>
<property name="scontactperson">
<column name="SCONTACTPERSON" sql-type="varchar" length="50" precision="0" not-null="false"/>
<property name="smailid">
<column name="SMAILID" sql-type="varchar" length="50" precision="0" not-null="false"/>
<property name="smobileno">
<column name="SMOBILENO" sql-type="varchar" length="30" precision="0" not-null="false"/>
<property name="suserid">
<column name="SUSERID" sql-type="varchar" length="15" precision="0" not-null="false"/>
<property name="dtupdtimestamp">
<column name="DTUPDTIMESTAMP" sql-type="date" length="10" precision="0" not-null="false"/>
<property name="weburi">
<column name="WEBURI" sql-type="varchar" length="50" precision="0" not-null="false"/>

<sql-query name="getUserDetails" callable="true">
<return alias="MasterTableUserEntity" class="org.base.application.common.business.MasterTableUserEntity" entity-name="MasterTableUserEntity">
<return-property name="susername">
<return-column name="susername"/>

{call getUserDetails()}


Posted by Sandeep on Monday, 11.3.08 @ 18:37pm | #81494

Dear Sir
We are using NHibernate with Asp.net.
I have written this code in HBM file

<sql-query name="OtherProfileAreas">
<return class="OtherProfileArea">
<return-property name="OtherDomain" column="OtherDomain"/>
<return-property name="Total" column="Total"/>
exec [dbo].[OtherProfileArea]

Also Created DAO for the same
now while executing the same

NHibernate.ISession iSession = NHibernateSessionManager.Instance.GetSessionFrom(SessionFactoryConfigPath);

NHibernate.IQuery query = iSession.GetNamedQuery("OtherProfileArea");

It gives run time error of

The given key was not present in the dictionary.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Exception: The given key was not present in the dictionary.

Posted by Chirag on Wednesday, 10.15.08 @ 12:20pm | #81092

I want to learn Spring frame work, How far it easy to learn.

Posted by vas on Monday, 09.22.08 @ 12:56pm | #80591

Please any one help me,
How to invoking sp in hibernate?
what i have to do in mapping.xml and client side.

Posted by how to execute store procedeure in hibernate on Tuesday, 04.8.08 @ 11:34am | #55620

First of all, congratulations to keep a lot of documentation about hibernate in one place: it's help a lot !
I need to call an stored procedure in oracle from Hibernate (see bellow) that has 1 input parameter and 2 return values. I'm receiving and error from Oracle (invalid column index). Any help is appreciated.
Thanks in advance !!!

HBM file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

<class name="br.com.gppg.dto.csep_Busca_Vinc_Matr">
<cache usage="read-only"/>
<id name="usuario" column="P_USERID"/>
<property name="vinculo" column="P_VINCULO"/>
<property name="matricula" column="P_MATRICULA"/>
<sql-query name="CSEP_BUSCA_VINC_MATR" callable="true" >
<return alias="vinc_matr" class="br.com.gppg.dto.csep_Busca_Vinc_Matr" lock-mode="read">
<return-property name="vinculo" column="P_VINCULO"/>
<return-property name="matricula" column="P_MATRICULA"/>
{call CSEP_BUSCA_VINC_MATR(:ID_USUARIO,{vinc_matr.vinculo},{vinc_matr.matricula})}

Code to call it:

session = HibernateUtil.currentSession();
Query query = session.getNamedQuery("CSEP_BUSCA_VINC_MATR");
query.setString("ID_USUARIO", "tstgp");

Here is error message:
INFO [STDOUT] Hibernate: {call CSEP_BUSCA_VINC_MATR(?,{vinc_matr.vinculo},P_MATRICULA)}
WARN [JDBCExceptionReporter] SQL Error: 17003, SQLState: null
ERROR [JDBCExceptionReporter] Invalid column index

Posted by Andre on Sunday, 03.2.08 @ 19:03pm | #51028

Nice job. I am a hard time understanding Hibernate but I find this tutorial very helpful. I will definitely use this as my reference.

Posted by jane on Wednesday, 02.27.08 @ 22:26pm | #50330

hi is there a way to get result in random manner in DetachedCriteria query i appreciates early response

Posted by Wishwa on Thursday, 11.29.07 @ 11:49am | #40878

thank you for your tutorial, the examples are great, i continue to use it as my reference

Posted by Kay on Thursday, 10.11.07 @ 04:35am | #33029

i need to know how to implement the sample or different example hibernate in Netbeans IDE.
Can anyone help out me?


Posted by selva on Tuesday, 09.18.07 @ 11:39am | #27462


This is very easy & quick learning tutorail...


Posted by sanjay Rakholiya on Wednesday, 05.30.07 @ 12:13pm | #17712

It is really good material for the beginners, nice, and thanks for your effort in presenting this material, try to update this one with the diffrent IDE's

Posted by vittal kambagi on Thursday, 04.26.07 @ 16:52pm | #14980

This tutorial is really very easy to understand and gives comprehensive knowledge of Hibernate.

Thank you for doing this great work Deepak.



Posted by Abhishek Tripathi on Monday, 04.2.07 @ 00:58am | #13151

Its really useful for me and he has explained all the topics with the very simple codes.
Thank you very much for the person who did this wonderful job..........

Posted by Sarath Babu on Thursday, 03.29.07 @ 15:49pm | #12912

I am facing problem in HQL.
I want to perform summation of products.

For example -
select (s.totalQuestions * s.weightageMarks) from Section s

But this doesnt work. If i try in SQL after converting the query it works fine.

It shows error at the '*' sign.
Can u guide how to perform multiplication using hibernate

Sameer Malde

Posted by Sameer Malde on Friday, 02.16.07 @ 19:26pm | #8070

Hi Deepak,

Can you please give me an example to delete an a Parent entity having a set of child entities using native SQL, that would be great?

Posted by Abhay on Friday, 12.29.06 @ 14:00pm | #2207

This is very nice tutorial I ever seen elsewhere. Much thanks to Deepak Kumar for explaining details in very simple way.


Posted by Kannan on Tuesday, 12.19.06 @ 14:38pm | #1232

I tried to run the FirstExample, but I got some NullPointerException. I think I missed the MySQL part. Would you explain how we should setup the database in order to run the hibernateexample?

Posted by Angie on Wednesday, 12.6.06 @ 20:11pm | #517

Hi Vivek,

You can read more about struts hibernate at http://www.roseindia.net/struts/struts-hibernate/index.shtml

n this tutorial I will show you how to integrate Struts and Hibernate. After completing this tutorial you will be able to use Hibernate in your Struts project. We will be using Hibernate Struts plug-in to write high performance application using Struts and Hibernate.

Deepak Kumar

Posted by Deepak Kumar on Wednesday, 11.29.06 @ 18:15pm | #205

I have gone throgh the complete tutorial....
If this is all in hibernate then thanks for making it so easy.
Really very nice tutorial...If u can show it with some struts(MVC) archietecture,then it will be really very useful.

Posted by Vivek Bhandarkar on Wednesday, 11.29.06 @ 18:11pm | #204

Ask programming questions?



Back to Tutorial


  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name


Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright 2007. All rights reserved.