Get all updates of Java4s
Follow Us: Email Newsletter

Example On Hibernate Delete Query

Hibernate » On Jun 12, 2011 { 7 Comments } By Sivateja

This is the program to Delete a row (Object) from the database, just like using delete query in the jdbc program..

Files required to execute this program..

  • (My POJO class)
  • Product.hbm.xml (Xml mapping file )
  • hibernate.cfg.xml (Xml configuration file)
  • file to write our hibernate logic) (POJO)





As usual compile all .java programs and run to see the output

Eclipse output

Oracle DB, Before Run The Program

Oracle DB, After Run the program


  • To deleting the object( 1 row) form the database we need to call delete method in the session.
  • In the hibernate we have only one method to delete an object from the database that is what i have shown you here..

You Might Also Like

  ♦ About Author ♦

Full Stack( Java/J2EE & UI/UX ) Developer and founder of Java4s - Get It Yourself, A popular Java/J2EE Programming Blog. Sign-up for the Email Newsletter for your daily dose of Java tutorials.


7 Responses to “Example On Hibernate Delete Query”
  1. manik says:

    are the column names in the pojo class case sensitive??

  2. bbvnb says:

    its very gud website to leran basic concepts

  3. Nagaraju says:

    Hi Siva,

    Can we delete multiple rows at a time,
    for eg i am using the below code to delete multiple rows

    Object o=session.load(Sample.class,new Integer(9035));
    Object o1=session.load(Sample.class,new Integer(9037));
    Sample s=(Sample)o;
    Sample s1=(Sample)o1;
    Transaction tx = session.beginTransaction();

    but is it possible to write the above code in oneline like

    Object o1=session.load(Sample.class,new Integer(9037,9035));

    Please give me the clarification for this post.


  4. Pallavi HN says:

    Sir, in hibernate we are having delete(String agr0,Object obj).what is the use of this.can you expalin us please.Thank you

  5. Avinash Kumar says:

    Yes, We can delete multiple rows at a time.

  6. santhosh says:

    Hello siva,
    Iam unable to delete the rows from my we create table already in our database before deleted.

    And why the ddl is update while we perform delete query.

    please help me in doing this.

    Thanks in advance.

  7. Sanjay says:

    You are sending product id 103 like
    Object o=session.load(Product.class,new Integer(103));

    How hibernate will identify we are sending product id???


By posting your answer, you agree to our comments policy.
What would you like to learn today?
Browse these popular technologies
Hibernate spring struts Servlets ajax Log4j jQuery Json Core Java Web Services AngularJs
Most Recent Tutorials
Hibernate_Logo Hibernate Recent Posts Spring_Logo Spring Recent Posts Struts_Logo Struts Recent Posts
Useful Links Current & UpComing Tutorials
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

© 2010 - 2017 Java4s - Get It Yourself.
The content is copyrighted to Sivateja Kandula and may not be reproduced on other websites.