Get all updates of Java4s
Follow Us: Email Newsletter

Hibernate Named Query Example

Hibernate » On Jul 14, 2011 { 3 Comments } By Sivateja

Let us see an example on Hibernate Named Queries,

files required…

  • class)
  • Product.hbm.xml
  • hibernate.cfg.xml
  • (For writing our business logic)




  • See Product.hbm.xml file, line numbers 15, 16, 17, we have given one HQL query in the <query /> element
  • In file, line number 23 will get that query from mapping xml into Query object, in line 24 we just passed the value to that label normally

But if you would like to use Named Query with Native SQL, then we need to change our mapping file like…



Note: In this case we need to use one new element <sql-query /> unlike <query /> element which we used to write HQL query

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.


3 Responses to “Hibernate Named Query Example”
  1. sandilya says:

    How to validate to fields in a table from the given values in hibernate for JavaFX using eclipse
    For ex:
    Username = “********”
    Password = “*******”

    I want to know whether the given values are same as in the table.

  2. karthick says:

    nice tutorial…very useful to me….

  3. mike says:

    How to perform the same with projection in the query like
    “select ab.pname from Products ab ”


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.