Get all updates of Java4s
Follow Us: Email Newsletter

Part 5 Hibernate Query Language, Passing Runtime Values

Hibernate » On Jul 9, 2011 { 7 Comments } By Sivateja

Now we will see, how to pass the values at time time while using the HQL  select query, actually same concept for 3 cases.

Required files…

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

Product.java

hibernate.cfg.xml

 

Product.hbm.xml

ForOurLogic.java

 

 

Eclipse Console

In The Database

Notes:

  • As i discussed earlier, in the hibernate we can pass the values into the hibernate query at run time also
  • See the commented code from line numbers 1839,  that if we would like to use Label rather question mark symbol
  • See the HQL query in line number 20, i have been used label :java4s [ as a programmer its our responsible to let the hibernate to know its the label not the value, by specifying the colon(:) symbol at starting of label ]
  • In line number 21 i used setParameter method to give the value that’s it.
  • And if you observer line number 41, i used question mark symbol rather label, this time in setParameter method i used zero (0) as first parameter and value in second parameter, remember if use more than one question mark symbol in the query then also the index will starts from zero only

 

You Might Also Like

  ♦ About Author ♦

Java4s_Author
sivateja@java4s.com
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.

Comments

7 Responses to “Part 5 Hibernate Query Language, Passing Runtime Values”
  1. Luisa Sedgwick says:

    You got a very superb website, Sword lily I noticed it through yahoo.

  2. utkal samal says:

    Please let me know ,when we pass a runtime value as a Level or as a Question mark? which one is the better approach ?or which one is the recomanded ??????

  3. Java4s says:

    @Utkal samal

    Actually its depends on you friend.
    But i always recommend question marks, as its quick ;) in most of the real time projects i saw question marks only.

  4. Neeraj+Kashyap says:

    How it is passing the value at runtime coz we are doing setparameter. I mean we have hardcoded the identifier in the next line then how its dynamic query build?

  5. vijay says:

    why parameter start from 0

  6. keshav says:

    sir, setParameter(- ,-) method in which class method.
    thank u for advance

  7. Arpita says:

    Really nice site…Thank you so much guys..for making it so simple

Name*
Mail*
Website



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
Upcoming
  Web Services [ SOAP ], JSP
Contact | About Us | Privacy Policy | Advertise With Us

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