-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: HQL vs Criteria API with fetchMode=JOIN
PostPosted: Fri Apr 22, 2016 7:58 am 
Newbie

Joined: Fri Sep 03, 2010 6:27 pm
Posts: 8
Location: Munich
In the class "Ticket" we have a relation with TicketLine:

Code:
    @OneToMany(targetEntity = TicketLine.class, fetch = FetchType.EAGER)
     @Fetch(org.hibernate.annotations.FetchMode.JOIN)
    @Cascade ....
    @IndexColumn(name = "line_index")
    public List<TicketLine> getLines() {
        return ticketlines;
    }


The following two queries return different results

1. HQL

Code:
                Srting sql = "from Ticket where dateClose is null "
                        + "and host = ?"
                        + "and place = ?";
                q = session.createQuery(sql)
                        .setString(0, AppConfig.getInstance().getHost())
                        .setEntity(1, place);
                List<Ticket> tickets = q.list();


Result: tickets contains 2 tickets as expected. Ticket 1 has 3 ticketlines, Ticket 2 has 5 ticketlines.

2. Criteria API

Quote:
Criteria crit = session.createCriteria(Ticket.class);
crit.add(Restrictions.isNull("dateClose"));
crit.add(Restrictions.eq("host", AppConfig.getInstance().getHost()));
crit.add(Restrictions.eq("place", place));
List<Ticket> tickets = crit.list();


Result: tickets contains 8 tickets, i.e. the JOIN is fully reflected and the result set contains 1 Ticket for each line.

Is this a bug or am I missing something?


Top
 Profile  
 
 Post subject: Re: HQL vs Criteria API with fetchMode=JOIN
PostPosted: Fri Apr 22, 2016 8:46 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
It looks like an issue. Please fill a bug request on Jira accompanied by a replicating test case.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.