-->
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: Mapping a property to FIELD1/FIELD2
PostPosted: Fri Jun 11, 2010 6:00 am 
Newbie

Joined: Fri Jun 11, 2010 5:29 am
Posts: 1
Good morning my 5 reader :) , I'm sorry if this is a question already asked, but I still cant find a solution:

I have an object mapped like this:

Code:
<hibernate-mapping>
    <class name="SipCall" table="RAW_SIP" schema="VOIP">
        <id name="id" type="big_decimal">
            <column name="ID" precision="20" scale="0"/>
            <generator class="assigned" />
        </id>
        <property name="idGroup" type="int">
            <column name="ID_GROUP" precision="9" scale="0" />
        </property>

       ...

        [cut]... many properties follows [/cut]

      ...

        <property name="rtpCalledPacketExpected" type="long">
            <column name="RTP_CALLED_PACKET_EXPECTED" precision="10" scale="0" />
        </property>
        <property name="rtpCalledPacketLost" type="long">
            <column name="RTP_CALLED_PACKET_LOST" precision="10" scale="0" />
        </property>

...
etc...


My object is quite big, having 192 properties and at this moment the readers left are probably fallen down to 3 :)
When I do createQuery(SipCall.class), I add Restrictions dinamically, based on user chooice, so, for example, user choose "RTP CALLED PACKET LOST" in the web form and I can dinamically append ".add(Restrictions.eq("rtpCalledPacketLost",userInputValue))" to my query, this way all is dynamic and I can avoid having 192 "if then" in the code

So all of this sounds normal, but what if I need to add a restriction on an arithmetic calculations like, for example:

percent of packet lost = rtpCalledPacketLost/rtpCalledPacketExpected

I thought I could add a property like
Code:
        <property name="rtpPercentPacketLost" type="long">
            <column name="RTP_CALLED_PACKET_LOST/RTP_CALLED_PACKET_EXPECTED" precision="10" scale="0" />
        </property>


but, of course, it doesnt work, so, my dear only one left reader :) finally my question is:

can I map a property to do some math on sql columns ??

thanks in advance


Top
 Profile  
 
 Post subject: Re: Mapping a property to FIELD1/FIELD2
PostPosted: Fri Jun 11, 2010 7:59 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
Yes. Use a formula attribute or element as explained here: http://docs.jboss.org/hibernate/stable/ ... ing-column


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.