You probably need to specify the return parameter from the query. I think
Hibernate is returning both the annotation and the OSBObject. So
Select ann From Annotation ann join ann.related_OSBObjects as osb where
osb.id = :osbId
Mike.
On 3/30/07, maskkkk <[EMAIL PROTECTED]> wrote:
Okay now I seem to be able to get the Annotation objects retrieved but I
can't seem to cast them from objects into Annotations...
new dao method wrote:
>
> public List<Annotation> getAnnotationsForOsbBaseObjectId(Long
osbId)
> {
> log.info("Begin:
getAnnotationsForOsbBaseObjectId()");
> // List find = getHibernateTemplate().find("From
Annotation ann join
> ann.related_OSBObjects as osb where osb.id = :osbId", osbId);
> // List <Annotation> list = find;
>
>
> String queryString = "From Annotation ann join
ann.related_OSBObjects
> as osb where osb.id = :osbId";
>
> List <Annotation> list =
getSession().createQuery(queryString)
> .setLong("osbId",
osbId)
> .list();
>
> if(list.isEmpty())
> {
> throw new ObjectRetrievalFailureException(
Annotation.class,
>
new
String(
> "Annotations not
found for query " + queryString +
> "with arguments
osbId: " + osbId));
>
> }
>
>
> log.info("Exit:
getAnnotationsForOsbBaseObjectId()");
> return list;
> }
>
test method where the dao dies wrote:
>
> public void testGetAnnotationsForOsbBaseObjectId()
> {
> testAnnotation = null;
>
> List <Annotation> annotationList = null;
> annotationList = dao.getAnnotationsForOsbBaseObjectId
(TEST_VERSE_ID);
>
> assertNotNull(annotationList);
> assertTrue(annotationList.size() > 0);
>
> // Dies when casting the object I retireved to an Annotation.
> Object o = (Annotation) annotationList.iterator().next(); //
<-- DIES
> HERE...
> log.debug(o);
>
> //testAnnotation = o;
> //assertEquals("Verse Sample Annotation 1",
> testAnnotation.getWiki_text());
>
> }
>
Stack Trace wrote:
>
> [junit] Testcase:
> testGetAnnotationsForOsbBaseObjectId(
com.conciliarpress.dao.AnnotationDaoTest):
> Caused an ERROR
> [junit] [Ljava.lang.Object;
> [junit] java.lang.ClassCastException: [Ljava.lang.Object;
> [junit] at
>
com.conciliarpress.dao.AnnotationDaoTest.testGetAnnotationsForOsbBaseObjectId
(AnnotationDaoTest.java:78)
> [junit] at
> org.springframework.test.ConditionalTestCase.runBare(
ConditionalTestCase.java:69)
>
Could this be a proxy? what with the Ljava.lang.Object?
Thank you again,
Andrew J. Leer
Michael Horwitz wrote:
>
> Hmm. It can definitely be done, but not sure the fectch clause is
exactly
> what you are after. The fetch clause simply forces a lazy loaded
> collection
> to load when you fetch the parent object. If all you are interested in
is
> the collection, then simply query for it?
>
> Something like:
>
> From Annotation ann join ann.related_OSBObjects as osb where osb.id =
> :osbId
>
> Mike.
>
> On 3/30/07, maskkkk <[EMAIL PROTECTED]> wrote:
>>
>>
>> Hello I am using Appfuse 1.9.4 to build a project:
>>
>> The feat I am trying to attempt here is to pass in the id of an
>> OSBBaseObject,
>> and retrieve all of the Annotations which are associated with it.
>>
>> There is a collection-many-to-many between the OSBBaseObject and
>> Annotation
>> classes.
>>
>> Now I talked to a guy online who told me that it could be done using a
>> FETCH
>> clause in HQL,
>> and thus far this is what I have:
>>
>>
>> what I have so far... wrote:
>> >
>> > ...
>> > public List<Annotation> getAnnotationsForOsbBaseObjectId(Long
>> osbId)
>> > {
>> > log.info("Begin:
>> getAnnotationsForOsbBaseObjectId()");
>> >
>> > //List <Annotation> list
>> = getHibernateTemplate().find("FROM
>> > Annotation ann WHERE ann. = ?", osbId);
>> >
>> > List <Annotation> list
>> = getHibernateTemplate().find("SELECT ann FROM
>> > Annotation ann FETCH ann.", osbId);
>> > select p from People p fetch p.friends
>> >
>> > //log.debug("Retrieved " + list.size() + "
>> results");
>> >
>> > log.info("Exit:
>> getAnnotationsForOsbBaseObjectId()");
>> > return list;
>> > }
>> > ...
>> >
>>
>> And bellow are the relationships as I have them defined in the back-end
>> of
>> my Appfuse webapp:
>>
>>
>> OSBBaseObject wrote:
>> >
>> > public abstract class OSBBaseObject extends BaseObject
>> > {
>> > private Long id;
>> > /**
>> > * The annotations that are assocated with
>> > * this OSBBaseObject.
>> > *
>> > */
>> > private Set annotations;
>> >
>> > ...
>> >
>> > /**
>> > * @hibernate.id
>> > * column="ID"
>> > * generator-class="hilo"
>> > * unsaved-value="null"
>> > */
>> > public Long getId(){ return id; }
>> > public void setId(Long id){ this.id = id;}
>> >
>> > /**
>> > * @hibernate.set
>> > * table="osbobjects_in_annotation"
>> > * cascade="save-update"
>> > * inverse="true"
>> > [EMAIL PROTECTED]
>> > * column="fk_annotation"
>> > * class="com.conciliarpress.model.Annotation"
>> > * @hibernate.collection-key
>> > * column="fk_osbbaseobject"
>> > */
>> > public Set getAnnotations(){ return annotations; }
>> > public void setAnnotations(Set a){ this.annotations = a; }
>> > ...
>> > }
>> >
>>
>>
>> Annotation Class wrote:
>> >
>> > public class Annotation
>> > {
>> > private Long id;
>> > private Set related_OSBObjects;
>> >
>> > /**
>> > * @hibernate.id
>> > * column="ID"
>> > * generator-class="hilo"
>> > * unsaved-value="null"
>> > */
>> > public Long getId() { return id; }
>> > public void setId(Long id) { this.id = id; }
>> >
>> > /**
>> > * @hibernate.set
>> > * table="osbobjects_in_annotation"
>> > * cascade="save-update"
>> > [EMAIL PROTECTED]
>> > * column="fk_osbbaseobject"
>> > * class="com.conciliarpress.model.OSBBaseObject"
>> > * @hibernate.collection-key
>> > * column="fk_annotation"
>> > *
>> > */
>> > public Set getRelated_OSBObjects() { return
>> related_OSBObjects; }
>> > public void setRelated_OSBObjects(Set related_OSBObjects)
>> > {this.related_OSBObjects = related_OSBObjects; }
>> >
>> > }
>> >
>>
>> Can this type of relationship be retrieved in HQL? Or am I required to
>> make
>> use of proxies?
>>
>> Thank you,
>> Andrew J. Leer
>> --
>> View this message in context:
>>
http://www.nabble.com/Retrieving-a-May-to-many-relationship--tf3492039s2369.html#a9752623
>> Sent from the AppFuse - User mailing list archive at Nabble.com.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: [EMAIL PROTECTED]
>> For additional commands, e-mail: [EMAIL PROTECTED]
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/Retrieving-a-May-to-many-relationship--tf3492039s2369.html#a9756419
Sent from the AppFuse - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]