Olá amigos, estou com um problemão aqui.
Eu tenho 4 entidades, pai (1 registro) + filho (2 registros) + filho do filho (2 registros) + filho di filho do filho (3 registros) e quando mando inserir ele só esta criando 1 registro em cada tabela e não gera nenhum erro, será que alguem pode me dar uma força nessa questão?
Segue abaixo as entidades ok:
DIAGNOSTICO
[code]@Entity
@Table(name = “diagnostico”, catalog = “salao”, schema = “public”)
@NamedQueries({
@NamedQuery(name = “Diagnostico.findAll”, query = “SELECT d FROM Diagnostico d”)})
public class Diagnostico implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = “id_diagnostico”, nullable = false)
private Integer idDiagnostico;
@Size(max = 100)
@Column(name = “dsc_diagnostico”, length = 100)
private String dscDiagnostico;
@OneToMany(cascade = CascadeType.ALL, mappedBy = “idDiagnostico”)
@LazyCollection(LazyCollectionOption.FALSE)
@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private List diagnosticoNivel1List;
public Diagnostico() {
}
public Diagnostico(Integer idDiagnostico) {
this.idDiagnostico = idDiagnostico;
}
public Integer getIdDiagnostico() {
return idDiagnostico;
}
public void setIdDiagnostico(Integer idDiagnostico) {
this.idDiagnostico = idDiagnostico;
}
public String getDscDiagnostico() {
return dscDiagnostico;
}
public void setDscDiagnostico(String dscDiagnostico) {
this.dscDiagnostico = dscDiagnostico;
}
public List<DiagnosticoNivel1> getDiagnosticoNivel1List() {
return diagnosticoNivel1List;
}
public void setDiagnosticoNivel1List(List<DiagnosticoNivel1> diagnosticoNivel1List) {
this.diagnosticoNivel1List = diagnosticoNivel1List;
}
@Override
public int hashCode() {
int hash = 0;
hash += (idDiagnostico != null ? idDiagnostico.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 Diagnostico)) {
return false;
}
Diagnostico other = (Diagnostico) object;
if ((this.idDiagnostico == null && other.idDiagnostico != null) || (this.idDiagnostico != null && !this.idDiagnostico.equals(other.idDiagnostico))) {
return false;
}
return true;
}
@Override
public String toString() {
return "br.jm.financeiro.entity.Diagnostico[ idDiagnostico=" + idDiagnostico + " ]";
}
}
[/code]
DIAGNOSTICONIVEL1
[code]@Entity
@Table(name = “diagnostico_nivel1”, catalog = “salao”, schema = “public”)
@NamedQueries({
@NamedQuery(name = “DiagnosticoNivel1.findAll”, query = “SELECT d FROM DiagnosticoNivel1 d”)})
public class DiagnosticoNivel1 implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = “id_diagnostico_nivel1”, nullable = false)
private Integer idDiagnosticoNivel1;
@Size(max = 40)
@Column(name = “dsc_diagnostico_nivel1”, length = 40)
private String dscDiagnosticoNivel1;
@JoinColumn(name = "id_diagnostico", referencedColumnName = "id_diagnostico", nullable = false)
@ManyToOne(optional = false, fetch = FetchType.EAGER)
private Diagnostico idDiagnostico;
@OneToMany(cascade = CascadeType.ALL,mappedBy = "idDiagnosticoNivel1")
@LazyCollection(LazyCollectionOption.FALSE)
@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private List<DiagnosticoNivel2> diagnosticoNivel2List;
public DiagnosticoNivel1() {
}
public DiagnosticoNivel1(Integer idDiagnosticoNivel1) {
this.idDiagnosticoNivel1 = idDiagnosticoNivel1;
}
public Integer getIdDiagnosticoNivel1() {
return idDiagnosticoNivel1;
}
public void setIdDiagnosticoNivel1(Integer idDiagnosticoNivel1) {
this.idDiagnosticoNivel1 = idDiagnosticoNivel1;
}
public String getDscDiagnosticoNivel1() {
return dscDiagnosticoNivel1;
}
public void setDscDiagnosticoNivel1(String dscDiagnosticoNivel1) {
this.dscDiagnosticoNivel1 = dscDiagnosticoNivel1;
}
public Diagnostico getIdDiagnostico() {
return idDiagnostico;
}
public void setIdDiagnostico(Diagnostico idDiagnostico) {
this.idDiagnostico = idDiagnostico;
}
public List<DiagnosticoNivel2> getDiagnosticoNivel2List() {
return diagnosticoNivel2List;
}
public void setDiagnosticoNivel2List(List<DiagnosticoNivel2> diagnosticoNivel2List) {
this.diagnosticoNivel2List = diagnosticoNivel2List;
}
@Override
public int hashCode() {
int hash = 0;
hash += (idDiagnosticoNivel1 != null ? idDiagnosticoNivel1.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 DiagnosticoNivel1)) {
return false;
}
DiagnosticoNivel1 other = (DiagnosticoNivel1) object;
if ((this.idDiagnosticoNivel1 == null && other.idDiagnosticoNivel1 != null) || (this.idDiagnosticoNivel1 != null && !this.idDiagnosticoNivel1.equals(other.idDiagnosticoNivel1))) {
return false;
}
return true;
}
@Override
public String toString() {
return "br.jm.financeiro.entity.DiagnosticoNivel1[ idDiagnosticoNivel1=" + idDiagnosticoNivel1 + " ]";
}
}
[/code]
DIAGNOSTICONIVEL2
[code]@Entity
@Table(name = “diagnostico_nivel2”, catalog = “salao”, schema = “public”)
@NamedQueries({
@NamedQuery(name = “DiagnosticoNivel2.findAll”, query = “SELECT d FROM DiagnosticoNivel2 d”)})
public class DiagnosticoNivel2 implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = “id_diagnostico_nivel2”, nullable = false)
private Integer idDiagnosticoNivel2;
@Size(max = 40)
@Column(name = “dsc_diagnostico_nivel2”, length = 40)
private String dscDiagnosticoNivel2;
@OneToMany(cascade = CascadeType.ALL,mappedBy = “idDiagnosticoNivel2”)
@LazyCollection(LazyCollectionOption.FALSE)
@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
private List diagnosticoNivel3List;
@JoinColumn(name = "id_diagnostico_nivel1", referencedColumnName = "id_diagnostico_nivel1", nullable = false)
@ManyToOne(optional = false, fetch = FetchType.EAGER)
private DiagnosticoNivel1 idDiagnosticoNivel1;
public DiagnosticoNivel2() {
}
public DiagnosticoNivel2(Integer idDiagnosticoNivel2) {
this.idDiagnosticoNivel2 = idDiagnosticoNivel2;
}
public Integer getIdDiagnosticoNivel2() {
return idDiagnosticoNivel2;
}
public void setIdDiagnosticoNivel2(Integer idDiagnosticoNivel2) {
this.idDiagnosticoNivel2 = idDiagnosticoNivel2;
}
public String getDscDiagnosticoNivel2() {
return dscDiagnosticoNivel2;
}
public void setDscDiagnosticoNivel2(String dscDiagnosticoNivel2) {
this.dscDiagnosticoNivel2 = dscDiagnosticoNivel2;
}
public List<DiagnosticoNivel3> getDiagnosticoNivel3List() {
return diagnosticoNivel3List;
}
public void setDiagnosticoNivel3List(List<DiagnosticoNivel3> diagnosticoNivel3List) {
this.diagnosticoNivel3List = diagnosticoNivel3List;
}
public DiagnosticoNivel1 getIdDiagnosticoNivel1() {
return idDiagnosticoNivel1;
}
public void setIdDiagnosticoNivel1(DiagnosticoNivel1 idDiagnosticoNivel1) {
this.idDiagnosticoNivel1 = idDiagnosticoNivel1;
}
@Override
public int hashCode() {
int hash = 0;
hash += (idDiagnosticoNivel2 != null ? idDiagnosticoNivel2.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 DiagnosticoNivel2)) {
return false;
}
DiagnosticoNivel2 other = (DiagnosticoNivel2) object;
if ((this.idDiagnosticoNivel2 == null && other.idDiagnosticoNivel2 != null) || (this.idDiagnosticoNivel2 != null && !this.idDiagnosticoNivel2.equals(other.idDiagnosticoNivel2))) {
return false;
}
return true;
}
@Override
public String toString() {
return "br.jm.financeiro.entity.DiagnosticoNivel2[ idDiagnosticoNivel2=" + idDiagnosticoNivel2 + " ]";
}
}
[/code]
DIAGNOSTICONIVEL3
[code]@Entity
@Table(name = “diagnostico_nivel3”, catalog = “salao”, schema = “public”)
@NamedQueries({
@NamedQuery(name = “DiagnosticoNivel3.findAll”, query = “SELECT d FROM DiagnosticoNivel3 d”)})
public class DiagnosticoNivel3 implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = “id_diagnostico_nivel3”, nullable = false)
private Integer idDiagnosticoNivel3;
@Size(max = 40)
@Column(name = “dsc_diagnostico_nivel3”, length = 40)
private String dscDiagnosticoNivel3;
@JoinColumn(name = “id_diagnostico_nivel2”, referencedColumnName = “id_diagnostico_nivel2”, nullable = false)
@ManyToOne(optional = false, fetch = FetchType.EAGER)
private DiagnosticoNivel2 idDiagnosticoNivel2;
public DiagnosticoNivel3() {
}
public DiagnosticoNivel3(Integer idDiagnosticoNivel3) {
this.idDiagnosticoNivel3 = idDiagnosticoNivel3;
}
public Integer getIdDiagnosticoNivel3() {
return idDiagnosticoNivel3;
}
public void setIdDiagnosticoNivel3(Integer idDiagnosticoNivel3) {
this.idDiagnosticoNivel3 = idDiagnosticoNivel3;
}
public String getDscDiagnosticoNivel3() {
return dscDiagnosticoNivel3;
}
public void setDscDiagnosticoNivel3(String dscDiagnosticoNivel3) {
this.dscDiagnosticoNivel3 = dscDiagnosticoNivel3;
}
public DiagnosticoNivel2 getIdDiagnosticoNivel2() {
return idDiagnosticoNivel2;
}
public void setIdDiagnosticoNivel2(DiagnosticoNivel2 idDiagnosticoNivel2) {
this.idDiagnosticoNivel2 = idDiagnosticoNivel2;
}
@Override
public int hashCode() {
int hash = 0;
hash += (idDiagnosticoNivel3 != null ? idDiagnosticoNivel3.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 DiagnosticoNivel3)) {
return false;
}
DiagnosticoNivel3 other = (DiagnosticoNivel3) object;
if ((this.idDiagnosticoNivel3 == null && other.idDiagnosticoNivel3 != null) || (this.idDiagnosticoNivel3 != null && !this.idDiagnosticoNivel3.equals(other.idDiagnosticoNivel3))) {
return false;
}
return true;
}
@Override
public String toString() {
return "br.jm.financeiro.entity.DiagnosticoNivel3[ idDiagnosticoNivel3=" + idDiagnosticoNivel3 + " ]";
}
}[/code]
Desde já agradeço qualquer ajuda.
Abraços
Jomello