-->
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.  [ 10 posts ] 
Author Message
 Post subject: The collection was unreferenced
PostPosted: Wed May 10, 2006 1:54 am 
Newbie

Joined: Mon Sep 26, 2005 4:08 am
Posts: 15
Hi Everyone,

i am trying to use collection filters but i am getting this error:
The collection was unreferenced

Here is what i am doing:

-- I have a xml mapping file which has a query defined:

<query name="tmp" cacheable="true">
<![CDATA[
SELECT M1 as Milestone
FROM Milestone M1
]]>
</query>

Next, i have a method which returns a list i.e.

public List tmp() {

Query query= getSession().getNamedQuery("tmp");

Query filterQuery = getSession().createFilter( getSession().getNamedQuery("tmp"), "");

return filterQuery.list();
}

now whenever i call this method, i get an error: The collection was unreferenced in line which says: return filterQuery.list();


Please Advise.
Many Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 2:09 am 
Regular
Regular

Joined: Wed Aug 25, 2004 6:23 am
Posts: 91
Hi gaurav_sting,
The error that you are getting is because you are passing an empty query string into createFilter but Collection filters can only be applied to mapped collections, not queries anyway I'm afraid.

Hope that helps,
Cheers,
Rich.


Top
 Profile  
 
 Post subject: mapped collections
PostPosted: Wed May 10, 2006 2:20 am 
Newbie

Joined: Mon Sep 26, 2005 4:08 am
Posts: 15
HI Rich,

Can u plz guide me how to use mapped collection here.

Thanx alot.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 2:40 am 
Regular
Regular

Joined: Wed Aug 25, 2004 6:23 am
Posts: 91
Ok, post your mappings and I'll show you an example


Top
 Profile  
 
 Post subject: Mappings
PostPosted: Wed May 10, 2006 3:19 am 
Newbie

Joined: Mon Sep 26, 2005 4:08 am
Posts: 15
HI Rich,

This is my mapping file:


<hibernate-mapping package="lotusssnd.projections.domain">
<class name="Milestone" table="milestone">

<id name="id" column="id" type="java.lang.Integer">
<generator class="hilo" />
</id>

<property name="milestoneDefinition" column="milestone_definition" type="java.lang.String" not-null="true" />

<property name="milestonePlannedHours" column="planned_hours"
type="java.lang.Integer" not-null="true" />

<many-to-one name="module" column="module_id" class="Module"
not-null="true" lazy="false" />

<many-to-one name="milestoneOwner" column="milestone_owner_id"
class="Associate" not-null="true" />

</class>


<query name="tmp" cacheable="true">
<![CDATA[

SELECT M1 as Milestone
FROM Milestone M1

]]>
</query>

</hibernate-mapping>

i have written a DAO Method which in which i am trying to create the filter, this is:

public List tmp() {

Query query= getSession().getNamedQuery("tmp");

Query filterQuery =
getSession().createFilter( getSession().getNamedQuery("tmp"), "");

return filterQuery.list();

}

whenevery i call this method i get an error in line where return statement is written -> the collection was unreferenced.

Rich, Thanx alot for your cooperation and help.
Regards.


Top
 Profile  
 
 Post subject: Mappings
PostPosted: Wed May 10, 2006 3:20 am 
Newbie

Joined: Mon Sep 26, 2005 4:08 am
Posts: 15
HI Rich,

This is my mapping file:


<hibernate-mapping package="lotusssnd.projections.domain">
<class name="Milestone" table="milestone">

<id name="id" column="id" type="java.lang.Integer">
<generator class="hilo" />
</id>

<property name="milestoneDefinition" column="milestone_definition" type="java.lang.String" not-null="true" />

<property name="milestonePlannedHours" column="planned_hours"
type="java.lang.Integer" not-null="true" />

<many-to-one name="module" column="module_id" class="Module"
not-null="true" lazy="false" />

<many-to-one name="milestoneOwner" column="milestone_owner_id"
class="Associate" not-null="true" />

</class>


<query name="tmp" cacheable="true">
<![CDATA[

SELECT M1 as Milestone
FROM Milestone M1

]]>
</query>

</hibernate-mapping>

i have written a DAO Method which in which i am trying to create the filter, this is:

public List tmp() {

Query query= getSession().getNamedQuery("tmp");

Query filterQuery =
getSession().createFilter( getSession().getNamedQuery("tmp"), "");

return filterQuery.list();

}

whenevery i call this method i get an error in line where return statement is written -> the collection was unreferenced.

Rich, Thanx alot for your cooperation and help.
Regards.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 3:44 am 
Regular
Regular

Joined: Wed Aug 25, 2004 6:23 am
Posts: 91
You don't seem to have any collections mapped. What exactly is it that you are trying to do?


Top
 Profile  
 
 Post subject: collections mapping
PostPosted: Wed May 10, 2006 4:26 am 
Newbie

Joined: Mon Sep 26, 2005 4:08 am
Posts: 15
Hi Rich,

I think i am going totally astray in my approach, according to my understanding collections mappings are used to filter a collection of record-set returned from the database, for instance, if we have a collection of records fetched from a query say: select * from milestone.

i thought collection filters could be used for further filteration of recordset based on the WHERE clause. Is this achievable using collection filters?

Actually, the issue is that, i am using a method level interceptor to intercept methods (Spring Framework) defined at the DAO level, earlier i used filters using <filter></filter> in my mapping file and was able to filter records based on the value.

I was facing a problem with joins in filters i.e. using joins to other tables, so someone suggested me to use collection filters, in which i think it is possible to use joins and then apply filters after that. That is why i was trying to use filters. Can u plz help me, i've been trying since many days and not able to achieve.

Regards.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 10, 2006 4:52 am 
Regular
Regular

Joined: Wed Aug 25, 2004 6:23 am
Posts: 91
No Session.createFilter can only be applied to a mapped collection not a query so it is no use to you unless you want to map all of the things that you want to filter as collections.

Can you use subselects to get around your need for joins in <filter> elements?


Top
 Profile  
 
 Post subject: subselects
PostPosted: Wed May 10, 2006 5:11 am 
Newbie

Joined: Mon Sep 26, 2005 4:08 am
Posts: 15
Hi again,

Sorry for bothering you unnecessarily, but can u plz help me by giving an example of subselects or what changes has to be done to my mapping file to get the collections thing working. i think subselect would be a better option, how can i use this and where are the places i'll need to do changes to use <subselect>

Regards.


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