-->
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: How can I map a pseudo column value to an Object property?
PostPosted: Mon Apr 11, 2005 5:20 am 
Newbie

Joined: Mon Apr 11, 2005 4:53 am
Posts: 3
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0
Mapping documents:
Code:
<class
    name="domain.bo.Comment"
    table="guest_comment"
    dynamic-update="true"
    dynamic-insert="true"
>

    <id
        name="id"
        type="java.lang.Long"
        unsaved-value="null"
    >
        <column name="ID" sql-type="NUMBER" not-null="true"/>
        <generator class="sequence">
                <param name="sequence">guest_comment_id_seq</param>
        </generator>
    </id>

    <property
        name="parentId"
        type="java.lang.Long"
    >
        <column name="REF" sql-type="NUMBER" not-null="true"/>
    </property>

</class>



  <sql-query name="domain.bo.Comment.treeChildrenByRootId">
    <return alias="comment" class="domain.bo.Comment">
      <return-property name="id" column="id"/>
      <return-property name="parentId" column="parentId"/>
      <return-property name="hierarchicalLevel" column="hierarchicalLevel"/>
    </return>
select comment.ID AS id, comment.REF AS parentId, LEVEL AS hierarchicalLevel
from guest_comment comment
start with comment.ID= :rootId connect by comment.REF = prior comment.ID
  </sql-query>



Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:
oracle 817
The generated SQL (show_sql=true):

select comment.ID AS id, comment.REF AS parentId, LEVEL AS hierarchicalLevel from GUEST_COMMENT comment start with comment.ID= ? connect by comment.REF = prior comment.ID

Debug level Hibernate log excerpt:



When execute this named query, value of id/parentId can be stored into Comment's id/parentId property correctly. But hierarchicalLevel's value always equals zero. As I know currently, pseudo column -LEVEL can't mapped to PO's property. How can I get value of "LEVEL"? Thanks for any help!


Top
 Profile  
 
 Post subject: en.... I have solved it.
PostPosted: Mon Apr 11, 2005 11:34 pm 
Newbie

Joined: Mon Apr 11, 2005 4:53 am
Posts: 3
Add "return-scalar" to handle other properties which can't declare in mapping file, ie: pseudo column

Code:

  <sql-query name="domain.bo.Comment.treeChildrenByRootId">
    <return alias="comment" class="domain.bo.Comment">
      <return-property name="id" column="id"/>
      <return-property name="parentId" column="parentId"/>
      <return-property name="hierarchicalLevel" column="hierarchicalLevel"/>
    </return>
[b]    <return-scalar type="int" column="hierarchicalLevel"/>[/b]
select comment.ID AS id, comment.REF AS parentId, LEVEL AS hierarchicalLevel
from guest_comment comment
start with comment.ID= :rootId connect by comment.REF = prior comment.ID
  </sql-query>






Code:
        Object[] row = (Object[])i.next();
        Comment child = (Comment)row[1];
        child.setHierarchicalLevel(((Integer)row[0]).intValue());



I'm a newbie for hibernate, it is simple question.:)


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.