[jboss-user] [EJB 3.0] - Re: help composite keys

sashaxiv do-not-reply at jboss.com
Fri May 4 10:35:40 EDT 2007


finally i solved my problem!! this is what i do 


@Entity
@Table(name="rutapuerto")
public class RutaPuerto{
	
	private RutaPuertoPK pk;
	private Puerto puerto;
	private Ruta ruta;
	private Double kilometros;
	
	public RutaPuerto() {}
	
	public RutaPuerto(RutaPuertoPK pk, Puerto puerto, Ruta ruta, Double kilometros) {
		super();
		this.pk = pk;
		this.puerto = puerto;
		this.ruta = ruta;
		this.kilometros = kilometros;
	}



	@EmbeddedId
	public RutaPuertoPK getPk() {
		return pk;
	}

	public void setPk(RutaPuertoPK pk) {
		this.pk = pk;
	}

	@Column(name="kilometros")
	public Double getKilometros() {
		return kilometros;
	}

	public void setKilometros(Double kilometros) {
		this.kilometros = kilometros;
	}

	@ManyToOne
	@JoinColumn(name="idPuerto", updatable=false, insertable=false)
	public Puerto getPuerto() {
		return puerto;
	}

	public void setPuerto(Puerto puerto) {
		this.puerto = puerto;
	}

	@ManyToOne
	@JoinColumn(name="idRuta", updatable=false, insertable=false)
	public Ruta getRuta() {
		return ruta;
	}

	public void setRuta(Ruta ruta) {
		this.ruta = ruta;
	}
	
	
}


------------------------------------------------------------

@Entity
@Table(name="puerto")
public class Puerto {

  .......

@OneToMany(mappedBy="puerto",cascade=CascadeType.REMOVE)
	public List getRutaPuertos() {
		return rutaPuertos;
	}
----------------------------------------------------------


@Entity
@Table(name="ruta")
public class Ruta{
	
	public Ruta() {}

@OneToMany(mappedBy="ruta", cascade=CascadeType.REMOVE)
	public List getPuertos() {
		return rutapuertos;
	}

----------------------------------------------------------------------


@Embeddable
public class RutaPuertoPK implements Serializable{

	private Long idRuta;
	private Long idPuerto;
	
	public RutaPuertoPK() {}

  ..........................
--------------------------------------------
Anyway very much thanks Felix!!!

	


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4043216#4043216

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4043216



More information about the jboss-user mailing list