0
In the following class diagram I am trying to make the following class relationships where a demand will have a responsible analyst and a requesting client. I wonder if my mapping is right if the list gets in the class demands otherwise follows the models below:
package br.com.deivsoft.model;
import java.util.Date;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import br.com.deivsoft.enums.PrioridadeEnum;
import br.com.deivsoft.enums.StatusEnum;
@Entity
@Table(name = "DEMANDAS")
public class Demanda {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID_DEMANDAS")
private Long id;
@Column(name = "NRO_TICKET", length = 50, nullable = false)
private String nro_ticket;
/* Enum de PRIORIDADE */
@Enumerated(EnumType.ORDINAL)
private PrioridadeEnum prioridade;
/* Enum de STATUS */
@Enumerated(EnumType.ORDINAL)
private StatusEnum status;
@OneToMany
@JoinTable(name = "DEMANDA_ANALISTA", joinColumns = @JoinColumn(name = "ID_ANALITAS"), inverseJoinColumns = @JoinColumn(name = "ID_DEMANDAS"))
private List<Contato> contato;
@OneToMany
@JoinTable(name = "DEMANDA_ANALISTA", joinColumns = @JoinColumn(name = "ID_ANALITAS"), inverseJoinColumns = @JoinColumn(name = "ID_DEMANDAS"))
private List<Analista> analista;
@Temporal(TemporalType.DATE)
private Date dt_abertura;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getNro_ticket() {
return nro_ticket;
}
public void setNro_ticket(String nro_ticket) {
this.nro_ticket = nro_ticket;
}
public StatusEnum getStatus() {
return status;
}
public void setStatus(StatusEnum status) {
this.status = status;
}
public PrioridadeEnum getPrioridade() {
return prioridade;
}
public void setPrioridade(PrioridadeEnum prioridade) {
this.prioridade = prioridade;
}
public List<Contato> getContato() {
return contato;
}
public void setContato(List<Contato> contato) {
this.contato = contato;
}
public List<Analista> getAnalista() {
return analista;
}
public void setAnalista(List<Analista> analista) {
this.analista = analista;
}
public void setDt_abertura(Date dt_abertura) {
this.dt_abertura = dt_abertura;
}
}
package br.com.deivsoft.model;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import br.com.deivsoft.model.Equipe.grupamentoEnum;
@Entity
@Table(name ="ANALISTAS")
public class Analista {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID_ANALISTAS")
private Long id;
@Column(name = "MATRICULA", length = 15, nullable = false)
private String matricula;
@Column(name = "NOME", length = 255, nullable = false)
private String nome;
@Column(name = "EQUIPE", length = 150, nullable = false)
private grupamentoEnum equipe;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getMatricula() {
return matricula;
}
public void setMatricula(String matricula) {
this.matricula = matricula;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public grupamentoEnum getEquipe() {
return equipe;
}
public void setEquipe(grupamentoEnum equipe) {
this.equipe = equipe;
}
public List<Demanda> getDemanda() {
return demanda;
}
public void setDemanda(List<Demanda> demanda) {
this.demanda = demanda;
}
}
Customer class is the below in the contact call code
package br.com.deivsoft.model;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name = "CONTATOS")
public class Contato {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID_CONTATOS")
private Long Id;
@Column(name = "NOME", length = 155, nullable = false)
private String nome;
@Column(name = "MATRICULA", length = 20, nullable = false)
private String matricula;
@Column(name = "LOTACAO", length = 155, nullable = false)
private String lotacao;
@OneToMany
@JoinTable(name="DEMANDA_CONTATO",
joinColumns=@JoinColumn(name="ID_CONTATOS"),
inverseJoinColumns = @JoinColumn(name="ID_DEMANDAS"))
private List<Demanda> demanda;
public Long getId() {
return Id;
}
public void setId(Long id) {
Id = id;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getMatricula() {
return matricula;
}
public void setMatricula(String matricula) {
this.matricula = matricula;
}
public String getLotacao() {
return lotacao;
}
public void setLotacao(String lotacao) {
this.lotacao = lotacao;
}
public List<Demanda> getDemanda() {
return demanda;
}
public void setDemanda(List<Demanda> demanda) {
this.demanda = demanda;
}
}
Resende vc could show me what the relational diagram of the database would look like in this case?
– Deivson Bezerra
In fact there is not much secret, demand will have a foreing key for customer and another for analyst. Note that it is not a relationship N to N, but 1 to N, so it is not necessary to use union table for either relationship, only the foreing Keys.
– Resende