Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Question on initial "field values"

Your exception doesn't show the underlying exceptions stack trace - where the NPE is being thrown from. 

Anyway, no, you cannot call event.updateAttributeWithObject("dirty", false);
unless the attribute "dirty" is mapped - this code relies on the mapping to set the attribute in the object. 

What are you trying to do though?  The initial problem seemed to be that the dirty field is being set to true - are you setting
this field in your accessor methods?  If so, is your entity using property access or field access.  If it is using property access,
could it be that loading the entity is setting those field because it must use the entities accessors? 

 I am not sure why you want to use merge, but since it is not transient, you would set the field
on the object directly - location.dirty = false;  You might want to look at using postLoad event to reset your transient dirty fields when the Entity is loaded from the
database or when it gets refreshed.   This will cover the case where you are loading an entity from the shared cache or the database. 

Best Regards,
Chris

On 01/12/2010 3:07 PM, Kevin Haskett wrote:
Here is the stack trace after executing this code -
    @Override
    public void postMerge(DescriptorEvent event) {
        CpLocation location = (CpLocation)event.getObject();
        boolean dirty = location.isDirty();
        if (dirty) {
            event.updateAttributeWithObject("dirty", false);
        }
        
    }


Could not commit JPA transaction; nested exception is
javax.persistence.RollbackException: java.lang.NullPointerException}
org.springframework.transaction.TransactionSystemException: Could not
commit JPA transaction; nested exception is
javax.persistence.RollbackException: java.lang.NullPointerException;
at
org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactio
nManager.java:465);
at
org.springframework.transaction.support.AbstractPlatformTransactionManag
er.processCommit(AbstractPlatformTransactionManager.java:732);at
org.springframework.transaction.support.AbstractPlatformTransactionManag
er.commit(AbstractPlatformTransactionManager.java:701);at
org.springframework.transaction.interceptor.TransactionAspectSupport.com
mitTransactionAfterReturning(TransactionAspectSupport.java:321);at
org.springframework.transaction.interceptor.TransactionInterceptor.invok
e(TransactionInterceptor.java:116);at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(Ref
lectiveMethodInvocation.java:171);at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAo
pProxy.java:204);at $Proxy55.update(Unknown Source);at
com.gmrc.cpp.managers.CppPolicyManager.processCpForInitTrans(CppPolicyMa
nager.java:1174);at
com.gmrc.cpp.struts.actions.TransactionAction.processCpForInitTrans(Tran
sactionAction.java:2495);at
com.gmrc.cpp.struts.actions.TransactionAction.processCpForInitTrans(Tran
sactionAction.java:2487);

Any ideas?


-----Original Message-----
From: Kevin Haskett 
Sent: Monday, November 29, 2010 4:42 PM
To: Kevin Haskett; 'EclipseLink User Discussions'
Subject: RE: [eclipselink-users] Question on initial "field values"

So I tried adding some code to the postMerge event,
event.updateAttributeWithObject("dirty", Boolean.FALSE);

But unfortunately I get a null pointer error. Is this because the
attribute is a boolean and not a full fledged object or is it because
its not a true field?

Thanks

-----Original Message-----
From: Kevin Haskett 
Sent: Monday, November 29, 2010 11:53 AM
To: eclipselink-users@xxxxxxxxxxx
Subject: RE: [eclipselink-users] Question on initial "field values"

I have tried adding code to the postMerge event, but this seems like it
is too late in the process.  Is there an event that would fire when the
record was initially read?

-----Original Message-----
From: eclipselink-users-bounces@xxxxxxxxxxx
[mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of James
Sutherland
Sent: Wednesday, November 24, 2010 9:32 AM
To: eclipselink-users@xxxxxxxxxxx
Subject: Re: [eclipselink-users] Question on initial "field values"


Have you marked the fields as @Transient?

For the existing object, were these fields set previously?  They may
still
have the existing values from the persistence context, or shared cache.
If
you do not want them cached you can clear them using a descriptor merge
event, or instantiation copy policy.



khaskett wrote:
  
I have a domain object that extends a "base domain" object. This base
domain object has some Boolean fields that aren't fields on the table
but are there to track certain changes that might occur during the
lifetime of the domain object.  It seems fine when I do a "new" on the
object the fields are defaulted to "false" correctly, but when I do a
find on an existing object, the values for these tracking fields seem
    
to
  
be mixed.



abstract class BaseBomainClass {



private Boolean trackingfield;



setTrackingfield(Boolean){..



getTrackingField()..



}



public class DomainClass extends BaseDomainClass {

...

}



How are these field values set?



Thanks

Kevin


This message (including any attachments) is intended only for
the use of the individual or entity to which it is addressed and
may contain information that is non-public, proprietary,
privileged, confidential, and exempt from disclosure under
applicable law or may constitute as attorney work product.
If you are not the intended recipient, you are hereby notified
that any use, dissemination, distribution, or copying of this
communication is strictly prohibited. If you have received this
communication in error, notify us immediately by telephone and
(i) destroy this message if a facsimile or (ii) delete this message
immediately if this is an electronic communication.

Thank you.


    

-----
http://wiki.eclipse.org/User:James.sutherland.oracle.com James
Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink ,

http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
Blog:  http://java-persistence-performance.blogspot.com/ Java
Persistence
Performance 
  

Back to the top