问题
I have a java project that uses JPA 2/Hibernate 3.5.6 for data access and it works great on a JBoss app server. Now I am trying to run this on a Coldfusion 9 environment and I see CF 9 already has hibernate3.jar and related jars thats needed for its ORM implementation. But, I would like to use my java project as is on CF and for that, I would need the same hibenate 3.5.6 jar and related jars on CF. So, I moved all the jars that I need, created a new folder in CF and updated the jvm.config to include this new path. It worked great!! But now the concern is, will this conflict with the default Hibernate/ORM behaviour that CF9 uses. Would this result in any other issues?(class loading, conflicts etc..)?
Option 2: Also, to circumvent any "possible" issues I decided to create a webservice application, package all jars that I need and deploy it as a war file on CF9-JRun4, and it worked great. In this case I dont have to worry about clasloading because its within the web application's scope. But, I wouldn't want my calls from CF app really go through a webservice layer, when all it has to do is plainly access the database and get data back. So I would really want my Option 1(previous paragraph) to work.
So could anyone who might have worked on a similar setup before provide some insight on this. Appreciate the help!
回答1:
I'm currently working on exactly that setup (spring/hibernate/jpa app running within a CF app). The only difference is that I'm on Railo, but I've done the same thing with Adobe ColdFusion (ACF) before also. In both ACF and Railo you can definitely run into problems with bringing your own Hibernate. The consensus seems to be that you'll get away with removing/replacing ACF's Hibernate as long as you're not using it's built-in ORM functionality.
Like you, I was left looking at option 2 and not liking it very much. If you want to properly separate your Java app form the CF container you're running in, you ought to use JavaLoader. It provides a child-first classloader which can load up the JARs in your app and will resolve classes and resources from there in preference to going up the chain to the classes provided in ACF.
The only gotcha I'll mention is that a lot of modern frameworks (Spring in particular) use the thread context Classloader to get at resources so you may need to switch the classloader round when constructing objects from your Java code. This is covered in the JavaLoader documentation, but it's worth knowing that it's likely the cause when your code moans about not being able to load properties files from your JARs etc. I tend to create one CFC which hides the fuss of constructing the Java Objects and lets the rest of your application code stay simple. You could look at the Railo implementation of CFSpreadsheet and this class in particular for an example of that.
Hope it all works out for you
来源:https://stackoverflow.com/questions/11256691/need-suggestion-for-running-a-jpa-hibernate-java-project-on-coldfusion-9