Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » RCP / Spring JPA - Need Example
RCP / Spring JPA - Need Example [message #461505] Wed, 10 January 2007 22:12 Go to next message
Eclipse UserFriend
Originally posted by: shinglj.nationwide.com

Good Day All,

I would like to hook up Spring JPA (Toplink) to a simple RCP application I am developing.

I have a swing app that I am converting to RCP.

I used -javaagent:spring-agent.jar. When I added it to the launcher, . . . it appeared to ignore it.

So, I am looking for a very simple example. That I can pattern after. Can anyone help.

Thanks in advance.

Jim
Re: RCP / Spring JPA - Need Example [message #461538 is a reply to message #461505] Thu, 11 January 2007 17:23 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mbayly.telus.net

I had similar issues. I tracked it down to class loading issues with the InstrumentationSavingAgent. The instance of this class executed by the launcher saves off a copy of the java.lang.instrumentation.Instrumentation object using a static. However, when the InstrumentationSavingAgent is later loaded by Spring to set up the LoadTimeWeaver, it gets loaded by a different class loader hence the java.lang.instrumentation.Instrumentation object is not available.

To get around this I made sure there were no copies of InstrumentationSavingAgent in the other Spring Jars (I think there is a copy in spring.jar, but if you use the modular Spring jars in your RCP app e.g. spring-beans.jar, spring-core.jar etc you should be okay), and do not include spring-agent.jar in your spring plug-in that your app plug-ins are dependent on.

Then to make your app see the InstrumentationSavingAgent from spring-agent.jar referenced by your launcher you need to add an appropriate buddy policy to your spring/app plugin.

Eclipse-BuddyPolicy: app

I bundled the spring jars I needed as a separate plug-in which I then reference from my app, so I added the above buddy policy to my spring plug-in. However, if you are just including the spring jars in a single RCP App plugin then you would need to add it to your app plug-in's manifest.

Let me know if this doesn't work for you. There could be something else I've forgotten to mention.

I've been through a lot of hair pulling trying to get various aspects of Spring JPA to work with Eclipse RCP, in particular making the use of Spring and JPA very modular as my app contains many plug-ins each of which contribute some configuration to Spring and JPA, so if you run into other issues let me know and I'll try and help if I can.

Cheers
Martin
Re: RCP / Spring JPA - Need Example [message #461599 is a reply to message #461538] Sat, 13 January 2007 05:10 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: shinglj.nationwide.com

Boy can I relate on the Hair Pulling ;-)

I could have messed it up, . . . not sure but it didn't work.

I have myApp(RCP) and myAppLibs(Spring,Toplink)

myApp has Eclipse-RegisteredBuddy: myAppLibs

myAppLibs has Eclipse-BuddyPolicy: registered

MyAppLibs has no references to InstumentationSavingAgent

This part is throwing me a little: "Then to make your app see the InstrumentationSavingAgent from spring-agent.jar referenced by your launcher you need to add an appropriate buddy policy to your spring/app plugin. "

So do I add spring-agent.jar to myApp as a library and add Eclipse-PolicyBuddy: app to myApp?

I tried this add it didn't work.

This is killing me. You would think it should be easier than this.
Re: RCP / Spring JPA - Need Example [message #461605 is a reply to message #461505] Sat, 13 January 2007 08:27 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mbayly.telus.net

> So do I add spring-agent.jar to myApp as a library
> and add Eclipse-PolicyBuddy: app to myApp?

I wasn't sure exactly what you meant by adding spring-agent.jar to myApp as a library. Essentially, you only want this jar to be seen by the launcher. You don't want it to be visible directly by your plugins, otherwise when Spring tries to access InstrumentationSavingAgent, it will access a new instance which does not have the java.lang.instrumentation.Instrumentation object cached.

When I'm running from Eclipse, I just have a spring-agent.jar file in the root of my project or my workspace - doesn't really matter - you just need to make sure it's not in the class path of your myApp plugin or your myAppLibs plugin. Probably a good way to check that it definitely isn't in your classpath is to try and add a reference to InstrumentationSavingAgent in one of your plugin source files.

e.g. private InstrumentationSavingAgent agent;

If organizing imports finds that class then it's still visible and something is wrong with your setup.


I add the following VM arg to my launch configuration for running my RCP app:

-javaagent:${project_loc}/spring-agent.jar

I think you can add

Eclipse-BuddyPolicy: app

to either your myApp plugin or your myAppLibs plugin. I used to have it added to my RCP app main plugin but I recently switched it to the library plugin containing Spring because that seemed more logical given that its the Spring classes that want to see the spring-agent.jar classes. I think either may work because your myApp plugin is registered as a buddy of your myAppLibs plugin anyway.

I assume in your post below the reference to 'Eclipse-PolicyBuddy' (rather than Eclipse-BuddyPolicy) is just a typo in your post. I'm guessing Eclipse would complain if that was in the manifest.mf.

Hope this helps - let me know if you still have trouble - I'd be happy to take a look at your project if you do - I need more people playing with Spring JPA and Eclipse RCP so I'm not the only one going up this hill!
Re: RCP / Spring JPA - Need Example [message #461609 is a reply to message #461605] Sat, 13 January 2007 15:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: shinglj.nationwide.com

Ah, That additional clarification helped. I am now past the not being able to find the spring-agent.jar. Unfortunately, . . . I had to full path it in the launcher for it to find it. Not sure why.

But, I am down to a different issue that I need to validate I haven't screwed up somehow in all of my experimenting.

Thanks for the Help.

I too am very interest in RCP / Spring JPA. what a great combination. I am considering adding SWTBinding from Sourceforge with HandyAspects. In the swing app I used JGoodies Bindings with HandyAspects and it was VERY COOL.

eclipse.buildId=unknown
java.version=1.5.0_09
java.vendor=Sun Microsystems Inc.
BootLoader constants: OS=win32, ARCH=x86, WS=win32, NL=en_US
Framework arguments: -application biz.genuinesolutions.sam.application
Command-line arguments: -application biz.genuinesolutions.sam.application -data C:\Work\SAM2/../runtime-EclipseApplication -dev file:C:/Work/SAM2/.metadata/.plugins/org.eclipse.pde.core/JP A/dev.properties -os win32 -ws win32 -arch x86

!ENTRY org.eclipse.osgi 4 0 2007-01-13 10:43:15.094
!MESSAGE Application error
!STACK 1
org.springframework.dao.InvalidDataAccessApiUsageException: An exception occured while creating a query in EntityManager; nested exception is java.lang.IllegalArgumentException: An exception occured while creating a query in EntityManager
Caused by: java.lang.IllegalArgumentException: An exception occured while creating a query in EntityManager
at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImp l.createQuery(EntityManagerImpl.java:194)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.orm.jpa.ExtendedEntityManagerCreator$Ext endedEntityManagerInvocationHandler.invoke(ExtendedEntityMan agerCreator.java:283)
at $Proxy11.createQuery(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.springframework.orm.jpa.JpaTemplate$CloseSuppressingInvo cationHandler.invoke(JpaTemplate.java:400)
at $Proxy12.createQuery(Unknown Source)
at org.springframework.orm.jpa.JpaTemplate$9.doInJpa(JpaTemplat e.java:307)
at org.springframework.orm.jpa.JpaTemplate.execute(JpaTemplate. java:191)
at org.springframework.orm.jpa.JpaTemplate.executeFind(JpaTempl ate.java:158)
at org.springframework.orm.jpa.JpaTemplate.find(JpaTemplate.jav a:305)
at biz.genuinesolutions.sam.model.dao.JpaTypeDao.findByName(Jpa TypeDao.java:17)
at biz.genuinesolutions.sam.Application.run(Application.java:69 )
at org.eclipse.core.internal.runtime.PlatformActivator$1.run(Pl atformActivator.java:78)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .runApplication(EclipseAppLauncher.java:92)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher .start(EclipseAppLauncher.java:68)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:400)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseS tarter.java:177)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAcce ssorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMe thodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.eclipse.core.launcher.Main.invokeFramework(Main.java:336 )
at org.eclipse.core.launcher.Main.basicRun(Main.java:280)
at org.eclipse.core.launcher.Main.run(Main.java:977)
at org.eclipse.core.launcher.Main.main(Main.java:952)
Caused by: Exception [TOPLINK-8034] (Oracle TopLink Essentials - 9.1 (Build b31)): oracle.toplink.essentials.exceptions.EJBQLException
Exception Description: Error compiling the query [select t from Type t where t.name = ?1]. Unknown abstract schema type [Type].
at oracle.toplink.essentials.exceptions.EJBQLException.unknownA bstractSchemaType(EJBQLException.java:479)
at oracle.toplink.essentials.internal.parsing.ParseTreeContext. classForSchemaName(ParseTreeContext.java:148)
at oracle.toplink.essentials.internal.parsing.SelectNode.getCla ssOfFirstVariable(SelectNode.java:341)
at oracle.toplink.essentials.internal.parsing.SelectNode.getRef erenceClass(SelectNode.java:329)
at oracle.toplink.essentials.internal.parsing.ParseTree.getRefe renceClass(ParseTree.java:452)
at oracle.toplink.essentials.internal.parsing.ParseTree.adjustR eferenceClassForQuery(ParseTree.java:88)
at oracle.toplink.essentials.internal.parsing.EJBQLParseTree.po pulateReadQueryInternal(EJBQLParseTree.java:112)
at oracle.toplink.essentials.internal.parsing.EJBQLParseTree.po pulateQuery(EJBQLParseTree.java:93)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImp l.buildEJBQLDatabaseQuery(EJBQueryImpl.java:204)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImp l.buildEJBQLDatabaseQuery(EJBQueryImpl.java:174)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImp l.buildEJBQLDatabaseQuery(EJBQueryImpl.java:138)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImp l. <init>(EJBQueryImpl.java:99)
at oracle.toplink.essentials.internal.ejb.cmp3.base.EJBQueryImp l. <init>(EJBQueryImpl.java:84)
at oracle.toplink.essentials.internal.ejb.cmp3.EJBQueryImpl.<init >(EJBQueryImpl.java:71)
at oracle.toplink.essentials.internal.ejb.cmp3.EntityManagerImp l.createQuery(EntityManagerImpl.java:189)
... 31 more

Any Thoughts?

The TType id Setup with @Entity
Re: RCP / Spring JPA - Need Example [message #461615 is a reply to message #461609] Sat, 13 January 2007 19:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: mbayly.telus.net

Sorry, not sure about requirement to enter full path to spring-agent.jar - do you mean when running it as an exported app? I guess I'm giving the full path when running in Eclipse by using the ${project_loc} variable. Eclipse probably expands that to a full path. Maybe I have not tried as exported product yet.

I'd be interested to hear how you find the SWTBinding. I ummed and ahhed about that and in the end chose to go with the JFace 3.2 provisional binding even though I'm probably going to have to convert a lot of stuff when 3.3 comes out. But I guess if you were already familiar with JGoodies, using SWTBinding makes more sense - for me it was a clean sheet.

Thanks for the tip about HandyAspects. I had not come across that before, but I was just thinking a couple of weeks back that I need to look into aspects as a way of registering my POJOs for property change support - so I'll take a look at HandyAspects.

Cheers
Martin
Re: RCP / Spring JPA - Need Example [message #461964 is a reply to message #461615] Fri, 19 January 2007 02:20 Go to previous message
Eclipse UserFriend
Originally posted by: shinglj.nationwide.com

Hey Martin,

I've had more time and I have good news and bad news.

Good News:
I was able to get the HandyAspects working in a simple RCP / Aspect J application without Spring JPA

Bad News:
So far, I haven't been able to get all three pieces working together RCP / Spring JPA / Aspectj (HandyAspects). When I add Handy Aspects to the Mix, it looks as if they aren't being woven. It worked in the swing app but I am have issues with it in the RCP App.

I am trying to track it down but it doesn't look good so far. It could be something I am doing wrong in configuration of Spring and AspectJ.

I'll keep you informed.
Previous Topic:Clicking the "X" close button to close the RCP app will not close the application. it leav
Next Topic:how i change another view?
Goto Forum:
  


Current Time: Tue Apr 23 15:34:51 GMT 2024

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

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

Back to the top