Hello,
I'm new with Hibernate. Thats why I have the following question:
Is it realy neccessary to have a key-class for an composit-key. If I don't take one, I get an Exception: Composite key has to be serializable. But my composite-key contains two Long and one String. That should be serializable.
What am I wrong?
Mapping and Class are appended.
Thanks.
bye bye
zone3
Hibernate version: 2.1.7
Name and version of the database you are using: Oracle 9i
Mapping documents:
<?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>
<class name="com.telekom.fast.data.mapping.UserRight" table="UD_TB_RIGHT" >
<composite-id> <!--rtUrLoginPkFk"--> <key-property name="login" column="RT_UR_LOGIN_PK_FK" type="java.lang.String" />
<!--SystemPriveledge"--> <key-property name="privilegId" column="RT_SP_ID_PK_FK" type="java.lang.Long" />
<!--DateFrom"--> <key-property name="number" column="RT_UT_NUMBER" type="java.lang.Long" />
</composite-id>
<!--Dateuntil"--> <property name="dateFrom" column="RT_DATE_FROM" type="java.lang.Long" length="10" />
<!--unitNumber"--> <property name="dateUntil" column="RT_DATE_UNTIL" type="java.lang.Long" length="10" />
<!-- Associations -->
<many-to-one name="user" class="com.telekom.fast.data.mapping.User" column="RT_UR_LOGIN_PK_FK" update="false" insert="false"> </many-to-one>
<many-to-one name="systemPrivileg" class="com.telekom.fast.data.mapping.SystemPrivileg" column="RT_SP_ID_PK_FK" update="false" insert="false"> </many-to-one>
<many-to-one name="unit" class="com.telekom.fast.data.mapping.Unit" column="RT_UT_NUMBER" update="false" insert="false"> </many-to-one>
<!-- end of associations -->
</class> </hibernate-mapping>
-------------------------------------------------------------------------------
public class UserRight {
private String login = null;
private Long privilegId = null;
private Long number = null;
private Long dateFrom = null;
private Long dateUntil = null;
private User user = null;
private Unit unit = null;
private SystemPrivileg systemPrivileg = null;
/** * default constructor */ public UserRight(){
}
/** * Constructs a new UserRight with only mandatory (non-nullable) parameters * @param user the udTbUser value * @param unit the adTbFormhUt value * @param systemPrivileg the udTbSystemPrivileg value */ public UserRight(User user, Unit unit, SystemPrivileg systemPrivileg) { setUser(user); setUnit(unit); setSystemPrivileg(systemPrivileg); }
/** * Returns the related UdTbUser * * @return the related UdTbUser */ public User getUser() { return user; }
/** * Sets the related UdTbUser * * @param user the related udTbUser */ public void setUser(User user) { this.user = user; }
public Unit getUnit() { return unit; }
public void setUnit(Unit unit) { this.unit = unit; }
/** * Returns the related SystemPrivileg * * @return the related SystemPrivileg */ public SystemPrivileg getSystemPriveleg() { return systemPrivileg; }
/** * Sets the related SystemPriveleg * * @param systemPrivileg the related udTbSystemPrivileg */ public void setSystemPrivileg(SystemPrivileg systemPrivileg) { this.systemPrivileg = systemPrivileg; }
public String getLogin() { return login; }
public void setLogin(String login) { this.login = login; }
public Long getPrivilegId() { return privilegId; }
public void setPrivilegId(Long privilegId) { this.privilegId = privilegId; }
public Long getNumber() { return number; }
public void setNumber(Long number) { this.number = number; }
public Long getDateFrom() { return dateFrom; }
public void setDateFrom(Long dateFrom) { this.dateFrom = dateFrom; }
public Long getDateUntil() { return dateUntil; }
public void setDateUntil(Long dateUntil) { this.dateUntil = dateUntil; }
public boolean equals(Object o) { if (this == o) return true; if (!(o instanceof UserRight)) return false;
final UserRight userRight = (UserRight) o;
if (!login.equals(userRight.login)) return false; if (!number.equals(userRight.number)) return false; if (!privilegId.equals(userRight.privilegId)) return false;
return true; }
public int hashCode() { int result; result = login.hashCode(); result = 29 * result + privilegId.hashCode(); result = 29 * result + number.hashCode(); return result; } }
|