-->
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: Hibernate with XDoclet composite key simple example...
PostPosted: Thu Oct 09, 2003 10:44 pm 
Newbie

Joined: Sun Aug 31, 2003 7:58 pm
Posts: 3
Reading the hibernate and xdoclet forums I can't seem to piece together a way of using hibernate composite keys using xdoclet.

For example, if I have a table that holds all the projects that an employee belongs to, with primary key columns empId, projId, with other non-key columns, projName, projLocation etc (I know this is not great but its just for the purposes of an example). I know that you'd have to build 2 classes, one for the composite primary key with getters setters for each column, a hashcode and toString, I dont know if you put xdoclet in this class. Then there is the "main" class that must "somehow" link to the composite class and have the usual property xdoclet for the non-key columns.

Heres a start if someone could fill in the blanks, I would be very grateful:


The composite key class:

package com.xxx;
/**
* @hibernate ???
*/
public class EmpProjPK implements java.io.Serializable
{
private int projId;
private int empId;

public EmpProjPK() {
}

/**
* @return int
* @hibernate ???
*/
public int getProjId() {
return projId;
}

public void setProjId(int projId) {
this.projId = projId;
}

/**
* @return int
* @hibernate ???
*/
public int getEmpId() {
return empId;
}

public void setEmpId(int empId) {
this.empId = empId;
}

public boolean equals(Object o) {
// Check equals ...
return true;
}

public int hashCode() {
int result = 17;
// Calc hash ...
return result;
}
}

The main class:

package com.xxx;

import java.util.*;
/**
*
* @hibernate.class
* table="emp_proj"
*/
public class EmpProj
implements java.io.Serializable
{
private String projName;
private EmpProjPK pk;

public EmpProj() {
pk = new EmpProjPK();
}

private int companyId;

public Compkeytest( int empId, int projId) {
pk.setEmpId(empId);
pk.setProjId(projId);
}

/**
*
* @hibernate.id
* generator-class="assigned" ???
*
* @return Compkeytest
*/
public EmpProjPK getEmpProjPK() {
return pk;
}


public void setEmpProjPK(EmpProjPK pk) {
this.pk = pk;
}

/**
* @return String
*
* @hibernate.property
* column="empName"
* not-null="false"
*/
public String getProjName() {
return this.projName;
}

/**
* @param description The empName to set
*/
public void setProjName(String projName) {
this.projName = projName;
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 10, 2003 4:57 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
No sure but I think this is a known limitation of the current HibernateDoclet. Gavin knows that.


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.