Sounds like a class loader problem.
We use Castor in a J2EE (JBoss/Tomcat) environment. When we create an
instance of the Castor Mapping class, we use the constructor where we
can specify a class loader, as in
Mapping CASTOR_REQUEST_MAPPING = new
Mapping(some_class_of_yours.class.getClassLoader());
:
CASTOR_REQUEST_MAPPING.loadMapping(REQUEST_MAPPING_URL);
where "some_class_of_yours" is any class you choose in your WAR.
REQUEST_MAPPING_URL is the URL for your mapping file (generated via a
local entity resolver or whatever mechanism you choose).
Leo Joncas
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Sent: Friday, November 26, 2004 9:44 AM
To: [EMAIL PROTECTED]
Subject: [castor-user] Mapping exception error
Hi all,
I want to use Costor to marshal objects to XML stream in a J2EE
environment.
I have to marshal an ArrayList of MyObject entity objects. These
objects
aren't Entity Beans, but plain Java objects mapped to a database using
Hibernate.
I created a simple mapping file :
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
"http://castor.exolab.org/mapping.dtd">
<mapping>
<description>Country List mapping</description>
<class name="java.util.ArrayList"
auto-complete="true">
<map-to xml="myobjects" />
</class>
</mapping>
All works fine. I get :
<?xml version="1.0" encoding="UTF-8"?>
<myobjects>
<my-object num="1">
<attr1>Value 1-1</attr1>
<attr2>Value 1-2</attr2>
<attr3>Value 1-3</attr3>
</my-object>
<my-object num="2">
<attr1>Value 2-1</attr1>
<attr2>Value 2-2</attr2>
<attr3>Value 2-3</attr3>
</my-object>
</myobjects>
Now I wanted to change the mapping to remove some attributes from the
resulting XML file. I modified the mapping file like this :
<!DOCTYPE mapping PUBLIC "-//EXOLAB/Castor Mapping DTD Version 1.0//EN"
"http://castor.exolab.org/mapping.dtd">
<mapping>
<description>Country List mapping</description>
<class name="java.util.ArrayList"
auto-complete="true">
<map-to xml="myobjects" />
</class>
<class name="com.myorg.myproject.entities.MyObject"
auto-complete="true">
<map-to xml="myobject" />
<field name="attr1" transient="true"/>
<field name="attr3" transient="true"/>
</class>
</mapping>
When I try to marshal using this mapping, I get the error message :
org.exolab.castor.mapping.MappingException: Could not find the class
com.myorg.myproject.entities.MyObject
at
org.exolab.castor.mapping.loader.MappingLoader.createDescriptor(MappingL
oader.java:340)
...
I'm sure of the package path. Are there restrictions on the Castor use
in
a J2EE environment ?
Any suggestion ?
Regards
--
A. ROY
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user
-----------------------------------------------------------
If you wish to unsubscribe from this mailing, send mail to
[EMAIL PROTECTED] with a subject of:
unsubscribe castor-user