-->
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: Composite-key & a newbie
PostPosted: Tue Oct 24, 2006 6:39 am 
Newbie

Joined: Tue Oct 24, 2006 6:04 am
Posts: 3
Location: Italy
Hi to all, I'm a totally newbie to Hibernate and I have a problem! I'm trying to use this mapping:

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping package="ParamLoader.model.adeguamento">

<class name="Adeguamento" table="WH_ADEGUAMENTI_FONDO"
dynamic-update="true" dynamic-insert="true">
<composite-id name="id" class="ParamLoader.model.adeguamento.AdeguamentoPK">
<key-property name="cod_anno_rif" column="COD_ANN_RIF" type="java.lang.Integer"/>
<key-property name="cod_marca_comm" column="COD_MARCA_COMM" type="java.lang.String" length="2"/>
<key-property name="cod_mkt_vend" column="COD_MKT_VEND" type="java.lang.String" length="4"/>
<key-property name="cod_fmta" column="COD_FMTA" type="java.lang.String" length="5"/>
<key-property name="cod_contratto" column="CODICE_CONTRATTO" type="java.lang.String" length="4"/>
</composite-id>
<property name="adeguamento" column="ADEGUAMENTO" type="java.lang.Double"></property>
</class>

In order to use it I have created 2 classes:

1-- First the AdeguamentoPK.java one:

public class AdeguamentoPK implements Serializable {

private String cod_marca_comm ;
private String cod_mkt_vend ;
private String cod_fmta ;
private String cod_contratto ;
private int cod_anno_rif ;

public AdeguamentoPK()
{ }

public int getCod_anno_rif()
{ return cod_anno_rif; }

public void setCod_anno_rif(int n)
{ this.cod_anno_rif = n; }

public String getCod_marca_comm()
{ return cod_marca_comm; }

public void setCod_marca_comm(String cod)
{ this.cod_marca_comm = cod; }

public String getCod_mkt_vend()
{ return cod_mkt_vend; }

public void setCod_mkt_vend(String cod)
{ this.cod_mkt_vend = cod; }

public String getCod_fmta()
{ return cod_fmta; }

public void setCod_fmta(String cod)
{ this.cod_fmta = cod; }

public String getCod_contratto()
{ return cod_contratto; }

public void setCod_contratto(String cod)
{ this.cod_contratto = cod; }

public boolean equals(Object other)
{ equals method..... }

public int hashCode()
{ hash method....}
}

2 -- then Adeguamento.java:

public class Adeguamento extends EntityObject implements Serializable
{
private AdeguamentoPK id;
private double adeguamento;

public Adeguamento()
{ }

public void setId(String cod_marca_comm ,
String cod_mkt_vend,
String cod_fmta,
String cod_contratto,
int cod_anno_rif)
{ this.id.setCod_anno_rif(cod_anno_rif);
this.id.setCod_marca_comm(cod_marca_comm);
this.id.setCod_mkt_vend(cod_mkt_vend);
this.id.setCod_fmta(cod_fmta);
this.id.setCod_contratto(cod_contratto);
}

public AdeguamentoPK getId()
{ return id; }

public void setAdeguamento(double n)
{ this.adeguamento = n; }

public double getAdeguamento()
{ return this.adeguamento; }

public boolean equals(Object other)
{ equals method..... }

public int hashCode()
{ hash method....}
}

Then I try to use it in a class, this way:
...............
sessionFactory = new Configuration() .configure(conf.getProperty(PARAM_HIBERNATE_CONFIG_FILE))
.buildSessionFactory();

Adeguamento adeguamenti= null;
adeguamenti.setId(cod_marca_comm,cod_mkt_vend,cod_fmta,cod_contratto,cod_anno_rif);
adeguamenti.setAdeguamento(adeguamento);

Resources.beginTransaction();
getSession().saveOrUpdate(entity);
Resources.commitTransaction();


The execution gives me an error like this:
"org.hibernate.PropertyNotFoundException Could not find a setter for property id in class ParamLoader.model.adeguamento.Adeguamento" ... But it seems to me that I have this setter!!! Could someone help me?
Please in advance! Paolo


Top
 Profile  
 
 Post subject: Re: Composite key & newbie
PostPosted: Fri Oct 27, 2006 9:46 am 
Newbie

Joined: Mon Nov 14, 2005 1:19 pm
Posts: 3
I think in your main class (Adeguamento?), you need a method setId() with a parameter of your Primary Key class...so something like

setId(AdeguamentoPK pk) {this.id = pk;}


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.