The following code creates a composite id class suitable to Andromda 2 and Hibernate. It is outdated, still using xDoclet, but I hope it helps.
CompositeIdClass.vsl #set($allIds = [])##lista com todas as chaves, pks dessa classe e de classes que vem de associações <<PrimaryKey>> #foreach($id in $class.identifiers) #set($dummy = $allIds.add($id) ) #end ## ###foreach ( $associationEnd in $class.associationEnds ) ###if($associationEnd.association.hasExactStereotype("PrimaryKey")) ###foreach($id in $associationEnd.otherEnd.type.identifiers) ####talvez tenha que mudar o nome, conforme nome da ponta da assoc. ###set($dummy = $allIds.add($id) ) ###end ###end ###end ## #if($allIds.size() > 1) package $class.packageName; public class ${class.name}_id implements java.io.Serializable{ public ${class.name}_id(){ } #set($args = "") #foreach($att in $allIds) #set($args = "${args},${att.type.fullyQualifiedName} ${att.name}") #end public ${class.name}_id($args.substring(1)){ #foreach($att in $allIds) this.${att.name} = $att.name; #end } #foreach($att in $allIds) #set($atttypename = $att.type.fullyQualifiedName) private $atttypename $att.name; /** * @hibernate.property * name="$att.name" ##me parece que o @hibernate.column não funciona direito aqui, então optei por usar ## o length ###set($theLength = $att.sqlType) ###set($posIni = $theLength.indexOf('(')) ###if($posIni > -1) ###set($posIni = $posIni + 1) ###set($posFim = $theLength.indexOf(')')) ###set($theLength = $theLength.substring($posIni,$posFim)) ## * length="$theLength" ###end * @hibernate.column * name="$att.name" * sql-type="$att.sqlType" **/ public $atttypename get${str.upperCaseFirstLetter(${att.name})}(){ return this.${att.name}; } public void set${str.upperCaseFirstLetter(${att.name})}(${atttypename} ${att.name}){ this.${att.name} = ${att.name}; } #end #set($eqValue = "") #foreach($att in $allIds) #set($eqValue = "$eqValue && ( this.${att.name} == ${att.name} || ((this.${att.name}!=null && ${att.name}!=null) && ( this.${att.name}.equals(((${class.name}_id)obj).get${str.upperCaseFirstLetter(${att.name})}()) )))") #end public boolean equals(Object obj){ return ${eqValue.substring(4)}; } public int hashCode(){ return ( #foreach($att in $allIds) this.${att.name}.toString() + #end "").hashCode(); } } #end _________________________________________________________ Reply to the post : http://galaxy.andromda.org/forum/viewtopic.php?p=2395#2395 Posting to http://forum.andromda.org/ is preferred over posting to the mailing list! ------------------------------------------------------- This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual core and dual graphics technology at this free one hour event hosted by HP, AMD, and NVIDIA. To register visit http://www.hp.com/go/dualwebinar _______________________________________________ Andromda-user mailing list Andromda-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/andromda-user