Tenho duas entidade Estabelecimento e Endereço que possuem um relacionamento one-to-one.
O que quero fazer é inserir o estabelecimento e o endereço ao mesmo tempo ou seja. crio um endereço q nao existe no banco, atribuo o a estabelecimento que tbm ainda nao esxite no banco e mando incluir o estabelecimento, soh q esta dando o seguinte erro: net.sf.hibernate.PropertyValueException: not-null property references a null or transient value:
Pelo jeito tenho que inserir primeiro o endereço depois atribuir ele ao estabelecimento e entao inserir o estabelecimento, nao tem como eu fazer isso de uma fez soh nao ???
Em anexo segue o log do erro q esta dando e em seguida o meu mapeamento das classes estabelecimento e endereço
----------------------LOG DE ERRO------------------------------------------
net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: restaurante.estabelecimento.Estabelecimento.endereco
at net.sf.hibernate.impl.SessionImpl.checkNullability(SessionImpl.java:1248)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2535)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2422)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2224)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2203)
at restaurante.util.persistencia.GerenciadorTransacao.commitTransacao(GerenciadorTransacao.java:63)
at restaurante.fachada.FachadaTeste.pagarConta(FachadaTeste.java:521)
at restaurante.fachada.FachadaTeste.main(FachadaTeste.java:556)
net.sf.hibernate.HibernateException: net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: restaurante.estabelecimento.Estabelecimento.endereco
at restaurante.util.persistencia.GerenciadorTransacao.commitTransacao(GerenciadorTransacao.java:67)
at restaurante.fachada.FachadaTeste.pagarConta(FachadaTeste.java:521)
at restaurante.fachada.FachadaTeste.main(FachadaTeste.java:556)
Caused by: net.sf.hibernate.PropertyValueException: not-null property references a null or transient value: restaurante.estabelecimento.Estabelecimento.endereco
at net.sf.hibernate.impl.SessionImpl.checkNullability(SessionImpl.java:1248)
at net.sf.hibernate.impl.SessionImpl.flushEntity(SessionImpl.java:2535)
at net.sf.hibernate.impl.SessionImpl.flushEntities(SessionImpl.java:2422)
at net.sf.hibernate.impl.SessionImpl.flushEverything(SessionImpl.java:2224)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2203)
at restaurante.util.persistencia.GerenciadorTransacao.commitTransacao(GerenciadorTransacao.java:63)
--------------------------MAPEAMENTO DA CLASSE ESTABELECIMENTO------
<hibernate-mapping>
<class name=“restaurante.estabelecimento.Estabelecimento” table=“estabelecimentos”>
<id name="cnpj" column="est_cnpj" type="string" length="18">
<generator class="assigned"/>
</id>
<!-- <property name=“cnpj” column=“est_cnpj” type=“string” length=“14” not-null=“true” unique=“true”/> -->
<property name=“nome” column=“est_nome” type=“string” length=“50” not-null=“true”/>
<property name=“nomeFantasia” column=“est_nome_fantasia” type=“string” length=“50” not-null=“false”/>
<property name=“logotipo” column=“est_logotipo” type=“string” length=“50” not-null=“false”/>
<property name=“telefone” column=“est_telefone” type=“string” length=“10” not-null=“false”/>
<property name=“fax” column=“est_fax” type=“string” length=“10” not-null=“false”/>
<property name=“email” column=“est_email” type=“string” length=“30” not-null=“false”/>
<one-to-one name="endereco" class="restaurante.endereco.Endereco" constrained="true" cascade="all"/>
</class>
</hibernate-mapping>
--------------------MAPEAMENTO DA CLASSE ENDEREÇO------------------
<hibernate-mapping>
<class name=“restaurante.endereco.Endereco” table=“endereco”>
<id name=“codigo” column=“end_codigo” type=“long” unsaved-value=“null”>
<generator class=“sequence”>
<param name=“sequence”>seq_endereco</param>
</generator>
</id>
<property name=“rua” column=“end_rua” type=“string” length=“100” not-null=“true”/>
<property name=“numero” column=“end_numero” type=“string” length=“6” not-null=“true”/>
<property name=“bairro” column=“end_bairro” type=“string” length=“50” not-null=“true”/>
<property name=“cidade” column=“end_cidade” type=“string” length=“50” not-null=“true”/>
<property name=“estado” column=“end_estado” type=“string” length=“30” not-null=“true”/>
<property name=“cep” column=“end_cep” type=“string” length=“10” not-null=“true”/>
</class>
</hibernate-mapping>