When I do
session.get() the returned object is NEVER considered to be persistent. Because when I set it to another one (see code excerpt) and try to persist it, the exception thrown is "not-null or transient property".
Hibernate version: 3.0
Mapping documents:
Code:
<hibernate-mapping>
<class name="br.gov.trern.siasf.suprimentos.dominio.Situacao" table="TB_SITUACAO" schema="SIASF">
<id name="id" type="big_decimal">
<column name="ID_SITUACAO" precision="22" scale="0" />
<generator class="assigned" />
</id>
<property name="codigoSituacao" type="string">
<column name="CDSITUACAO" length="2" not-null="true" />
</property>
<property name="descricaoSituacao" type="string">
<column name="DESITUACAO" length="50" />
</property>
<set name="historicoSuprimentos" inverse="true" cascade="all">
<key>
<column name="ID_SITUACAO" precision="22" scale="0" />
</key>
<one-to-many class="br.gov.trern.siasf.suprimentos.dominio.HistoricoSuprimento" />
</set>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="br.gov.trern.siasf.suprimentos.dominio.HistoricoSuprimento" table="TB_HISTORICO_SUPRIMENTO" schema="SIASF">
<id name="id" type="long">
<column name="ID_HISTORICO_SUPRIMENTO" precision="22" scale="0" />
<generator class="seqhilo">
<param name="sequence">seq_geral</param>
</generator>
</id>
<many-to-one name="situacao" class="br.gov.trern.siasf.suprimentos.dominio.Situacao" fetch="select">
<column name="ID_SITUACAO" precision="22" scale="0" />
</many-to-one>
<many-to-one name="solicitacao" class="br.gov.trern.siasf.suprimentos.dominio.SolicitaSuprimento" fetch="select">
<column name="ID_SOLICITACAO_SUPRIMENTO" precision="22" scale="0" not-null="true" />
</many-to-one>
<property name="dataAlteracao" type="date">
<column name="DTALTERAÇÃO" length="7" />
</property>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
session.beginTransaction();
historico.setSituacao((Situacao) session.get(Situacao.class,new BigDecimal(1)));
session.save(historico);
solicitacao.getHistoricoSuprimentos().add(historico);
String id = Long.toString(solicitacao.getId());
solicitacao.setNumeroSolicitacao(new BigDecimal(String.valueOf(GregorianCalendar.getInstance().get(Calendar.YEAR)) + id));
session.save(solicitacao);
session.getTransaction().commit();
Full stack trace of any exception that occurs:Code:
org.hibernate.PropertyValueException: not-null property references a null or transient value: br.gov.trern.siasf.suprimentos.dominio.HistoricoSuprimento.solicitacao
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:265)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:167)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:114)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:186)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:530)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)
at br.gov.trern.siasf.suprimentos.negocio.SolicitacaoNegocio.insertSolicitacao(SolicitacaoNegocio.java:161)
at br.gov.trern.siasf.suprimentos.dominio.SolicitaSuprimento.solicita(SolicitaSuprimento.java:375)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
at javax.faces.component.UICommand.broadcast(UICommand.java:312)
at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Name and version of the database you are using: Oracle 9The generated SQL (show_sql=true):Code:
Hibernate: select seq_geral.nextval from dual