-->
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: Accessing a property of a composite-element in a collection
PostPosted: Tue Jul 26, 2005 5:47 am 
Beginner
Beginner

Joined: Fri Feb 11, 2005 12:03 pm
Posts: 48
Location: Kiel, Germany
I have a Session object which has a List of SessionAttribute objects.
The SessionAttribute is mapped as a composite-element.

How can I query all Session objects which have a SessionAttribute whose value property has a specific value?

POJOs
Code:
public class Session
{
   private long sessionId;
   private List attributes;
   private String name;

        // + getter/setter
}


Code:
public class SessionAttribute
{
   private String name;
   private String value;

        // + getter/setter
}


Hibernate version:
2.0

Mapping documents:

Code:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping
>
    <class
        name="de.wowware.hibernatetest.model.beans.Session"
        table="SESSION"
    >

        <id
            name="sessionId"
            column="session_id"
            type="long"
        >
            <generator class="increment">     
            </generator>
        </id>

        <list
            name="attributes"
            table="SESSION_ATTRIBUTE"
            lazy="false"
            cascade="none"
        >

              <key
                  column="attribute_id"
              >
              </key>

              <index
                  column="position"
              />

              <composite-element
                  class="de.wowware.hibernatetest.model.beans.SessionAttribute"
              >
        <property
            name="name"
            type="java.lang.String"
            column="name"
        />

        <property
            name="value"
            type="java.lang.String"
            column="value"
        />
    </class>

</hibernate-mapping>


Name and version of the database you are using:
MySQL 4.0.15


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 28, 2005 7:58 am 
Beginner
Beginner

Joined: Fri Feb 11, 2005 12:03 pm
Posts: 48
Location: Kiel, Germany
I made it myself.

First there is a mistake in the mapping:
It must be
Code:
        <list
            name="attributes"
            table="SESSION_ATTRIBUTE"
            lazy="false"
            cascade="none"
        >

              <key
                  column="session_id"
              >
              </key>


The query is then simply:
Code:
from Session session
left join session.attributes attr
where attr.value like :attributeValue


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.