I used Hibernate 2.1.1 and Middlegen R3.
----------------
Mapping file
----------------
OpTurno
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="pt.vo.OpTurno"
table="op_turnos"
>
<composite-id name="comp_id" class="pt.vo.OpTurnoPK">
<key-property
name="dataTurno"
column="data_turno"
type="long"
length="8"
/>
<!-- bi-directional many-to-one association to Turno -->
<key-many-to-one
name="turno"
class="pt.vo.Turno"
>
<column name="turno_fk" />
</key-many-to-one>
<!-- bi-directional many-to-one association to Op -->
<key-many-to-one
name="op"
class="pt.vo.Op"
>
<column name="op_fk" />
</key-many-to-one>
</composite-id>
<property
name="userId"
type="java.lang.String"
column="user_id"
not-null="true"
length="10"
/>
<property
name="dtHr"
type="java.sql.Timestamp"
column="dt_hr"
not-null="true"
length="8"
/>
<!-- associations -->
<!-- bi-directional one-to-one association to ControloVolante -->
<!-- constrained="true" -->
<one-to-one
name="controloVolante"
class="pt.vo.ControloVolante"
outer-join="auto"
constrained="false"
/>
</class>
</hibernate-mapping>
---------------------------------------------
POJO's (generated with Middlegen R3)
---------------------------------------------
OpTurno.java
package pt.vo;
import java.io.Serializable;
import java.util.Date;
import java.util.Set;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
/** @author Hibernate CodeGenerator */
public class OpTurno implements Serializable {
/** identifier field */
private pt.vo.OpTurnoPK comp_id;
/** persistent field */
private String userId;
/** persistent field */
private Date dtHr;
/** nullable persistent field */
private pt.vo.ControloVolante controloVolante;
/** full constructor */
public OpTurno(pt.vo.OpTurnoPK comp_id, String userId, Date dtHr, pt.vo.ControloVolante controloVolante) {
this.comp_id = comp_id;
this.userId = userId;
this.dtHr = dtHr;
this.controloVolante = controloVolante;
}
/** default constructor */
public OpTurno() {
}
/** minimal constructor */
public OpTurno(pt.vo.OpTurnoPK comp_id, String userId, Date dtHr) {
this.comp_id = comp_id;
this.userId = userId;
this.dtHr = dtHr;
}
public pt.vo.OpTurnoPK getComp_id() {
return this.comp_id;
}
public void setComp_id(pt.vo.OpTurnoPK comp_id) {
this.comp_id = comp_id;
}
public String getUserId() {
return this.userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public Date getDtHr() {
return this.dtHr;
}
public void setDtHr(Date dtHr) {
this.dtHr = dtHr;
}
public pt.vo.ControloVolante getControloVolante() {
return this.controloVolante;
}
public void setControloVolante(pt.vo.ControloVolante controloVolante) {
this.controloVolante = controloVolante;
}
public String toString() {
return new ToStringBuilder(this)
.append("comp_id", getComp_id())
.toString();
}
public boolean equals(Object other) {
if ( !(other instanceof OpTurno) ) return false;
OpTurno castOther = (OpTurno) other;
return new EqualsBuilder()
.append(this.getComp_id(), castOther.getComp_id())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getComp_id())
.toHashCode();
}
}
OpTurnoPK.java
package pt.vo;
import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
/** @author Hibernate CodeGenerator */
public class OpTurnoPK implements Serializable {
/** identifier field */
private long dataTurno;
/** identifier field */
private pt.vo.Turno turno;
/** identifier field */
private pt.vo.Op op;
/** full constructor */
public OpTurnoPK(long dataTurno, pt.vo.Turno turno, pt.vo.Op op) {
this.dataTurno = dataTurno;
this.turno = turno;
this.op = op;
}
/** default constructor */
public OpTurnoPK() {
}
public long getDataTurno() {
return this.dataTurno;
}
public void setDataTurno(long dataTurno) {
this.dataTurno = dataTurno;
}
public pt.vo.Turno getTurno() {
return this.turno;
}
public void setTurno(pt.vo.Turno turno) {
this.turno = turno;
}
public pt.vo.Op getOp() {
return this.op;
}
public void setOp(pt.vo.Op op) {
this.op = op;
}
public String toString() {
return new ToStringBuilder(this)
.append("dataTurno", getDataTurno())
.append("turno", getTurno())
.append("op", getOp())
.toString();
}
public boolean equals(Object other) {
if ( !(other instanceof OpTurnoPK) ) return false;
OpTurnoPK castOther = (OpTurnoPK) other;
return new EqualsBuilder()
.append(this.getDataTurno(), castOther.getDataTurno())
.append(this.getTurno(), castOther.getTurno())
.append(this.getOp(), castOther.getOp())
.isEquals();
}
public int hashCode() {
return new HashCodeBuilder()
.append(getDataTurno())
.append(getTurno())
.append(getOp())
.toHashCode();
}
}
When I try to execute the following lines of code:
---------------------------------
( ... "data_turno" and "turno_id" are already instantiated ... )
OpTurnoPK op_turno_pk = new OpTurnoPK();
op_turno_pk.setDataTurno(data_turno);
Op op = new Op();
op.setId(new Long(1));
op_turno_pk.setOp(op);
Turno turno = new Turno();
turno.setId(new Short(turno_id));
op_turno_pk.setTurno(turno);
OpTurno op_turno = new OpTurno();
op_turno.setComp_id(op_turno_pk);
op_turno.setUserId(user_id);
op_turno.setDtHr(dt_hr);
if((OpTurno)session.get(OpTurno.class, op_turno) == null) {
System.out.println("IT IS NULL");
}
---------------------------------
it gives me the following error:
net.sf.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) getter of pt.comseal.arsol.vo.OpTurnoPK.?
and when I use "hibernate.cglib.use_reflection_optimizer=false" it shows:
net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of pt.comseal.arsol.vo.OpTurnoPK.dataTurno
I can't see any problem in the mapping file or in the POJO's!?
Please help.