Hello all,
I have been working with axis2 for last two weeks and trust me, it's a roller coaster ride for me. The amount of time I spent on figuring out the issues made me to write this blog. Hope someone finds this helpful.
Problem:
While integrating axis2 with hibernate I encountered this error. org.hibernate.mappingnotfoundexception requested resource *.hbm.xml not found. I placed the *.hbm.xml files in all various possible locations but could not succeed. No matter where I put it I kept on getting the same error.
Solution:
My Environment: Axis2(1.5.4), Tomcat 7, Java 6, Mac OS X
The solution for the problem is simple but the reason to find the solution took time because we have to look at the problem with a different perspective. The cause for this problem is not just the location but also the way we are trying to access it.
Step 1: Adding the resource files to appropriate location
All the mapping files should go into axis2/WEB-INF/classes (assuming you have webapp as axis2). I had a bunch of files to load so I made my *.hbm.xml files into a file named "mapping.jar" and placed it in the directory. check the below figure for reference
Step 2: Accessing the added resource files
This part is what I was missing for a long time. I thought adding files in the appropriate location will do but that's not the case. This I don't like about axis2. The problem is axis2 treats the resources under it's ambit are exclusively meant only for it. The problem comes when hibernate tries to locate these files under axis' location. It has no access to the location where the mapping files actually resides. For that we should we should build the session factory in the following fashion.
//To load resource for third party residing in axis, in this case the third party is hibernate.
Configuration config = new Configuration();
MessageContext msgCtx = MessageContext.getCurrentMessageContext();
AxisService myService = msgCtx.getAxisService();
config.addJar(new File(
myService.getClassLoader().getResource("mapping.jar").getFile()));
config.buildSessionFactory();
addJar will add *.hbm.xml files.
With these, it started working :)
Thanks,
Lokee
I have been working with axis2 for last two weeks and trust me, it's a roller coaster ride for me. The amount of time I spent on figuring out the issues made me to write this blog. Hope someone finds this helpful.
Problem:
While integrating axis2 with hibernate I encountered this error. org.hibernate.mappingnotfoundexception requested resource *.hbm.xml not found. I placed the *.hbm.xml files in all various possible locations but could not succeed. No matter where I put it I kept on getting the same error.
Solution:
My Environment: Axis2(1.5.4), Tomcat 7, Java 6, Mac OS X
The solution for the problem is simple but the reason to find the solution took time because we have to look at the problem with a different perspective. The cause for this problem is not just the location but also the way we are trying to access it.
Step 1: Adding the resource files to appropriate location
All the mapping files should go into axis2/WEB-INF/classes (assuming you have webapp as axis2). I had a bunch of files to load so I made my *.hbm.xml files into a file named "mapping.jar" and placed it in the directory. check the below figure for reference
Step 2: Accessing the added resource files
This part is what I was missing for a long time. I thought adding files in the appropriate location will do but that's not the case. This I don't like about axis2. The problem is axis2 treats the resources under it's ambit are exclusively meant only for it. The problem comes when hibernate tries to locate these files under axis' location. It has no access to the location where the mapping files actually resides. For that we should we should build the session factory in the following fashion.
//To load resource for third party residing in axis, in this case the third party is hibernate.
Configuration config = new Configuration();
MessageContext msgCtx = MessageContext.getCurrentMessageContext();
AxisService myService = msgCtx.getAxisService();
config.addJar(new File(
myService.getClassLoader().getResource("mapping.jar").getFile()));
config.buildSessionFactory();
addJar will add *.hbm.xml files.
With these, it started working :)
Thanks,
Lokee