-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: session.get() does not return persistent object?!
PostPosted: Tue May 16, 2006 12:01 pm 
Newbie

Joined: Fri Apr 28, 2006 3:46 pm
Posts: 8
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 9

The generated SQL (show_sql=true):
Code:
Hibernate: select seq_geral.nextval from dual


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 12:17 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
Try this code, though there is not much change. see the comment

Code:
session.beginTransaction();
Situacao situacaoObject = (Situacao) session.get(Situacao.class,new BigDecimal(1));
historico.setSituacao( situacaoObject );

// I dont want to save it YET
//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();


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 12:24 pm 
Newbie

Joined: Fri Apr 28, 2006 3:46 pm
Posts: 8
I've already tried that. It just delays the exception to the next save() call.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 12:34 pm 
Newbie

Joined: Fri Apr 28, 2006 3:46 pm
Posts: 8
Corrected it. Actually that post made me re-debug and I found out one object with a null-value!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.