-->
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: Map a value from a Configuration table to other tables
PostPosted: Wed Jun 29, 2005 7:22 pm 
Beginner
Beginner

Joined: Thu May 05, 2005 11:12 pm
Posts: 26
I have a class called OutputClass that contains among other things a budget of type Money. This Money is an amount and a currency code. This scenario occurs in several tables in our system. An object contains a monetary value of a certain currency. It is assumed in our application that the currency code is the application default currency code. This code is defined in an ApplicationConfiguration table. This table is basically a key (1, 2,3, 4...) and a String value. The default currency code is key number 4.

I want to map this default currency code into the currency code part of the Money that represents the budget. I can't work out how to make that mapping work. A <one-to-one> seems right, but it isn't clear to me how to define it. My initial attempt is below but it just doesn't look right. It doesn't define which table to go to, and I don't want to return a class, just the one property from it.

Hibernate version:
3.0

Mapping documents:
OutputClass:
<hibernate-mapping package="com.ilign.ppm.domain">
<class name="OutputClass" table="OUTPUT_CLASS" lazy="true">
<id name="objectId" column="OUTPUT_CLASS_ID" type="long">
<generator class="hilo">
<param name="table">OBJECT_ID</param>
<param name="column">next_value</param>
<param name="max_lo">100</param>
</generator>
</id>
<version name="vsn" column="VSN" type="integer"/>
<property name="name" column="NAME" type="string" not-null="true"/>
<property name="description" column="DESCRIPTION" type="string" not-null="true" />
<property name="startDate" column="START_DATE" type="com.ilign.ppm.common.PersistentDateTime" not-null="true" />
<property name="endDate" column="END_DATE" type="com.ilign.ppm.common.PersistentDateTime" not-null="true" />
<component name="budget" class="com.ilign.ppm.common.Money" >
<property name="amount" column="BUDGET" type="big_decimal" not-null="true"/>
<one-to-one name="currencyCode" entity-name="ConfigurationSetting" cascade="none">
<formula>'4'</formula>
</one-to-one>
</component>
</class>
</hibernate-mapping>

ApplicationConfiguration
<hibernate-mapping package="com.ilign.ppm.domain">
<class name="ConfigurationSetting" table="APPLICATION_CONFIG" lazy="true">
<id name="objectId" column="CONFIG_ID" type="long">
<generator class="hilo">
<param name="table">OBJECT_ID</param>
<param name="column">next_value</param>
<param name="max_lo">100</param>
</generator>
</id>
<version name="vsn" column="VSN" type="integer"/>
<property name="configValue" column="CONFIG_VALUE" type="string"/>
</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
Not there yet

Full stack trace of any exception that occurs:
Not there yet

Name and version of the database you are using:
Firebird 1.5.2

The generated SQL (show_sql=true):
Not there yet

Debug level Hibernate log excerpt:
Not there yet


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 30, 2005 10:42 pm 
Beginner
Beginner

Joined: Thu May 05, 2005 11:12 pm
Posts: 26
Solved...

Ended up using a formula which feels a bit hokey but seems to be the only way.

Code:
<hibernate-mapping package="com.ilign.ppm.domain">
  <class name="OutputClass" table="OUTPUT_CLASS" lazy="true">
      <id name="objectId" column="OUTPUT_CLASS_ID" type="long">
          <generator class="hilo">
              <param name="table">OBJECT_ID</param>
              <param name="column">next_value</param>
              <param name="max_lo">100</param>
          </generator>
      </id>
      <version name="vsn" column="VSN" type="integer"/>
      <property name="name" column="NAME" type="string" not-null="true"/>
      <property name="description" column="DESCRIPTION" type="string" not-null="true" />
      <property name="startDate" column="START_DATE" type="com.ilign.ppm.common.PersistentDateTime" not-null="true" />
      <property name="endDate" column="END_DATE" type="com.ilign.ppm.common.PersistentDateTime" not-null="true" />
      <component name="budget" class="com.ilign.ppm.common.ForeignCurrency" >
          <component name="baseMoney" class="com.ilign.ppm.common.Money" >
              <property name="amount" column="BUDGET" type="big_decimal" not-null="true"/>
              <property name="currencyCode" update="false" insert="false">
                <formula>
                    ( Select ac.config_value from application_config ac where ac.config_id = '17' )
                </formula>
              </property>
          </component>
          <component name="srcMoney" class="com.ilign.ppm.common.Money" >
              <property name="amount" column="SRC_BUDGET" type="big_decimal" />
              <property name="currencyCode" column="SRC_BUDGET_CURR_CODE" type="string" />
          </component>
      </component>
  </class>
</hibernate-mapping>


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.