Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6168745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:44:30+00:00 2026-05-23T22:44:30+00:00

By the moment, I know four kinds of doing transactions with hibernate: Using objects

  • 0

By the moment, I know four kinds of doing transactions with hibernate:

  1. Using objects
  2. Using HQL
  3. Using DB-specific SQL
  4. Using criteria (QBE)

Well, regarding how strong are they against injections, I think these are (correct me if I’m wrong):

  1. Secure, because the internal SQL call is parameterized.
  2. Secure if the query is parameterized, insecure otherwise.
  3. Same as #2 but not as portable.
  4. Insecure?

My question is about #4, Query by Example, because i’ve found it is also vulnerable. Example:

    Account a = new Account(); //POJO class       
    a.setId("1' OR '1'='1");

    //s is a org.hibernate.Session instance
    Criteria crit = s.createCriteria(Account.class);
    crit.add(Example.create(a));
    List results = crit.list();  //table dump!

That snippet selects the whole accounts table. Is there any way to prevent injection? How?

NOTE: I’m using Hibernate 3.6.5 final, the testing database is HSQLDB.

UPDATE: Seems like a bug to me too, and indeed may be not related to the injected SQL. Tried setting the id with a nonexistent value and also returns all the rows. Tried the injection with ‘5’=’5′ instead of ‘1’=’1′ and the 5 is not propagated to the SQL call. It keeps using (1=1) as where clause.

UPDATE 2: Solved. See the answer below.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T22:44:31+00:00Added an answer on May 23, 2026 at 10:44 pm

    Hibernate QBE ignores the id (mapped to PK) fields. Seems that this is done because an id filter would return only a row, and this can be achieved with a get() or a load(). I wonder what if I want to use a like condition on the id???

    Related posts on hibernate official forum:

    https://forum.hibernate.org/viewtopic.php?t=927063

    https://forum.hibernate.org/viewtopic.php?t=938036

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know how to determine the active network type at the specific moment:
at the moment we're using SVN (yeah, I know that's shame :)) and we're
Does anyone know how to make labels, or text, smoother? At the moment they
At moment I want to implement picture upload without using any plug-ins. My upload
At the moment I'm using JavaFX only for fun and learning it. What I
I know this is only part of a programming question, but at the moment,
I decide to write a plugin, but there is a moment I don't know,and
I know object oriented PHP and Java, and I can code Javascript fairly well
I know, I know IE6 right? Well no matter how strong the argument --
I have a method that receives many different kinds of objects and decides what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.