Bom dia a todos.
Tenho a sequinte situação , tenho as classe Quadro Geral e Quadro Risco que extends de ItemProntuario.
Existe também uma relação @ManyToMany(gerando a tabela intermediária) PacientProntuario.
Até então nao tenho esta classe intermediaria…Porém nesta tabela preciso de mais um campo observação além dos campos (iditem, e id paciente). Pois ligo este tipo a um paciente
Alguém sabe como posso realizar isto criar uma coluna nesta tabela de junção, a partir do que ja tenho?
To mandando o código…para ajudar a vocês me ajudarem.
Desde já agradeço.
Classe Quadro Geral
package .....
import ......
@Entity
@DiscriminatorValue(value="1") // Valor 1 representa Quadro Geral
// Valor 2 representa Quadro Risco
public class QuadroGeral extends ItemProntuario{
@ManyToMany(targetEntity = Pacientes.class)
@JoinTable(name="PACIENTEPRONTUARIO", joinColumns=@JoinColumn(name="IDITEMPRONTUARIO"), inverseJoinColumns=@JoinColumn(name="IDPACIENTE"))
private List<Pacientes> pacientes;
Get e Set.......
}
Classe ItemProntuario
package...
import.......
@Entity
@Table(name = "ITEMPRONTUARIO")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TIPO",discriminatorType=DiscriminatorType.STRING,length=1)
public abstract class ItemProntuario implements Serializable {
@Transient
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator="IDITEMPRONTUARIO")
@SequenceGenerator(name = "IDITEMPRONTUARIO", sequenceName = "ITEMPRONT_IDITEMPRONTUARIO_GEN" )
@Column(name = "IDITEMPRONTUARIO")
private Integer idItemProntuario;
@Column(name = "NOME", nullable=false, length=50)
private String nome;
@Column(name = "OBSERVACAO", nullable=true, length=100)
private String observacao;
public ItemProntuario() {
}
public ItemProntuario(Integer iditemprontuario) {
this.idItemProntuario = iditemprontuario;
}
public ItemProntuario(Integer iditemprontuario, String nome, String tipo) {
this.idItemProntuario = iditemprontuario;
this.nome = nome;
}
Get e Set.
@Override
public int hashCode() {
int hash = 0;
hash += (idItemProntuario != null ? idItemProntuario.hashCode() : 0);
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 ItemProntuario)) {
return false;
}
ItemProntuario other = (ItemProntuario) object;
if ((this.idItemProntuario == null && other.idItemProntuario != null) || (this.idItemProntuario != null && !this.idItemProntuario.equals(other.idItemProntuario))) {
return false;
}
return true;
}
@Override
public String toString() {
return "as.com.sisclinica.model.ItemProntuario[idItemProntuario=" + idItemProntuario + "]";
}
public void addPropertyChangeListener(PropertyChangeListener listener) {
changeSupport.addPropertyChangeListener(listener);
}
public void removePropertyChangeListener(PropertyChangeListener listener) {
changeSupport.removePropertyChangeListener(listener);
}
}