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 6925909
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:51:01+00:00 2026-05-27T10:51:01+00:00

Hibernate seems to incorrectly handle date ranges using the Criterion API in Oracle. The

  • 0

Hibernate seems to incorrectly handle date ranges using the Criterion API in Oracle. The SQL Query itself seems correct (copied it from Hibernate and executed it manually). So,

given

Clazz<Bar> clazz;
Date start, end; 

this fails

List<Bar> bars = sessionFactory.getCurrentSession()
    .createCriteria(clazz)
    .add(Restrictions.between("timestamp", start, end))
    .list();

and this

 List<Bar> bars = sessionFactory.getCurrentSession()
     .createCriteria(clazz)
     .add(Restrictions.ge("timestamp", start))
     .add(Restrictions.le("timestamp", end))
     .list();

but this works

List<Bar> bars = sessionFactory.getCurrentSession()
    .createQuery("from Bar b where b.timestamp > ? and b.timestamp < ?")
    .setDate(0, start)
    .setDate(1, end)
    .list();

The fail observation is:

  1. The number of Bar results returned are the same (and correct)

  2. but in the criterion cases a Bar with a List<Foo> returns roughly 10x more Foo objects than the corresponding SQL query does. All the extra Foo objects are identical copies.


EDIT

@Entity
public class Bar {

    @Id 
    private String id;

    @Temporal(TemporalType.TIMESTAMP)
    private Date timestamp;

    @ManyToMany(cascade = CascadeType.ALL, fetch=FetchType.EAGER)
    @JoinTable(
        name = "bar_foo",
        joinColumns = { @JoinColumn(name = "barid") },
        inverseJoinColumns = { @JoinColumn(name = "fooid") }
    )
    private List<Foo> params;
}
@Entity
public class Foo {
    @Id private String id;
}
  • 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-27T10:51:02+00:00Added an answer on May 27, 2026 at 10:51 am

    I can’t remember or look up the rationale behind this right now but what you are seeing might be expected behavior. Try this:

    criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new in hibernate,after read the hibernate api and tutorial,it seems that the
It seems like most examples of JPA/Hibernate entity bean classes I've seen do no
NHibernate Version: 2.1 I'm using what seems to be a pretty standard HttpModule approach
I'm trying to add JBoss repository to m2eclipse, mainly for Hibernate. It seems to
I'm trying to learn Spring+Hibernate and I started using Lazy loading with Hibernate. To
We're using hibernate entitymanager to map our entities through JPA. And we are using
I'm trying to get the following query to work in Hibernate: SELECT m FROM
It seems to me that JBoss reuses entity managers and the underlying hibernate sessions
I am using org.hibernate.cfg.ImprovedNamingStrategy, But for a table I have specified the table name
Using hibernate ctiteria I want to select an object and it's associated oneToMany list

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.