Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] PersistenceObjectInstantiationPolicy.buildNewInstance null'ing out all fields of an object regardless of fields set by default-constructor

Hi all.
 
Short version:
org.eclipse.persistence.internal.descriptors.PersistenceObjectInstantiationPolicy.buildNewInstance() calls _persistence_new which seems to return an object not initialized by the default-construcotor.
 
Longer version:
I have this @Embeddable class (it's in Scala but that's not releavant:
@Embeddable
class ChangeInfo (_created: DateTime, _createdBy: User, _modified: Option[DateTime], _modifiedBy: Option[User]) extends Serializable {

        @Column(name = "created", nullable = false, updatable = false)
        @net.sf.oval.constraint.NotNull
        var created = _created

        @ManyToOne(fetch = FetchType.LAZY, optional = false)
        @JoinColumn(name = "created_by", nullable = false, updatable = false)
        @net.sf.oval.constraint.NotNull
        var createdBy = _createdBy

        @Column(name = "modified")
        var modified: Option[DateTime] = _modified

        @ManyToOne(fetch = FetchType.LAZY)
        @JoinColumn(name = "modified_by")
        private var modifiedBy: User = _modifiedBy.orNull
        def modifiedByOpt = Option(modifiedBy)
        def modifiedByOpt_=(newVal:Option[User]) = modifiedBy = newVal.orNull

        def this(_created: DateTime, _createdBy: User) {
                this(_created, _createdBy, None, None)
        }

        def this() {
                this(null, null, None, None)
        }

}
As you see the default-constructor (marked in yellow) initializes the field "modified" to None. However, org.eclipse.persistence.internal.descriptors.ObjectBuilder.buildNewInstance returns an object with all fields set to null.
 
What happens is that right before PersistenceObjectInstantiationPolicy.buildNewInstance() is called the object instantiated looks correct (because the constructor has set the "modified"-field to None):
 
(please let me know if you don't see the above inline image as it's inline base64-encoded, as my mailer creates)
 
But the problem is that buildNewInstance returns another object with all fields set to null:
 
(again, please let me know if you don't see this image)
 
This is the result of  the following in org.eclipse.persistence.internal.descriptors.PersistenceObjectInstantiationPolicy:
public Object buildNewInstance() {
    return factory._persistence_new(factory);
}
Which appearantly calls the weaved-in _persistence_new method which I have noe idea of what is doing.
 
This results in unwanted NPEs in my converters because fields are not initialized according to my constructors, which breaks the contract set by constructors.
 
Is there a way to make _persistence_new not modifiy fields set by the default-constructor?
 
Is this a result of me doing something else wrong?
 
thansk.
 
--
Andreas Joseph Krogh <andreak@xxxxxxxxxxxx>      mob: +47 909 56 963
Senior Software Developer / CTO - OfficeNet AS - http://www.officenet.no
Public key: http://home.officenet.no/~andreak/public_key.asc

Back to the top