Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Hibernate 3 one-to-many relationship mapping

Reply
Thread Tools

Hibernate 3 one-to-many relationship mapping

 
 
Piotre Ugrumov
Guest
Posts: n/a
 
      06-16-2009
Hi,
I have this 2 tables:


TABLE TPS16_CONFIGURATION
( **TPS16_NAME**, TPS16_VALID_FROM_DATE, TPS16_OPERATING_RANGE_HI,
TPS16_OPERATING_RANGE_LO,
TPS16_MAX_OPERATING_DELTA, TPS16_TIME_GRID_PROTOTYPE)



TPS25_CURRENCIES_DIFFMIN
( **TPS16_ID, TPS25_ISO_CURRENCY**, TPS25_DIFF_MIN
)


I signed with * 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:

<?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.ECurrenciesDif fmin"/>
</set>

</class>
</hibernate-mapping>



The object ECurrenciesDiffmin maps the table TPS25_CURRENCIES_DIFFMIN
in this way:

<?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.ECurrenciesDiff min"
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:


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


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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hibernate @OneToMany relationship karol1208 Java 0 08-17-2008 10:37 PM
Many-to-many relationship with attributes in Hibernate Mirko Java 0 10-12-2006 04:02 PM
Hibernate Syncronizer now generates code for Hibernate 3.0 msenin@covad.net Java 0 07-14-2005 05:47 AM
Recursive Relationship with Hibernate? Aquila Deus Java 1 03-03-2005 04:20 AM
[HIBERNATE] [EVALUATION] - Gavin King Censors Hibernate Forum Ilias Lazaridis Java 0 12-27-2004 04:26 AM



Advertisments