aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate running outside the servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate running outside the servlet" Watch "Hibernate running outside the servlet" New topic
Author

Hibernate running outside the servlet

Chris Spierings
Greenhorn

Joined: Mar 29, 2001
Posts: 25
We are thinking about creating a java app which will run at night and not be running behind struts or any sort of servlet. The idea being that once a month the app would run at about 1AM in the morning.

Has anyone had any experience with this? Where there issues with the session with regard to hibernate?

Thanks,

Chris
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Hibernate does not require Servlets to work. It uses so-called "Plain Old Java Objects", which basically means you can use it in an container managed environment, with a framework like Spring, in a Servlet environment or with a normal Java application. Basically, any way you like.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Chris Spierings
Greenhorn

Joined: Mar 29, 2001
Posts: 25
We've finally gotten to the point of trying to run Hibernate outside the servlet and we are experiencing issues with the hbm files being found.

When running a web app using hibernate you end up having a bunch of initialization occur when hibernate is used. I'm wondering if that is the issue we are running into trying to run this via a main method.

Has anyone else run into this sort of issue? Were you able to work through it? If so can you share how?

Thanks

Chris
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42289
    
  64
We've used Hibernate in both servlet and non-servlet environments. I don't really see why there would (or should) be a difference in terms of initialization or storage of .hbm files (which we kept in the classpath along with their respective class files in both cases). Can you elaborate a bit on why you think there is a difference?


Ping & DNS - my free Android networking tools app
Chris Spierings
Greenhorn

Joined: Mar 29, 2001
Posts: 25
The more we look at this I think its coming down to classpath issues.

We seem to be having issues with the .hbm files being found. We've even gone so far to move the hbm files on to the class path outside a jar and continue to have issues.

Here is the message we get in the WSAD console when we attempt to run in a batch mode that is to say running the code from a main method.



WSCL0100E: Exception received: java.lang.reflect.InvocationTargetException
Caused by: java.lang.ExceptionInInitializerError
at java.lang.Class.initialize(Class.java:356)
at com.amfam.isagent.codebase.persistence.IASIRDAO.getData(IASIRDAO.java:39)
at com.amfam.isagent.codebase.persistence.RegionDAO.getRegionList(RegionDAO.java:67)
at com.amfam.isagent.codebase.facade.AgentCodeBaseFacade.getAllRegions(AgentCodeBaseFacade.java:101)
at com.amfam.isagent.codebase.facade.AgentCodeBaseFacade.getAllRegionsFromXml(AgentCodeBaseFacade.java:56)
at com.amfam.isagent.agtplnacr.batchproc.builders.ReportDataBuilder.createReportTree(ReportDataBuilder.java:148)
at com.amfam.isagent.agtplnacr.batchproc.builders.ReportDataBuilder.createReportData(ReportDataBuilder.java:70)
at com.amfam.isagent.agtplnacr.batchproc.builders.ReportDataBuilder.createReport(ReportDataBuilder.java:55)
at com.amfam.isagent.agtplnacr.batch.runner.ReportDataBuilderRunner.main(ReportDataBuilderRunner.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
at java.lang.reflect.Method.invoke(Method.java:391)
at com.ibm.websphere.client.applicationclient.launchClient.createContainerAndLaunchApp(launchClient.java:644)
at com.ibm.websphere.client.applicationclient.launchClient.main(launchClient.java:426)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
at java.lang.reflect.Method.invoke(Method.java:391)
at com.ibm.ws.bootstrap.WSLauncher.run(WSLauncher.java:222)
at java.lang.Thread.run(Thread.java:813)
Caused by: com.amfam.isagent.codebase.persistence.HibernateUtilityException: Configuration problem: Resource: /com/amfam/isagent/codebase/entities/SALE_REGN.hbm.xml not found
at com.amfam.isagent.codebase.persistence.HibernateUtility.<clinit>(HibernateUtility.java:59)
at java.lang.Class.initializeImpl(Native Method)
at java.lang.Class.initialize(Class.java:350)
at com.amfam.isagent.codebase.persistence.IASIRDAO.getData(IASIRDAO.java:39)
at com.amfam.isagent.codebase.persistence.RegionDAO.getRegionList(RegionDAO.java:67)
at com.amfam.isagent.codebase.facade.AgentCodeBaseFacade.getAllRegions(AgentCodeBaseFacade.java:101)
at com.amfam.isagent.codebase.facade.AgentCodeBaseFacade.getAllRegionsFromXml(AgentCodeBaseFacade.java:56)
at com.amfam.isagent.agtplnacr.batchproc.builders.ReportDataBuilder.createReportTree(ReportDataBuilder.java:148)
at com.amfam.isagent.agtplnacr.batchproc.builders.ReportDataBuilder.createReportData(ReportDataBuilder.java:70)
at com.amfam.isagent.agtplnacr.batchproc.builders.ReportDataBuilder.createReport(ReportDataBuilder.java:55)
at com.amfam.isagent.agtplnacr.batch.runner.ReportDataBuilderRunner.main(ReportDataBuilderRunner.java:15)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
at java.lang.reflect.Method.invoke(Method.java:391)
at com.ibm.websphere.client.applicationclient.launchClient.createContainerAndLaunchApp(launchClient.java:644)
at com.ibm.websphere.client.applicationclient.launchClient.main(launchClient.java:426)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:60)
at java.lang.reflect.Method.invoke(Method.java:391)
at com.ibm.ws.bootstrap.WSLauncher.run(WSLauncher.java:222)
at java.lang.Thread.run(Thread.java:813)
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


Resource: /com/amfam/isagent/codebase/entities/SALE_REGN.hbm.xml not found

Yeah you are right - its just a classpath issue. So long as that resource in in your classpath Hibernate will be happy.

Perhaps if you told us a liitle about how you package and run you application someone might spot where you are making a mistake.
[ May 25, 2006: Message edited by: Paul Sturrock ]
Chris Spierings
Greenhorn

Joined: Mar 29, 2001
Posts: 25
we've set up a project in WSAD (locally) we're just trying to get it working locally first.

In the build path for this project we include a reference to a jar file which contains all the classes which interact with the tables using hibernate. One class the hibernateUtlity references the .cfg file for hibernate. That config file references the .hbm files also within that jar.
Chris Spierings
Greenhorn

Joined: Mar 29, 2001
Posts: 25
turns out that the references to the hbm files in the cfg file had an extra slash in front of them. This meant we were looking for the hbm files in c:..../then the normal package strucutre.

Thanks for all the help.

Chris
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Glad you managed to sort it out, and thanks for taking the time to post your solution.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Hibernate running outside the servlet