[Hibernate-JIRA] Created: (HHH-4085) Specifying a select clause triggers the "query specified join fetching, but the owner..." exception
by Kent Tong (JIRA)
Specifying a select clause triggers the "query specified join fetching, but the owner..." exception
---------------------------------------------------------------------------------------------------
Key: HHH-4085
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4085
Project: Hibernate Core
Issue Type: Bug
Components: query-hql
Affects Versions: 3.3.2
Environment: Kubuntu 9.04
Reporter: Kent Tong
An Order contains some OrderItem's. Each OrderItem contains a Product and a quantity. To retrieve the Orders, The following HQL works:
Code:
from Order o left join fetch o.items i join fetch i.product
However, if I specify the select clause:
Code:
select o from Order o left join fetch o.items i join fetch i.product
Then Hibernate will return an error:
Code:
Exception in thread "main" org.hibernate.QueryException: query specified join fetching, but the owner of the fetched association was not present in the select list [FromElement{explicit,not a collection join,fetch join,fetch non-lazy properties,classAlias=null,role=null,tableName=Product,tableAlias=product2_,origin=items items1_,colums={items1_.p_id ,className=lab3.Product}}] [select o from lab3.Order o left join fetch o.items i join fetch i.product]
at org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:217)
at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:727)
at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:551)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:645)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:229)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:251)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:183)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:134)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:94)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1650)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.hibernate.context.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:342)
at $Proxy0.createQuery(Unknown Source)
at lab3.OnlineStoreApp.run(OnlineStoreApp.java:32)
at lab3.OnlineStoreApp.main(OnlineStoreApp.java:14)
The test code is shown below:
Code:
package lab3;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class OnlineStoreApp {
private SessionFactory factory;
private Session session;
public static void main(String[] args) {
new OnlineStoreApp().run();
}
public OnlineStoreApp() {
Configuration cfg = new Configuration();
cfg.configure();
factory = cfg.buildSessionFactory();
}
@SuppressWarnings("unchecked")
private void run() {
session = factory.getCurrentSession();
session.beginTransaction();
Order o = new Order();
o.getItems().add(new OrderItem(new Product("p1"), 10));
o.getItems().add(new OrderItem(new Product("p2"), 20));
session.save(o);
List<Order> orders = session
.createQuery(
"select o from Order o left join fetch o.items i join fetch i.product")
.list();
System.out.println(orders.size());
session.getTransaction().commit();
}
}
package lab3;
import java.util.ArrayList;
import java.util.List;
public class Order {
private Long internalId;
private List<OrderItem> items;
public Order() {
items = new ArrayList<OrderItem>();
}
public Long getInternalId() {
return internalId;
}
public void setInternalId(Long internalId) {
this.internalId = internalId;
}
public List<OrderItem> getItems() {
return items;
}
public void setItems(List<OrderItem> items) {
this.items = items;
}
}
package lab3;
public class OrderItem {
private Product product;
private int qty;
public OrderItem() {
}
public OrderItem(Product product, int qty) {
this();
this.product = product;
this.qty = qty;
}
public Product getProduct() {
return product;
}
public void setProduct(Product product) {
this.product = product;
}
public int getQty() {
return qty;
}
public void setQty(int qty) {
this.qty = qty;
}
}
package lab3;
public class Product {
private Long internalId;
private String name;
public Product() {
}
public Product(String name) {
this();
this.name = name;
}
public Long getInternalId() {
return internalId;
}
public void setInternalId(Long internalId) {
this.internalId = internalId;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
<?xml version="1.0"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.url">jdbc:h2:tcp://localhost/~/test</property>
<property name="hibernate.connection.driver_class">org.h2.Driver</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password"></property>
<property name="hibernate.hbm2ddl.auto">update</property>
<property name="hibernate.dialect">org.hibernate.dialect.H2Dialect</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.show_sql">false</property>
<mapping resource="Product.hbm.xml"/>
<mapping resource="Order.hbm.xml"/>
</session-factory>
</hibernate-configuration>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="lab3.Order" table="orders">
<id name="internalId">
<generator class="sequence"></generator>
</id>
<list name="items" cascade="save-update">
<key column="o_id"></key>
<list-index column="idx"></list-index>
<composite-element class="lab3.OrderItem">
<many-to-one name="product" column="p_id" cascade="save-update"></many-to-one>
<property name="qty"></property>
</composite-element>
</list>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="lab3.Product">
<id name="internalId">
<generator class="sequence"></generator>
</id>
<property name="name"></property>
</class>
</hibernate-mapping>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years, 7 months
[Hibernate-JIRA] Created: (HHH-2374) setFetchMode() ignore incorect path
by Baptiste MATHUS (JIRA)
setFetchMode() ignore incorect path
-----------------------------------
Key: HHH-2374
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2374
Project: Hibernate3
Type: Bug
Versions: 3.2.0.ga
Environment: All DB I guess
Reporter: Baptiste MATHUS
This bug report is in fact a copy of the one that was already present in H2 : http://opensource.atlassian.com/projects/hibernate/browse/HB-763 . It does not seem to have changed in H3.
When calling setFetchMode("path", FetchMode.JOIN) on a criteria, even if the path is not correct, Hibernate does not complain. Its behaviour seems to be to simply ignore this bad path. I guess this should throw an exception. In fact, the bad thing of ignoring bad path is that if the developer was wrong specifying the path (typo, for example), then the join simply won't happen :-/.
I wrote a very simple testcase :
public void testFindClients()
{
Session session = HibernateUtil.currentSession();
session.beginTransaction();
Client c = (Client)session.createCriteria(Client.class).setFetchMode("foo", FetchMode.JOIN)
.setFetchMode("foo.bar", FetchMode.JOIN).uniqueResult();
session.getTransaction().commit();
}
My Client class has some relationships with other classes, but obviously none named "foo". The code above just issue the following select :
select
this_.ID as ID0_0_,
this_.nom as nom0_0_,
this_.prenom as prenom0_0_,
this_.age as age0_0_
from
Client this_
Thanks again for your great work, guys!
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
15 years, 7 months
[Hibernate-JIRA] Updated: (HHH-5508) setFetchMode() ignore incorect path
by Gail Badner (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-5508?page=c... ]
Gail Badner updated HHH-5508:
-----------------------------
Description:
In a criteria, call to setFetchMode() with an incorect path don't throw any exception. Hibernate just ignore it.
That mean that some optimisation we expect won't append, and because of lazy initialization, everything may look to work fine, except it will run much slower.
Adrien
was:
In a criteria, call to setFetchMode() with an incorect path don't throw any exception. Hibernate just ignore it.
That mean that some optimisation we expect won't append, and because of lazy initialization, everything may look to work fine, except it will run much slower.
Adrien
Affects Version/s: 3.2.0.ga
> setFetchMode() ignore incorect path
> -----------------------------------
>
> Key: HHH-5508
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5508
> Project: Hibernate Core
> Issue Type: Improvement
> Components: core, query-criteria
> Affects Versions: 3.2.0.ga, 3.5.5, 3.6.0.Beta3
> Reporter: Adrien
> Assignee: Michael Gloegl
> Attachments: CriteriaImpl.java, SessionImpl.java
>
>
> In a criteria, call to setFetchMode() with an incorect path don't throw any exception. Hibernate just ignore it.
> That mean that some optimisation we expect won't append, and because of lazy initialization, everything may look to work fine, except it will run much slower.
> Adrien
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years, 7 months
[Hibernate-JIRA] Updated: (HHH-1425) Setting Projection for Criteria brake previously set Fetch mode.
by Gail Badner (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-1425?page=c... ]
Gail Badner updated HHH-1425:
-----------------------------
Affects Version/s: 3.5.5
3.6.0.Beta3
I am seeing this behavior in 3.5.5 and 3.6.0.Beta-3.
In trunk, it is because in org.hibernate.loader.criteria.CriteriaJoinWalker.getJoinType():
<code>
if ( translator.hasProjection() ) {
return -1;
}
</code>
-1 indicates no join.
> Setting Projection for Criteria brake previously set Fetch mode.
> ----------------------------------------------------------------
>
> Key: HHH-1425
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-1425
> Project: Hibernate Core
> Issue Type: Bug
> Components: query-criteria
> Affects Versions: 3.1.2, 3.5.5, 3.6.0.Beta3
> Environment: Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_03-b07)
> MySQL 4.1.9-standard
> Reporter: Ivan Latysh
>
> A criteria query:
> Criteria cr = session.createCriteria(ApplicationBean.class);
> cr.setFetchMode("categories", FetchMode.JOIN);
> cr.add(Expression.sql("category_id=?", "2", Hibernate.STRING));
> cr.list();
> execute without an error, and produce proper sql and return expected results.
> But when I add projection right before list():
> Criteria cr = session.createCriteria(ApplicationBean.class);
> cr.setFetchMode("categories", FetchMode.JOIN);
> cr.add(Expression.sql("category_id=?", "2", Hibernate.STRING));
> cr.setProjection(Projections.count("id"));
> cr.list();
> Query produce an SQL without a join.
> This issue has been discovered after upgrade from 3.0.5 to 3.1.2
> Mapping:
> <hibernate-mapping package="a.b">
> <class name="ApplicationBean" table="application">
> <id name="id" column="id" type="long">
> <generator class="identity"/>
> </id>
> ...
> <!-- Application categories -->
> <set name="categories" cascade="all-delete-orphan" lazy="true" table="application_category">
> <key column="application_id"/>
> <composite-element class="a.b.ApplicationCategory">
> <many-to-one name="category" class="a.b.CategoryBean" column="category_id" cascade="none">
> </many-to-one>
> </composite-element>
> </set>
> </class>
> </hibernate-mapping>
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
15 years, 7 months
[Hibernate-JIRA] Created: (HHH-2344) Persistent collection queued operation ignored with lazy inverse one-to-many collection.
by Sebastien Robert (JIRA)
Persistent collection queued operation ignored with lazy inverse one-to-many collection.
----------------------------------------------------------------------------------------
Key: HHH-2344
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2344
Project: Hibernate3
Type: Bug
Components: core
Versions: 3.2.1
Environment: Hibernate 3.2.1
Reporter: Sebastien Robert
I load an Object that contains a lazy inverse collection (one-to-many).
Hibernate wrap my collection with a PersistentMap
There is objects in the collection in the database but in my case the PersistentMap is not yet initialized.
I perform a remove operation on the persistentMap with a known key of one of the objects.
The map is not initialized (and the relation is an inverse one-to-many) so the map queue the removeOperation.
I perform a get operation with the same key and the value is still returned.
If we look closer at what happened in the PersistentMap, it's look like this.
//*****
public Object remove(Object key) {
if ( isPutQueueEnabled() ) { // This returned true, the
// map is not yet
// initialized
Object old = readElementByIndex( key ); // This method triggered
// an initialization of the
// map.
// Queued operation are
// processed in the after
// init method
queueOperation( new Remove( key, old ) ); // The remove operation
// is queued.
return old;
}
....
//*******
When i perform the get operation on the map the map is now initialized. The get is processed by the underlying map and the value is returned. The queued operation is completely ignored.
Currently i fixed my code by performing a containsKey before the remove . The containsKey initialize the map and then the remove do not queue the operation. But by looking at all the PersistentCollection it seem that i may have the same problem using put and remove with other persistentCollection.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira
15 years, 7 months