Galera,
seguinte tenho tres tabelas :cliente, empresa e de endereco. Quando mando persistir cliente esta dando o seguinte erro:
Caused by: org.hibernate.PropertyValueException: not-null property references a null or transient value: br.com.centrooeste.dominio.Empresa.cliente
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:609)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:601)
at org.hibernate.engine.EJB3CascadingAction$1.cascade(EJB3CascadingAction.java:30)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:296)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:456)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:334)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
at org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
at org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:213)
... 25 more
A unica coisa que eu sei e que esta indo valor null, e com isso deve ser a chave da tabela emrpesa que esta indo como nula. Como eu resolvo esse problema?
Tabela Cliente
import static javax.persistence.GenerationType.IDENTITY;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
@Entity
@Table(name = "cliente", catalog = "projeto_centro_oeste")
public class Cliente implements java.io.Serializable {
private static final long serialVersionUID = -1229152608080075259L;
// Fields
@Id
@GeneratedValue(strategy =GenerationType.AUTO)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
@Column(name = "nome", length = 50)
private String nome;
@Column(name = "cpf", length = 20)
private String cpf;
@Temporal(TemporalType.DATE)
@Column(name = "data_nascimento", length = 10)
private Date dataNascimento;
@Temporal(TemporalType.DATE)
@Column(name = "data_cadastro", length = 10)
private Date dataCadastro;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "cliente")
private Set<Empresa> empresas = new HashSet<Empresa>(0);
// Constructors
/** default constructor */
public Cliente() {
}
//Get e Sets dos atributos
}
Tabela Empresa
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name = "empresa", catalog = "projeto_centro_oeste")
public class Empresa implements java.io.Serializable {
private static final long serialVersionUID = -7817959290878002099L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "cliente_id", nullable = false)
private Cliente cliente;
@Column(name = "nome", length = 50)
private String nome;
@Column(name = "nome_fantasia", length = 45)
private String nomeFantasia;
@Column(name = "cnpj", length = 20)
private String cnpj;
@Column(name = "logomarca")
private String logomarca;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "empresa")
private Set<Endereco> enderecos = new HashSet<Endereco>(0);
// Constructors
/** default constructor */
public Empresa() {
}
//Get e Sets dos atributos
}
Tabela Endereco
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
@Entity
@Table(name = "endereco", catalog = "projeto_centro_oeste")
public class Endereco implements java.io.Serializable {
private static final long serialVersionUID = 2539125249339628761L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id", unique = true, nullable = false)
private Integer id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "empresa_id", nullable = false)
private Empresa empresa;
@Column(name = "logradouro")
private String logradouro;
@Column(name = "numero", length = 5)
private String numero;
@Column(name = "complemento", length = 20)
private String complemento;
@Column(name = "bairro", length = 20)
private String bairro;
@Column(name = "cep", length = 20)
private String cep;
// Constructors
/** default constructor */
public Endereco() {
}
//Get e Sets dos atributos
}