-->
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.  [ 2 posts ] 
Author Message
 Post subject: Lazy instantiation causes TransientObjectException
PostPosted: Mon Mar 14, 2005 6:09 pm 
Newbie

Joined: Fri Feb 25, 2005 5:12 pm
Posts: 10
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

Mapping documents:
<class name="model.Company" table="MASTER">

<id name="masterNo" type="int" unsaved-value="null" >
<column name="MASTER_NO" not-null="true"/>
<generator class="sequence">
<param name="sequence">master_seq</param>
</generator>
</id>
<many-to-one name="prez" class="model.Party" column="PREZ"/>
</class>
<class name="model.Party" table="PARTY">

<id name="partyNo" type="int" unsaved-value="null" >
<column name="PARTY_NO" not-null="true"/>
<generator class="sequence">
<param name="sequence">party_seq</param>
</generator>
</id>

<property name="name" />
<property name="ssn" />
<many-to-one name="addr" class="model.Address" column="ADDR"/>

</class>
<class name="model.Address" table="ADDRESS">

<id name="addrNo" type="int" unsaved-value="null" >
<column name="ADDR_NO" not-null="true"/>
<generator class="sequence">
<param name="sequence">addr_seq</param>
</generator>
</id>

<property name="houseNo">
<column name="HOUSE_NO"/>
</property>
<property name="addr" />
<property name="city" />
<property name="state" />
<property name="zip" />
<property name="zip4" />

</class>

Code between sessionFactory.openSession() and session.close():
These happen in different files. First a company object is returned, then the user hits an edit button. From there it tries to grab prez and lazily instantiates it. Before the user hits save however it needs to populate a list box of owntypes, so it runs an getOwnTypes query. Code snippets bellow:

Grab company to populate edit form:
List tps = s.createQuery("from Company as c where c.masterNo = " + id).list();

Text field to bind to object in session for tapestry/ognl tries to populate company.prez.name , since its null prez = new Party().

Further down the page it tries to populate own types, calls
s.createQuery("from OwnType as o order by o.id").list(); <- error happens here

Never gets to the save portion to save the company object:
Transaction t = s.beginTransaction();
s.update(co);
t.commit();

The hibernate session is stored in a threadlocal, using code from your HibernateUtil class.

Full stack trace of any exception that occurs:

org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: model.Party
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(ForeignKeys.java:210)
at org.hibernate.type.EntityType.getIdentifier(EntityType.java:88)
at org.hibernate.type.EntityType.isDirty(EntityType.java:204)
at org.hibernate.type.TypeFactory.findDirty(TypeFactory.java:378)
at org.hibernate.persister.entity.BasicEntityPersister.findDirty(BasicEntityPersister.java:2518)
at org.hibernate.event.def.DefaultFlushEntityEventListener.dirtyCheck(DefaultFlushEntityEventListener.java:343)
at org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:108)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:190)
at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:70)
at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:39)
at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:650)
at org.hibernate.impl.SessionImpl.prepareQueries(SessionImpl.java:825)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:815)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:773)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at model.service.HibernateCigVendService.getOwnTypes(HibernateCigVendService.java:214)
at view.OwnTypeModel.<init>(OwnTypeModel.java:22)
at view.Engine.getOwnTypeModel(Engine.java:34)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at ognl.OgnlRuntime.invokeMethod(OgnlRuntime.java:491)
at ognl.OgnlRuntime.getMethodValue(OgnlRuntime.java:904)
at ognl.ObjectPropertyAccessor.getPossibleProperty(ObjectPropertyAccessor.java:54)
at ognl.ObjectPropertyAccessor.getProperty(ObjectPropertyAccessor.java:122)
at ognl.OgnlRuntime.getProperty(OgnlRuntime.java:1616)
at ognl.ASTProperty.getValueBody(ASTProperty.java:96)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
at ognl.SimpleNode.getValue(SimpleNode.java:210)
at ognl.ASTChain.getValueBody(ASTChain.java:109)
at ognl.SimpleNode.evaluateGetValueBody(SimpleNode.java:170)
at ognl.SimpleNode.getValue(SimpleNode.java:210)
at ognl.Ognl.getValue(Ognl.java:333)
at ognl.Ognl.getValue(Ognl.java:310)
at org.apache.tapestry.binding.ExpressionBinding.resolveProperty(ExpressionBinding.java:201)
at org.apache.tapestry.binding.ExpressionBinding.getObject(ExpressionBinding.java:194)
at org.apache.tapestry.binding.AbstractBinding.getObject(AbstractBinding.java:208)
at org.apache.tapestry.param.AbstractParameterConnector.getBindingValue(AbstractParameterConnector.java:105)
at org.apache.tapestry.param.ObjectParameterConnector.setParameter(ObjectParameterConnector.java:53)
at org.apache.tapestry.param.ParameterManager.setParameters(ParameterManager.java:105)
at org.apache.tapestry.AbstractComponent.prepareForRender(AbstractComponent.java:898)
at org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:853)
at org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624)
at org.apache.tapestry.components.RenderBody.renderComponent(RenderBody.java:45)
at org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
at org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624)
at org.apache.tapestry.components.Any.renderComponent(Any.java:53)
at org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
at org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624)
at org.apache.tapestry.components.Any.renderComponent(Any.java:53)
at org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
at org.apache.tapestry.BaseComponent.renderComponent(BaseComponent.java:118)
at stark.jwc.groupbox.GroupBox.renderComponent(GroupBox.java:37)
at org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
at org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624)
at org.apache.tapestry.components.RenderBody.renderComponent(RenderBody.java:45)
at org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
at org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624)
at org.apache.tapestry.components.Any.renderComponent(Any.java:53)
at org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
at org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624)
at org.apache.tapestry.components.Any.renderComponent(Any.java:53)
at org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
at org.apache.tapestry.BaseComponent.renderComponent(BaseComponent.java:118)
at stark.jwc.groupbox.GroupBox.renderComponent(GroupBox.java:37)
at org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
at org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624)
at org.apache.tapestry.components.RenderBody.renderComponent(RenderBody.java:45)
at org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
at org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624)
at org.apache.tapestry.form.Form.renderComponent(Form.java:362)
at org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
at org.apache.tapestry.BaseComponent.renderComponent(BaseComponent.java:118)
at org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
at org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624)
at org.apache.tapestry.html.Body.renderComponent(Body.java:269)
at org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
at org.apache.tapestry.AbstractComponent.renderBody(AbstractComponent.java:624)
at org.apache.tapestry.html.Shell.renderComponent(Shell.java:124)
at org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
at org.apache.tapestry.BaseComponent.renderComponent(BaseComponent.java:118)
at org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:857)
at org.apache.tapestry.AbstractPage.renderPage(AbstractPage.java:300)
at org.apache.tapestry.engine.RequestCycle.renderPage(RequestCycle.java:368)
at org.apache.tapestry.engine.AbstractEngine.renderResponse(AbstractEngine.java:732)
at org.apache.tapestry.engine.DirectService.service(DirectService.java:174)
at org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java:872)
at org.apache.tapestry.ApplicationServlet.doService(ApplicationServlet.java:197)
at org.apache.tapestry.ApplicationServlet.doGet(ApplicationServlet.java:158)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at view.ResponseFilter.doFilter(ResponseFilter.java:39)
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:214)
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:825)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
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(Unknown Source)

Name and version of the database you are using: Oracle 9i

The generated SQL (show_sql=true): n/a

Debug level Hibernate log excerpt: n/a


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 15, 2005 10:55 am 
Newbie

Joined: Fri Feb 25, 2005 5:12 pm
Posts: 10
I've read the chapters in the documenation about detached objects and usage of flush. I'm fairly certain that I'm using session improperly, but I don't know how what the best thing to do is to fix it.

In my case, I have a persistent object that needs to be returned from the database. It is passed to the UI layer where associated objects may be instantiated just so the user can enter data into them. This happens before they decide to save, so it really shouldn't be committed to the database yet.

In between the load() and the saveOrUpdate() it may need to also run queries to build Select Boxes and such, which I am performing all of this within one session in a ThreadLocal (which seems to be what most people are doing).

Should I manage two sessions, one for the main persistent class, and then another for utility lookups such as to build ListBox's?

I apologize if this has come up before and been answered, either I'm not very good at searching or I'm just way off base on what I'm trying to do.

I realize that a lot of the examples I have read will store data entered by the user in seperate temporary holding variables, and then update the persistent class and sess.update() it all at once.

However, I am using a large number of fields, and with the features of Tapestry it is very easy to bind the persistent classes fields directly to the text boxes, so that you avoid all of the obj.setPropA(getPropA()), obj.setPropB(getPropB()), obj.setPropC(getPropC()), and so on....

Thank you in advance.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.