O que siginifica detached entity ?
package erp.banco.agencia;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.PersistenceContext;
import erp.banco.Banco;
import javax.persistence.CascadeType;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
@PersistenceContext(unitName = “depto”)
@Entity
@SuppressWarnings(“serial”)
public class Agencia implements Serializable {
@ManyToOne(cascade = CascadeType.ALL, fetch=FetchType.EAGER)
private Banco banco;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(length = 30)
private String nome;
@Column(length = 15)
private String numero;
public Agencia() {
}
public Banco getBanco() {
return banco;
}
public Long getId() {
return id;
}
public String getNome() {
return nome;
}
public String getNumero() {
return numero;
}
public void setBanco(final Banco banco) {
this.banco = banco;
}
public void setId(final Long id) {
this.id = id;
}
public void setNome(final String nome) {
this.nome = nome;
}
public void setNumero(final String numero) {
this.numero = numero;
}
@Override
public String toString() {
return nome;
}
}
package erp.banco;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.PersistenceContext;
@PersistenceContext(unitName = “depto”)
@Entity
@SuppressWarnings(“serial”)
public class Banco implements Serializable {
@Column(length = 15)
private String codigo;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(length = 50)
private String nome;
public Banco() {
}
public String getCodigo() {
return codigo;
}
public Long getId() {
return id;
}
public String getNome() {
return nome;
}
public void setCodigo(final String codigo) {
this.codigo = codigo;
}
public void setId(final Long id) {
this.id = id;
}
public void setNome(final String nome) {
this.nome = nome;
}
@Override
public String toString() {
return nome;
}
}
javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: erp.banco.Banco
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1377)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1300)
at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1306)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:871)