-->
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
PostPosted: Tue Feb 15, 2005 5:42 am 
Newbie

Joined: Tue Feb 15, 2005 5:26 am
Posts: 1
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;
}
}





Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 15, 2005 6:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
UserRight has to be serializable, it is its own PK class

_________________
Emmanuel


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.