-->
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.  [ 5 posts ] 
Author Message
 Post subject: "where" attribute is not being applied to collecti
PostPosted: Wed Mar 31, 2004 6:04 pm 
Regular
Regular

Joined: Sun Oct 26, 2003 9:02 pm
Posts: 90
I have a parent/child relationship and the child class has a "deleted" attribute so I can set it to true when I want to delete a child. I use the "where" attribute in the mapping file that specifies to load if "deleted != 'Y'". When I load the parent hibernate is not applying the where clause to the child query. The query is:

Hibernate: select childs0_.id as id__, childs0_.parent_id as parent_id__, childs0_.order_seq as order_seq__, childs0_.id as id0_, childs0_.name as name0_, childs0_.deleted as deleted0_, childs0_.parent_id as parent_id0_ from child childs0_ where childs0_.parent_id=?

Test Case:

Parent.hbm.xml:
<hibernate-mapping>

<class name="mypackage.Parent" table="parent">
<id name="id" column="id" type="long" unsaved-value="0">
<generator class="hilo">
<param name="table">sequences</param>
<param name="column">next_value</param>
<param name="max_lo">1000</param>
</generator>
</id>
<property name="name" column="name" type="string"/>
<list name="childs" lazy="false" cascade="all">
<key column="parent_id"/>
<index column="order_seq"/>
<one-to-many class="mypackage.Child"/>
</list>
</class>

</hibernate-mapping>

Child.htm.xml:
<hibernate-mapping>

<class name="mypackage.Child" table="child" where="deleted != 'Y'">
<id name="id" column="id" type="long" unsaved-value="0">
<generator class="hilo">
<param name="table">sequences</param>
<param name="column">next_value</param>
<param name="max_lo">1000</param>
</generator>
</id>
<property name="name" column="name" type="string"/>
<property name="deleted" column="deleted" type="yes_no"/>
<many-to-one name="parent" column="parent_id"/>
</class>

</hibernate-mapping>

Parent.java:
public class Parent
{
protected long id;
protected String name;
protected List childs = new ArrayList ();

public Parent()
{
}

public long getId()
{
return id;
}

public void setId(long newId)
{
id = newId;
}

public String getName()
{
return name;
}

public void setName(String newName)
{
name = newName;
}

public List getChilds()
{
return childs;
}

public void setChilds(List newChilds)
{
childs = newChilds;
}
}

Child.java:
public class Child
{
protected long id;
protected String name;
protected Parent parent;
protected boolean deleted;

public Child()
{
}

public long getId()
{
return id;
}

public void setId(long newId)
{
id = newId;
}

public String getName()
{
return name;
}

public void setName(String newName)
{
name = newName;
}

public Parent getParent()
{
return parent;
}

public void setParent(Parent newParent)
{
parent = newParent;
}

public boolean isDeleted()
{
return deleted;
}

public void setDeleted(boolean newDeleted)
{
deleted = newDeleted;
}
}

Test:

Transaction transaction;
Configuration configuration = new Configuration ();
SessionFactory factory;
Session session;
Parent parent;
Child child;

configuration.addClass (Parent.class);
configuration.addClass (Child.class);

factory = configuration.buildSessionFactory ();
session = factory.openSession ();

parent = new Parent ();
parent.setName ("Example");

child = new Child ();
child.setName ("Example Child");
child.setDeleted (true);
child.setParent (parent);
parent.getChilds ().add (child);

transaction = session.beginTransaction ();
session.saveOrUpdate (parent);
transaction.commit ();

session.close ();
session = factory.openSession ();

parent = (Parent) session.find ("from Parent where name = ?", "Example", Hibernate.STRING).get (0);

System.out.println (parent.getChilds ().size ()); // displays 1
session.close ();


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 6:30 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i have exactly the same
http://forum.hibernate.org/viewtopic.php?t=929493

but i don't know if it is normal...


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 7:09 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It is normal. Note that collections have their own where attribute.


Top
 Profile  
 
 Post subject: Thanks for the reply
PostPosted: Wed Mar 31, 2004 10:01 pm 
Regular
Regular

Joined: Sun Oct 26, 2003 9:02 pm
Posts: 90
Missed it in the documentation.

Thanks Gavin


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 3:17 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i've read it in the doc but what about many-to-many, we can only define a clause where on the association table, what i want is to respect the one i've define for one end.
My question is pretty simple, is it possible?
Thanks

if someone can take a look at
http://forum.hibernate.org/viewtopic.php?t=929493

Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.