geronimo-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From MoleSon <sascha.gebha...@t-online.de>
Subject ClassCastException when using a self written TypeConverter
Date Thu, 05 Jul 2007 12:34:52 GMT

Hi!

I have an EAR file that I want to deploy in Geronimo.
I use some CMP Beans there and some of these need a self written
TypeConverter, which looks the following (it implements the TypeConverter
Interface from the tranql-jar file that geronimo uses):
package mypackage;
import java.sql.Timestamp;
import java.util.Date;
import org.tranql.sql.TypeConversionException;
import org.tranql.sql.TypeConverter;
public class MyTypeConverter implements TypeConverter {
	static final long serialVersionUID = 0L;
	public static final MyTypeConverter CONVERTER = new MyTypeConverter();
	public SaschasTypeConverter() {
	}	
	public Object convertJavaToSQLType(Object obj)
			throws TypeConversionException {
		Object returnObj = obj;
		if (obj == null) {
			return null;
		} else if (obj instanceof Boolean)
			returnObj = ((Boolean) obj).equals(Boolean.TRUE)
					? new Integer(0)
					: new Integer(1);
		else if (obj instanceof Date)
			returnObj = new Timestamp(((Date) obj).getTime());
		else
			throw new TypeConversionException(
					"No conversion possible for Java Type: " + obj.getClass());
		return returnObj;
	}
	public Object convertSQLToJavaType(Object obj)
			throws TypeConversionException {
		Object returnObj = obj;
		if (obj == null) {
			return null;
		} else if (obj instanceof Integer)
			returnObj = ((Integer) obj).equals(new Integer(0))
					? Boolean.TRUE
					: Boolean.FALSE;
		else if (obj instanceof Timestamp)
			returnObj = new Date(((Timestamp) obj).getTime());
		else
			throw new TypeConversionException(
					"No conversion possible for SQL Type: " + obj.getClass());
		return returnObj;
	}
}

The deployment for the Bean I have problems with looks like this:
<entity>
	<ejb-name>MyEntityBean</ejb-name>
	<table-name>TABLE</table-name>
	<cmp-field-mapping>
		<cmp-field-name>row1</cmp-field-name>
		<cmp-field-class>java.lang.String</cmp-field-class>
		<table-column>ROW1</table-column>
	</cmp-field-mapping>
	<cmp-field-mapping>
		<cmp-field-name>row2</cmp-field-name>
		<cmp-field-class>java.lang.String</cmp-field-class>
		<table-column>ROW2</table-column>
	</cmp-field-mapping>
		<cmp-field-mapping>
		<cmp-field-name>row3</cmp-field-name>
		<cmp-field-class>java.lang.Integer</cmp-field-class>
		<table-column>CUST_COUNTRY</table-column>
		<sql-type>ROW3</sql-type>
	</cmp-field-mapping>
		<cmp-field-name>row4</cmp-field-name>
		<cmp-field-class>java.lang.Boolean</cmp-field-class>
		<table-column>ROW4</table-column>
		<sql-type>INTEGER</sql-type>
		<type-converter>mypackage.MyTypeConverter</type-converter>
	</cmp-field-mapping>
	<cmp-field-mapping>
		<cmp-field-name>row5</cmp-field-name>
		<cmp-field-class>java.util.Date</cmp-field-class>
		<table-column>ROW5</table-column>
		<sql-type>TIMESTAMP</sql-type>
		<type-converter>mypackage.MyTypeConverter</type-converter>
	</cmp-field-mapping>
	<resource-ref>
		<ref-name>jdbc/MyDataBase</ref-name>
		<resource-link>mydatabase</resource-link>
	</resource-ref
>
</entity>

So long everything looks fine to me, but when I deploy my Application I get
the following exception:
 	
Deployment failed:
Could not deploy module
Show full details

Could not deploy module
org.apache.geronimo.common.DeploymentException: Could not deploy module
	...
Caused by: org.apache.geronimo.common.DeploymentException: Cannot create
type converter mypackage.MyTypeConverter
	at
org.openejb.deployment.SchemataBuilder.processEnterpriseBeans(SchemataBuilder.java:436)
	... 32 more
Caused by: java.lang.ClassCastException: mypackage.MyTypeConverter
	at
org.openejb.deployment.SchemataBuilder.processEnterpriseBeans(SchemataBuilder.java:434)
	... 33 more

I had a look at the geronimo source code and notices that the Exception is
thrown at these lines in the ScemataBuilder:
try
{
	Class typeConverterClass = cl.loadClass(mapping.getTypeConverter().trim());
	typeConverter = (TypeConverter)typeConverterClass.newInstance();
}
catch(Exception e)
{
	throw new DeploymentException("Cannot create type converter " +
mapping.getTypeConverter(), e);
}

My problem: I have absolutely no Idea, why Geronimo cannot cast
MyTypeConverter to a generic TypeConverter... I assume that it has anything
to do with the ClassLoader Geronimo uses, but I don't see any possible
solution for me... 

I would really be pleased if anybody could help me with this problem.
Thx, Sascha
-- 
View this message in context: http://www.nabble.com/ClassCastException-when-using-a-self-written-TypeConverter-tf4029440s134.html#a11445617
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Mime
View raw message