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.  [ 7 posts ] 
Author Message
 Post subject: Persisting on criteria query
PostPosted: Mon Apr 02, 2007 12:55 pm 
Newbie

Joined: Mon Apr 02, 2007 12:53 pm
Posts: 10
Hi,

I am inside a EJB2 transaction part way through creating an object to persist. I have an object which has among other things an ID and a code. I want to look up this object by the code. I've tried using query by example and criteria and this is where I run into problems. I can do a get() and pass the ID and this works fine but in practice I wont actually know the ID at this time. Hibernate attempts to persist part way through fetching the object. I'm not sure if this is caused by an exception being thrown and the transaction finishing. That's my best guess at least. I can't see why else hibernate would be tiring to persist at that time. The problem is I am not ready to persist the object, not all objects have been added (I need to add the one I am attempting to look up for a start).

My stack trace is as follows:

Code:
17:46:21,437 ERROR [LogInterceptor] TransactionRolledbackLocalException in method: public abstract com.sami.warrantySystem.ejb.session.audit.AuditComm
and com.sami.warrantySystem.ejb.session.LocalAuditService.runCommand(com.sami.warrantySystem.ejb.session.audit.AuditCommand) throws com.sami.warrantyS
ystem.ejb.session.audit.InvalidAuditStateException, causedBy:
org.hibernate.PropertyValueException: not-null property references a null or transient value: com.sami.warrantySystem.ejb.entities.AssessmentClaim.cla
im
        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:121)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
        at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
        at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
        at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
        at org.hibernate.engine.CascadingAction$1.cascade(CascadingAction.java:218)
        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.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:131)
        at org.hibernate.event.def.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:122)
        at org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:65)
        at org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:35)
        at org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:969)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1562)
        at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:283)
        at com.sami.util.j2ee.hibernate.GenericHibernateDAO.findByCriteria(GenericHibernateDAO.java:165)
        at com.sami.warrantySystem.ejb.session.audit.AuditUploader.recordClaimLines(AuditUploader.java:321)
        at com.sami.warrantySystem.ejb.session.audit.AuditUploader.handleClaimsResponse(AuditUploader.java:255)
        at com.sami.warrantySystem.ejb.session.audit.AuditUploader.loadAnswers(AuditUploader.java:76)
        at com.sami.warrantySystem.ejb.session.audit.UploadAuditCommand.doCommand(UploadAuditCommand.java:55)
        at com.sami.warrantySystem.ejb.session.AuditServiceBean.runCommand(AuditServiceBean.java:95)
        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 org.jboss.invocation.Invocation.performCall(Invocation.java:359)
        at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:237)
        at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:158)
        at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:169)
        at org.jboss.ws.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:64)
        at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:63)
        at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:121)
        at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:350)
        at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:181)
        at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:168)
        at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:205)
        at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:136)
        at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:648)
        at org.jboss.ejb.Container.invoke(Container.java:954)
        at org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invoke(BaseLocalProxyFactory.java:430)
        at org.jboss.ejb.plugins.local.StatelessSessionProxy.invoke(StatelessSessionProxy.java:103)
        at $Proxy103.runCommand(Unknown Source)
        at com.sami.warrantySystem.ejb.session.ws.ClientWebServiceBean.uploadAuditResults(ClientWebServiceBean.java:194)
        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 org.jboss.invocation.Invocation.performCall(Invocation.java:359)
        at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:237)
        at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:158)
        at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:169)
        at org.jboss.ws.server.ServiceEndpointInterceptor.invoke(ServiceEndpointInterceptor.java:90)
        at org.jboss.ejb.plugins.CallValidationInterceptor.invoke(CallValidationInterceptor.java:63)
        at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:121)
        at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:350)
        at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:181)
        at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:168)
        at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:205)
        at org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invoke(ProxyFactoryFinderInterceptor.java:136)
        at org.jboss.ejb.SessionContainer.internalInvoke(SessionContainer.java:648)
        at org.jboss.ejb.Container.invoke(Container.java:954)
        at sun.reflect.GeneratedMethodAccessor119.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
        at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
        at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
        at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
        at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
        at org.jboss.ws.server.ServiceEndpointInvokerEJB21.invokeServiceEndpoint(ServiceEndpointInvokerEJB21.java:137)
        at org.jboss.ws.server.ServiceEndpointInvoker.invoke(ServiceEndpointInvoker.java:118)
        at org.jboss.ws.server.ServiceEndpoint.handleRequest(ServiceEndpoint.java:234)
        at org.jboss.ws.server.ServiceEndpointServlet.doPost(ServiceEndpointServlet.java:120)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
        at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
        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.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
        at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
        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:869)
        at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
        at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
        at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
        at java.lang.Thread.run(Thread.java:595)


I've been trying to figure this one out all afternoon but have had no success. I'm hoping it's something pretty simple that someone with more experience will be able to help me out pretty easily :). Thanks in advance for you help.

Sam


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 4:19 am 
Regular
Regular

Joined: Mon Jun 12, 2006 5:33 am
Posts: 63
Hi samblake,
are you trying to query your object or save it? In the stack trace it seams that you're trying to save an object O1 that has a reference on object O2, but O2 is not yet persisted at that time or is null.
Could u provide a pseudo code of your mappings and POJOS about the related classes?

chucky
--------


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 4:41 am 
Regular
Regular

Joined: Fri May 12, 2006 4:05 am
Posts: 106
Hi,

when using FlushMode.AUTO hibernate might flush the session-context(i.e. issue insert- or update-statements) just before exectuing a query. This is because changes made in the persistence context might change the result of the query so hibernate has to synchronize the DB-state.
To get around this you could try one of the following (just my first ideas, perhaps there's a better way):
- set the sessions's FlushMode to FlushMode.COMMIT or FlushMode.MANUAL (remember you have to call flush() yourself) - if this doesn't collide with the other work you'er doing in this session.
- detach all modified objects that you don't want to be updated in the database before executing the query and reattach them later.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 4:47 am 
Newbie

Joined: Mon Apr 02, 2007 12:53 pm
Posts: 10
The code itself is quite long but I am just trying to query this object. Originally I create a Claim and set a bunch of parameters, I then want to look up a PartsCode via it's code to add to it so I do:

Code:
Criteria crit = getSession().createCriteria(ClaimLine.class);
crit.add((Expression.eq(PartsCode.FIELD_CODE, webCharge.getPartCode()));
List results = crit.list();


This is the line I get the exception on.

The Claim has an AssessmentClaim which has an Assessments. The Assessments then have many ClaimLineDeficiencies. Each ClaimLineDeficiency belongs to a ClaimLine which has many ClaimLineCharges. A ClaimLineCharge may have an associated PartsCode. I have added all other stages to the Claim (either by adding them without getting them from the database as they are not yet in there, or by looking them up with a get) and am now attempting to lookup the PartsCode to add to the ClaimLineCharge. It's when trying to get the part code by criteria that I get the problem. As I previously mentioned if I can get() one by id but I only know the code at this time.

Is this sufficient detail? I know these not much in there but it’s a complex relationship and so putting more detail in would take forever unless I knew what kind of detail you’re looking for.

Thanks.

Sam


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 4:48 am 
Newbie

Joined: Mon Apr 02, 2007 12:53 pm
Posts: 10
The code itself is quite long but I am just trying to query this object. Originally I create a Claim and set a bunch of parameters, I then want to look up a PartsCode via it's code to add to it so I do:

Code:
Criteria crit = getSession().createCriteria(ClaimLine.class);
crit.add((Expression.eq(PartsCode.FIELD_CODE, webCharge.getPartCode()));
List results = crit.list();


This is the line I get the exception on.

The Claim has an AssessmentClaim which has an Assessments. The Assessments then have many ClaimLineDeficiencies. Each ClaimLineDeficiency belongs to a ClaimLine which has many ClaimLineCharges. A ClaimLineCharge may have an associated PartsCode. I have added all other stages to the Claim (either by adding them without getting them from the database as they are not yet in there, or by looking them up with a get) and am now attempting to lookup the PartsCode to add to the ClaimLineCharge. It's when trying to get the part code by criteria that I get the problem. As I previously mentioned if I can get() one by id but I only know the code at this time.

Is this sufficient detail? I know these not much in there but it’s a complex relationship and so putting more detail in would take forever unless I knew what kind of detail you’re looking for.

Thanks.

Sam


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 5:40 am 
Newbie

Joined: Mon Apr 02, 2007 12:53 pm
Posts: 10
Ah right. Thanks piet. That makes a lot of sense. Setting the flush mode to commit while I make the query and resetting it afterwards works fine. Thanks a lot.

Sam


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 5:46 am 
Regular
Regular

Joined: Mon Jun 12, 2006 5:33 am
Posts: 63
Hi samblake,

in the stack trace, you have :
Code:
at com.sami.util.j2ee.hibernate.GenericHibernateDAO.findByCriteria(GenericHibernateDAO.java:165)
at com.sami.warrantySystem.ejb.session.audit.AuditUploader.recordClaimLines(AuditUploader.java:321)

It seams like when recording your ClaimLines, the associated object (maybe the ClaimLineDeficiencies ??) mapped in the "ClaimLine.hbm.xml" is not set in the code, and is maybe mapped to be not-null in the "ClaimLine.hbm.xml".
Chucky
----------
Don't forget to rate if that helps


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.