-->
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.  [ 9 posts ] 
Author Message
 Post subject: one-to-one property help!!
PostPosted: Thu Jul 21, 2005 9:06 am 
Newbie

Joined: Tue Jun 14, 2005 12:44 pm
Posts: 19
HI there,

What am I doing wrong?

I have a Message object and a Session object. Each message has one session. Each session may have one or more messages.

The two objects are not connected in the mapping, both have sessionId keys which can be used to join the two.

My only request: I would like to have a Session property in my Message POJO.

How do I map this out in a hiberante mapping HBM file?

This is what I tried so far - it returns a null for each Session:

Code:
<class name="GXMessageDisplayDBObject" table="Messages" lazy="false">
   <id name="messageId">
        <column name="MessageId" length="36"/>
   </id>
<property name="SessionId" length="36" column="SESSION_ID"/>
[b]<one-to-one name="session" class="GXSessionDisplayDBObject"   outer-join="auto"/> [/b]
      <property name="Direction"/>
</class>


My Message POJO class has a getter/setter for my session object.

PS> I do not have a many-to-one relationship mapped in my Session XML file - is this necessary?

Thanks in advance
Eyal


Top
 Profile  
 
 Post subject: Re: one-to-one property help!!
PostPosted: Thu Jul 21, 2005 9:25 am 
Beginner
Beginner

Joined: Fri Feb 11, 2005 12:03 pm
Posts: 48
Location: Kiel, Germany
eyalg wrote:
I have a Message object and a Session object. Each message has one session. Each session may have one or more messages.

From the Message point of view this is a many-to-one association then. Please try this.

eyalg wrote:
PS> I do not have a many-to-one relationship mapped in my Session XML file - is this necessary?


As far as I know not.


Top
 Profile  
 
 Post subject: works
PostPosted: Thu Jul 21, 2005 10:59 am 
Newbie

Joined: Tue Jun 14, 2005 12:44 pm
Posts: 19
Thanks! You are correct - that is the mapping i needed.
It works now!


Top
 Profile  
 
 Post subject: another question
PostPosted: Mon Jul 25, 2005 5:07 am 
Newbie

Joined: Tue Jun 14, 2005 12:44 pm
Posts: 19
Now that I have the Session mapped, I would like to access its attributes via HQL - that is, run a LIKE query on its attributes named "ClientName"

When I try to access the session property (which is mapped via a foreign key) through HQL, I receive an error:

Code:
org.hibernate.hql.ast.QuerySyntaxError: Invalid path: 'message.session' [select message.session from  MessageDisplayDBObject


Any suggestions?[/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 5:20 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Show your query as well as your POJO.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 25, 2005 5:20 am 
Beginner
Beginner

Joined: Fri Feb 11, 2005 12:03 pm
Posts: 48
Location: Kiel, Germany
Is this the complete text of the query you are trying:
Code:
select message.session from  MessageDisplayDBObject


In this case you are missing something, I think. Try this:

Code:
select message.session from  MessageDisplayDBObject message


Top
 Profile  
 
 Post subject: yes but
PostPosted: Mon Jul 25, 2005 5:54 am 
Newbie

Joined: Tue Jun 14, 2005 12:44 pm
Posts: 19
You are correct, I just noticed my mistake.
However when I run the query "select message.session.attributes.AttributeName from Messages"

I receive this error:
org.hibernate.exception.GenericJDBCException: could not execute query

This is the SQL :
select attributes2_.AttributeName as col_0_0_ from Messages gxmessaged0_ SessionAttributes attributes2_ where (gxmessaged0_.SessionId=gxsessiond1_.SessionId and gxsessiond1_.SessionId=attributes2_.SessionId)

For some apparent reason, the join in the query is not functioning well. Retrieving the Session object works now however.
I cannot retrieve the attributes by themselves as well(message.session.attributes).

Thanks


Top
 Profile  
 
 Post subject: more clarification
PostPosted: Mon Jul 25, 2005 6:53 am 
Newbie

Joined: Tue Jun 14, 2005 12:44 pm
Posts: 19
The session HBM:

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

   <class name="Session" table="Sessions" lazy="false">
      <id name="sessionId">
         <column name="SessionId" length="36"/>
      </id>
          <list fetch="join" name="attributes" table="SessionAttributes" lazy="false">
           <key not-null="true">
            <column name="SessionId" length="36"/>
         </key>
         <list-index column="AttributeIndex" />
          <composite-element class="com.intellinx.channels.internal.SessionAttribute">
              <property name="AttributeName"/>
              <property name="AttributeValue"/>
          </composite-element>
       </list>
      
      
   </class>

</hibernate-mapping>


Code:
The Session Attribute class:
public class  SessionAttribute {
   private String m_attributeName;
   private String m_attributeValue;

//getters and setters
}


The Session class (bean) contains:
Code:
public class GXSessionDisplayDBObject implements Serializable{
//all members..
private List<SessionAttribute> m_attributes;
//getters and setters


Thanks


Top
 Profile  
 
 Post subject: Re: yes but
PostPosted: Thu Jul 28, 2005 8:19 am 
Beginner
Beginner

Joined: Fri Feb 11, 2005 12:03 pm
Posts: 48
Location: Kiel, Germany
Hi Eyal,

I have no a similar working example for this query

eyalg wrote:
You are correct, I just noticed my mistake.
However when I run the query "select message.session.attributes.AttributeName from Messages"

I receive this error:
org.hibernate.exception.GenericJDBCException: could not execute query


In my example I have just a Session and SessionAttribute objects and the query is
Code:
select attr.value from Session session left join session.attributes attr


For your example it should be something like
Code:
select attr.AttributeName from Messages message left join message.session.attributes attr


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