EDIT.: como outro pessoa tinha duvida, segui explicando sobre esse assunto aqui => http://www.guj.com.br/posts/list/121586.java
opa!! e ai ?? ^^ ... como havia falado, pra fazer Eng. Reversa, Netbeans > Hibernate Tools.... o que extamente vc ker fazer ? com as chaves compostas ??
da uma olhana na img anexada... ^^ ....
[img]http://img25.imageshack.us/img25/8563/rdb.png[/img]
bom acredito que o que não tem chave composta da pra mapear de boa... a parte que tem chave composta faz assim...
EstoqueProdutoLoja.class
@Entity
@Table(name = "estoque_produto_loja")
public class EstoqueProdutoLoja implements Serializable {
private static final long serialVersionUID = 1L;
@EmbeddedId
protected EstoqueProdutoLojaPK estoqueProdutoLojaPK;
//...
@JoinColumn(name = "estoque_produto_id", referencedColumnName = "id", insertable = false, updatable = false)
@ManyToOne(optional = false, fetch = FetchType.LAZY)
private EstoqueProduto estoqueProduto;
@JoinColumn(name = "loja_id", referencedColumnName = "id", insertable = false, updatable = false)
@ManyToOne(optional = false, fetch = FetchType.LAZY)
private Loja loja;
//...
@OneToMany(cascade = CascadeType.ALL, mappedBy = "estoqueProdutoLoja")
private Set<EventoEstoqueMinimo> eventoEstoqueMinimoCollection;
//...
}
EstoqueProdutoLojaPK.java
@Embeddable
public class EstoqueProdutoLojaPK implements Serializable {
@Basic(optional = false)
@Column(name = "estoque_produto_id")
private int estoqueProdutoId;
@Basic(optional = false)
@Column(name = "loja_id")
private int lojaId;
public EstoqueProdutoLojaPK() {
}
public EstoqueProdutoLojaPK(int estoqueProdutoId, int lojaId) {
this.estoqueProdutoId = estoqueProdutoId;
this.lojaId = lojaId;
}
public int getEstoqueProdutoId() {
return estoqueProdutoId;
}
public void setEstoqueProdutoId(int estoqueProdutoId) {
this.estoqueProdutoId = estoqueProdutoId;
}
public int getLojaId() {
return lojaId;
}
public void setLojaId(int lojaId) {
this.lojaId = lojaId;
}
@Override
public int hashCode() {
int hash = 0;
hash += (int) estoqueProdutoId;
hash += (int) lojaId;
return hash;
}
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof EstoqueProdutoLojaPK)) {
return false;
}
EstoqueProdutoLojaPK other = (EstoqueProdutoLojaPK) object;
if (this.estoqueProdutoId != other.estoqueProdutoId) {
return false;
}
if (this.lojaId != other.lojaId) {
return false;
}
return true;
}
@Override
public String toString() {
return "br.com.superlocar.model.entity.EstoqueProdutoLojaPK[estoqueProdutoId=" + estoqueProdutoId + ", lojaId=" + lojaId + "]";
}
}
EventoEstoqueMinimo.java
@Entity
@Table(name = "evento_estoque_minimo")
public class EventoEstoqueMinimo implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Basic(optional = false)
@Column(name = "evento_id")
private Integer eventoId;
//....
@JoinColumn(name = "evento_id", referencedColumnName = "id", insertable = false, updatable = false)
@OneToOne(optional = false)
private Evento evento;
//...
@JoinColumns({@JoinColumn(name = "estoque_produto_id", referencedColumnName = "estoque_produto_id"), @JoinColumn(name = "loja_id", referencedColumnName = "loja_id")})
@ManyToOne(optional = false)
private EstoqueProdutoLoja estoqueProdutoLoja;
//....
}
Ps.: o Netbeans mapea isso ai, com a ferramenta dele ^^ ... boa sorte
