Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Why does weaving prevent initalization of class variable
icon5.gif  Why does weaving prevent initalization of class variable [message #500151] Wed, 25 November 2009 08:36 Go to next message
habakuk  is currently offline habakuk Friend
Messages: 32
Registered: October 2009
Member
Hello people!

I found a strange behaviour when using weaving with inheritance. The class variables of the abstract superclass do not get initialized, no matter what I do. My example shows the class AbstractDV with the field changeSupport. I try to initialize it directly in the header and also in the constructor of the class. But it is always null and then causes a NPE when I call addPropertyChangeListener. The problem goes away when I turn off weaving.

@MappedSuperclass
public abstract class AbstractDV implements Serializable,PropertyChangeListener  {
	private static final long serialVersionUID = 1L;
	
	@Transient
	protected PropertyChangeSupport changeSupport = new PropertyChangeSupport(this); ;

        // constructor
        public AbstractDV() {
       	       changeSupport = new PropertyChangeSupport(this);    	
        }
	
	public void addPropertyChangeListener(String propertyName,
			PropertyChangeListener listener) {
		changeSupport.addPropertyChangeListener(propertyName, listener);
	}

...

}


@Entity
@Table(name="DV")
public class DV extends AbstractDV implements Serializable  {
...
       public DV() {
		super();
	}
...
}
	


I thought that weaving is completly transparent. But it looks like there is something happening inside that I don't know. How can the variable changeSupport ever be null? Calling new DV() should alway initialize the variable, or am I wrong?

Thanks
Re: Why does weaving prevent initalization of class variable [message #500521 is a reply to message #500151] Thu, 26 November 2009 14:23 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

This was a bug in weaving, but it was fixed in the 2.0 stream, the latest 2.0 build should not have the issue.

A workaround without the fix is to switch to lazy initializing the variable in its get method.

You can also just disable internal weaving (this still allows lazy, etc.)

"eclipselink.weaving.internal"="false"


James : Wiki : Book : Blog : Twitter
Re: Why does weaving prevent initalization of class variable [message #500634 is a reply to message #500521] Fri, 27 November 2009 09:15 Go to previous message
habakuk  is currently offline habakuk Friend
Messages: 32
Registered: October 2009
Member
James wrote on Thu, 26 November 2009 09:23
This was a bug in weaving, but it was fixed in the 2.0 stream, the latest 2.0 build should not have the issue.



Alright. Thought I was already using the latest build (M13 as far as I remember). I will try a newer build.

Quote:

A workaround without the fix is to switch to lazy initializing the variable in its get method.



I'm doing that already. This seems to work.

Quote:

You can also just disable internal weaving (this still allows lazy, etc.)

"eclipselink.weaving.internal"="false"



Thanks James!
Previous Topic:creating history records - potential clock issues
Next Topic:Virtual columns (@Formula of Hibernate)
Goto Forum:
  


Current Time: Tue Mar 19 08:11:13 GMT 2024

Powered by FUDForum. Page generated in 0.02220 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top