-->
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: Hibernate 3 one-to-many relationship
PostPosted: Tue Jun 16, 2009 3:45 am 
Newbie

Joined: Sun Apr 05, 2009 6:56 am
Posts: 5
Hi,
I have these 2 tables:

Code:
TABLE TPS16_CONFIGURATION
( [u]TPS16_NAME[/u], TPS16_VALID_FROM_DATE, TPS16_OPERATING_RANGE_HI, TPS16_OPERATING_RANGE_LO,
TPS16_MAX_OPERATING_DELTA, TPS16_TIME_GRID_PROTOTYPE)


Code:
TPS25_CURRENCIES_DIFFMIN
( [u]TPS16_ID, TPS25_ISO_CURRENCY,[/u] TPS25_DIFF_MIN
)


I underlined the keys of the tables.
There is a foreign key in the table TPS25_CURRENCIES_DIFFMIN in fact TPS16_ID refers to TPS16_CONFIGURATION(TPS16_NAME).

Now I have a problem of mapping.
The object EConfiguration maps the table TPS16_CONFIGURATION in this way:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
   <class name="com.intesasanpaolo.tps.model.EConfiguration"
      table="TPS16_CONFIGURATION" catalog="@CATALOG@" mutable="true">
      <comment></comment>
      <id name="name" type="string" column="TPS16_NAME"
         access="field">
      </id>

      <property name="validFrom" type="java.util.Date">
         <column name="TPS16_VALID_FROM_DATE" not-null="false" />
      </property>

      <property name="operatingRangeHigh" type="java.math.BigDecimal">
         <column name="TPS16_OPERATING_RANGE_HI" not-null="false" />
      </property>

      <property name="operatingRangeLow" type="java.math.BigDecimal">
         <column name="TPS16_OPERATING_RANGE_LO" not-null="false" />
      </property>

      <property name="maxOperatingDelta" type="java.math.BigDecimal">
         <column name="TPS16_MAX_OPERATING_DELTA" not-null="false" />
      </property>

      <many-to-one name="timeGridPrototype" column="TPS16_TIME_GRID_PROTOTYPE"
         unique="false" not-null="false" fetch="join" cascade="all">
      </many-to-one>
      
        <list name="internalPortfolios" cascade="all" table="TPS17_INTERNAL_PORTFOLIO"  catalog="@CATALOG@" lazy="false">
            <key column="TPS16_ID"/>
            <index column="TPS16_IDX"/>
            <element column="TPS17_NAME" type="string"/>
        </list>

        <list name="externalPortfolios" cascade="all" table="TPS18_EXTERNAL_PORTFOLIO"  catalog="@CATALOG@" lazy="false">
            <key column="TPS16_ID"/>
             <index column="TPS16_IDX"/>
            <element column="TPS18_NAME" type="string"/>
        </list>
       
        <list name="internalCounterparts" cascade="all" table="TPS19_INTERNAL_COUNTERPART" catalog="@CATALOG@" lazy="false">
            <key column="TPS16_ID"/>
            <index column="TPS16_IDX"/>
            <element column="TPS19_NAME" type="string"/>
        </list>

        <list name="externalCounterparts" cascade="all" table="TPS20_EXTERNAL_COUNTERPART" catalog="@CATALOG@" lazy="false">
            <key column="TPS16_ID"/>
             <index column="TPS16_IDX"/>
            <element column="TPS20_NAME" type="string"/>
        </list>
       
        <set name="currenciesDiffMin" lazy="true" inverse="true" cascade="all-delete-orphan">
           <key column="TPS16_ID"/>
           <one-to-many class="com.intesasanpaolo.tps.model.ECurrenciesDiffmin"/>
        </set>
       
   </class>
</hibernate-mapping>



The object ECurrenciesDiffmin maps the table TPS25_CURRENCIES_DIFFMIN in this way:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="com.intesasanpaolo.tps.model.ECurrenciesDiffmin"
      table="TPS25_CURRENCIES_DIFFMIN" catalog="@CATALOG@" mutable="true">
      <comment>Oggetto hibernate che mappa la tabella TPS25_CURRENCIES_DIFFMIN</comment>
      
      <composite-id>
         <key-many-to-one name="configuration" column="TPS16_NAME" ></key-many-to-one>
          <key-property name="currency" type="string">
             <column name="TPS25_ISO_CURRENCY"></column>
          </key-property>
      </composite-id>
      
      <property name="diffMin" type="double">
         <column name="TPS25_DIFF_MIN" not-null="false" />
      </property>
      
</class>      
</hibernate-mapping>


So I have the classes that maps the table in this way:

Code:
public class EConfiguration {
   protected String name;
   private Date validFrom;
   private ETimeGridConfiguration timeGridPrototype;
   private List externalPortfolios;
   private List internalPortfolios;
   private List externalCounterparts;
   private List internalCounterparts;
   private BigDecimal operatingRangeHigh;
   private BigDecimal operatingRangeLow;
   private BigDecimal maxOperatingDelta;
   private Set currenciesDiffMin;
   
   
   public Set getCurrenciesDiffMin() {
      return currenciesDiffMin;
   }
   public void setCurrenciesDiffMin(Set currenciesDiffMin) {
      this.currenciesDiffMin = currenciesDiffMin;
   }
   protected EConfiguration() {}
   public EConfiguration(String name) {
      this.name = name;
   }
   /**
    * Configuration name
    * @return The name of the configuration
    */
   public String getName() {
      return name;
   }
   /**
    * Validity date
    * @return The first date for which this configuration is valid
    */
   public Date getValidFrom() {
      return validFrom;
   }
   public void setValidFrom(Date validFrom) {
      this.validFrom = validFrom;
   }
   /**
    * Time grid prototype
    * @return A {@link ETimeGridConfiguration} object
    */
   public ETimeGridConfiguration getTimeGridPrototype() {
      return timeGridPrototype;
   }
   public void setTimeGridPrototype(ETimeGridConfiguration timeGridPrototype) {
      this.timeGridPrototype = timeGridPrototype;
   }
   /**
    * External deal portfolios that must be used for this hedging process
    * @return A List of String representing the names of the portfolios
    */
   public List getExternalPortfolios() {
      return externalPortfolios;
   }
   public void setExternalPortfolios(List externalPortfolios) {
      this.externalPortfolios = externalPortfolios;
   }
   /**
    * Internal deal portfolios that must be hedged by this hedging process
    * @return A List of String representing the names of the portfolios
    */
   public List getInternalPortfolios() {
      return internalPortfolios;
   }
   public void setInternalPortfolios(List internalPortfolios) {
      this.internalPortfolios = internalPortfolios;
   }
   /**
    * External deal counterparts that must be used for this hedging process
    * @return A List of String representing the names of the counterparts
    */
   public List getExternalCounterparts() {
      return externalCounterparts;
   }
   public void setExternalCounterparts(List externalCounterparts) {
      this.externalCounterparts = externalCounterparts;
   }
   /**
    * Internal deal counterparts that must be hedged by this hedging process
    * @return A List of String representing the names of the counterparts
    */
   public List getInternalCounterparts() {
      return internalCounterparts;
   }
   public void setInternalCounterparts(List internalCounterparts) {
      this.internalCounterparts = internalCounterparts;
   }
   /**
    * High limit of hedging ratio
    * @return A BigDecimal representing a hedge/risk ratio
    */
   public BigDecimal getOperatingRangeHigh() {
      return operatingRangeHigh;
   }
   public void setOperatingRangeHigh(BigDecimal operatingRangeHigh) {
      this.operatingRangeHigh = operatingRangeHigh;
   }
   /**
    * Low limit of hedging ratio
    * @return A BigDecimal representing a hedge/risk ratio
    */
   public BigDecimal getOperatingRangeLow() {
      return operatingRangeLow;
   }
   public void setOperatingRangeLow(BigDecimal operatingRangeLow) {
      this.operatingRangeLow = operatingRangeLow;
   }
   /**
    * Absolute value of the maximum risk amount that can exceed hedging for every time bucket
    * @return A BigDecimal representing an amount
    */
   public BigDecimal getMaxOperatingDelta() {
      return maxOperatingDelta;
   }
   public void setMaxOperatingDelta(BigDecimal maxOperatingDelta) {
      this.maxOperatingDelta = maxOperatingDelta;
   }
   public void setName(String name) {
      this.name = name;
   }
}




and


Code:
public class ECurrenciesDiffmin {
   
   private EConfiguration configuration;
   private String currency;
   private double diffMin;
   
   public ECurrenciesDiffmin() {
      super();
   }
   
   public ECurrenciesDiffmin(EConfiguration configuration, String currency, double diffMin) {
      super();
      this.configuration = configuration;
      this.currency = currency;
      this.diffMin = diffMin;
   }
   public EConfiguration getConfiguration() {
      return configuration;
   }
   public void setConfiguration(EConfiguration configuration) {
      this.configuration = configuration;
   }
   public String getCurrency() {
      return currency;
   }
   public void setCurrency(String currency) {
      this.currency = currency;
   }
   public double getDiffMin() {
      return diffMin;
   }
   public void setDiffMin(double diffMin) {
      this.diffMin = diffMin;
   }

}


This mapping does not work and I do not understand why, can someone help me?
Where do I make a mistake?
How can I solve?
Thanks, bye bye.


Last edited by abdujaparov on Wed Jun 17, 2009 6:12 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Hibernate 3 one-to-many relationship
PostPosted: Wed Jun 17, 2009 6:12 am 
Newbie

Joined: Sun Apr 05, 2009 6:56 am
Posts: 5
Could someone help me? This problem crashes my application and I don't know hot I can solve.
Thanks, bye bye.


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.