Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Implementing post merge events
Implementing post merge events [message #907981] Tue, 04 September 2012 13:52 Go to next message
Amit B is currently offline Amit BFriend
Messages: 14
Registered: July 2012
Junior Member
Hi,
Getting a crash when trying to implement post merge event. My application defines a custom annotation to maintain a cache on the client side. The application is also implementing a post merge event so that some transient data in each entity can be merge post persist or post merge calls. The event listener class is defines using the annotation @EntityListeners(value = {MyEventListener.class}) for each of the entities. When the application calls getAnnotation() method on the same entity to get the custom annotation the client crashes with the stack trace shown below -
java.lang.ArrayStoreException: sun.reflect.annotation.TypeNotPresentExceptionProxy
	at sun.reflect.annotation.AnnotationParser.parseClassArray(Unknown Source)
	at sun.reflect.annotation.AnnotationParser.parseArray(Unknown Source)
	at sun.reflect.annotation.AnnotationParser.parseMemberValue(Unknown Source)
	at sun.reflect.annotation.AnnotationParser.parseAnnotation(Unknown Source)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations2(Unknown Source)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations(Unknown Source)
	at java.lang.Class.initAnnotationsIfNecessary(Unknown Source)
	at java.lang.Class.getAnnotation(Unknown Source)
	at com.easyautomation.feedoffice.FOEDataCache.initializeInternalListeners(FOEDataCache.java:34)
	at com.easyautomation.DataCache.<init>(DataCache.java:20)
	at com.easyautomation.feedoffice.FOEDataCache.<init>(FOEDataCache.java:16)
	at com.easyautomation.feedoffice.ClientDataCache.<init>(ClientDataCache.java:163)
	at com.easyautomation.feedoffice.ClientDataCache.<clinit>(ClientDataCache.java:171)
	at com.easyautomation.feedoffice.forms.FOENumericTextFieldFactory.<init>(FOENumericTextFieldFactory.java:14)
	at com.easyautomation.feedoffice.forms.FOENumericTextFieldFactory.getInstance(FOENumericTextFieldFactory.java:24)
	at com.easyautomation.feedoffice.FOEApplet.displayMenu(FOEApplet.java:282)
	at com.easyautomation.feedoffice.FOEApplet.loginWindowClosed(FOEApplet.java:215)
	at com.easyautomation.feedoffice.forms.AppLogin.submitButtonClicked(AppLogin.java:49)
	at com.easyautomation.feedoffice.forms.AppLogin.performSubmitAction(AppLogin.java:106)
	at com.easyautomation.forms.TitledInternalFrame$2.actionPerformed(TitledInternalFrame.java:88)
	at javax.swing.SwingUtilities.notifyAction(Unknown Source)
	at javax.swing.JComponent.processKeyBinding(Unknown Source)
	at javax.swing.JComponent.processKeyBindings(Unknown Source)
	at javax.swing.JComponent.processKeyEvent(Unknown Source)
	at java.awt.Component.processEvent(Unknown Source)
	at java.awt.Container.processEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.KeyboardFocusManager.redispatchEvent(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(Unknown Source)
	at java.awt.DefaultKeyboardFocusManager.dispatchEvent(Unknown Source)
	at java.awt.Component.dispatchEventImpl(Unknown Source)
	at java.awt.Container.dispatchEventImpl(Unknown Source)
	at java.awt.Component.dispatchEvent(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$000(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.awt.EventQueue$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)

Note that this crash only happens when I define the @EntityListeners. If I comment this out everything works fine. It looks an issue with reflection. Is their any other jar file besides eclipselink and jpa 2.0 that needs to be included to implement postmerge events ?. Any help is appreciated.

Thanks
Re: Implementing post merge events [message #908078 is a reply to message #907981] Tue, 04 September 2012 16:57 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1389
Registered: July 2009
Senior Member
Searching for the error suggests that the problem is that the MyEventListener.class isn't available to the classloader for the code that is looking for your annotations. Check that the class is available possibly in the same jar as your entities. If that doesn't help, try removing your custom annotations and see if it works if loaded just through the persistence unit.

Best Regards,
Chris
Re: Implementing post merge events [message #908468 is a reply to message #908078] Wed, 05 September 2012 12:37 Go to previous message
Amit B is currently offline Amit BFriend
Messages: 14
Registered: July 2012
Junior Member
Still getting the crash. I think you are correct that the class loader is not able to find the MyEventListner class, just cant figure out why. I forgot to mention that when the application is run through the Netbeans debugger everything works fine. There is no crash. Only when running the client outside the debugger the application crashes.

Here is the pseudo-code
Entity.java
------------
@MyCustomAnnotation(classes = {MyCache.class})
@Entity
@EntityListeners(value = {MyEventListener.class}) 
@Table(name = "myTable")
public class Entity {

	public void postMerge() {
		//Do something
	}

}
MyEventListener.java
----------------------------
public class MyEventListener extends DescriptorEventAdapter {
    @Override
    public void postMerge(DescriptorEvent event) {
		//Object origObject = event.getOriginalObject();
		//Object srcObject = event.getObject();
		//srcObject.postMerge()
	}
}

DataCache.java
--------------
@Override
public void initializeInternalListeners() {
		Class klass = SerializableEntity.getClassForEntityType(i, false);
		if (klass != null) {
		 try {
			MyCustomAnnotation annoKlass = (MyCustomAnnotation)klass.getAnnotation(MyCustomAnnotation.class);
			if (annoKlass != null) {
				Class dependentClasses[] = annoKlass.classes();
				for (Class depklass : dependentClasses) {
					addInternalListenerDependency(depklass, klass);
				}
			}
			} catch(Exception e) {
				LoggingUtil.getLogger().log(Level.INFO, "kclass name " + klass.getSimpleName());
				LoggingUtil.getLogger().log(Level.INFO, "Caught exception in initializeInternalListeners", e);
			}
		}
	}
}


Tried the following -
1. The event listner class is in the same jar as the entities.
2. Changed the position of the custom and eventlistner annotation.
3. Removed the custom annotation and it still crashed as the getAnnotation() call.

Any suggestions ?

Thanks for your help.
Previous Topic:The parameter name in the query's selection criteria does not match any parameter name defined in th
Next Topic:Error on first query
Goto Forum:
  


Current Time: Fri Apr 26 12:31:45 GMT 2024

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

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

Back to the top