Colin,
The error message is pretty clear. It says it can't convert a Calendar
object into a SQL type. So, you need to do this for it.
What I would do is make a private CMP field (setter and getter) storing a
long in the DB. This long should be the cal.getTime().getTime().
You should provide a public getter and setter, which call the private
version. Something like:
public abstract long getPrivateTime();
public abstract void setPrivateTime(long timeInMilliseconds);
public Calendar getTime() {
long t = getPrivateTime();
return new Calendar( new Date( t ));
}
public void setTime( Calendar cal) {
setPrivateTime( cal.getTime().getTime());
}
You'll need to set up the XDoclet tags appropriately. Just don't export
the privateTime stuff to the local interface class.
Ciao,
Jonathan O'Connor
Development Manager
XCOM Dublin
Phone: +353 1 872 3305
Mobile: +353 86 824 0736
"Colin McFarlane" <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
11.06.2003 09:34
Please respond to jboss-user
To: <[EMAIL PROTECTED]>
cc:
Subject: [JBoss-user] Using java.util.Calendar with CMP
I seem to be unable to use a CMP bean that has persistent fields of type
java.util.Calendar with a mySQL database. (I am using XDoclet to generate
the bean). I can create the bean class and deploy it okay and the table is
created with the correct SQL columns. But when I try to create an instance
of the bean I get a ClassCastException (see below). I can use a
java.util.Date okay but I'm trying to integrate the bean with an Axis
service which requires Calendar not Date.
I converted the fields to dates and tried to create extra methods in the
bean that take/return a calendar object and set/get the date fields but
this causes the value objects to fail at compilation as the data object
doesn't contain all the methods. Besides I would prefer not to have an
extra layer converting between date & calendar.
Does anyone have any suggestions?
2003-06-08 13:05:14,795 ERROR [org.jboss.ejb.plugins.LogInterceptor]
EJBException, causedBy:
javax.ejb.CreateException: Could not create entity:javax.ejb.EJBException:
Internal error setting parameters for field test; CausedByException is:
Cannot convert class java.util.GregorianCalendar to SQL type requested due
to java.lang.ClassCastException - null
at
org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractVendorCreateCommand.insertEntity(JDBCAbstractVendorCreateCommand.java:136)
at
org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractVendorCreateCommand.execute(JDBCAbstractVendorCreateCommand.java:76)
at
org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:569)
at
org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:225)
at
org.jboss.resource.connectionmanager.CachedConnectionInterceptor.createEntity(CachedConnectionInterceptor.java:270)
at org.jboss.ejb.EntityContainer.createLocalHome(EntityContainer.java:571)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at
org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContainer.java:998)
at
org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:88)
at
org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySynchronizationInterceptor.java:188)
at
org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invokeHome(CachedConnectionInterceptor.java:215)
at
org.jboss.ejb.plugins.AbstractInterceptor.invokeHome(AbstractInterceptor.java:88)
at
org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInterceptor.java:91)
at
org.jboss.ejb.plugins.EntityLockInterceptor.invokeHome(EntityLockInterceptor.java:61)
at
org.jboss.ejb.plugins.EntityCreationInterceptor.invokeHome(EntityCreationInterceptor.java:28)
at
org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:88)
at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:243)
at
org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:74)
at
org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.java:92)
at
org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:120)
at
org.jboss.ejb.plugins.ProxyFactoryFinderInterceptor.invokeHome(ProxyFactoryFinderInterceptor.java:93)
at
org.jboss.ejb.EntityContainer.internalInvokeHome(EntityContainer.java:477)
at org.jboss.ejb.Container.invoke(Container.java:694)
at
org.jboss.ejb.plugins.local.BaseLocalProxyFactory.invokeHome(BaseLocalProxyFactory.java:272)
at
org.jboss.ejb.plugins.local.LocalHomeProxy.invoke(LocalHomeProxy.java:110)
at $Proxy40.create(Unknown Source)
at com.incito.mirror.ejb.TicketMasterBean.issue(TicketMasterBean.java:100)
at com.incito.mirror.ejb.TicketMasterBean.issue(TicketMasterBean.java:61)
<snipped/>
-------------------------------------------------------
This SF.net email is sponsored by: Etnus, makers of TotalView, The best
thread debugger on the planet. Designed with thread debugging features
you've never dreamed of, try TotalView 6 free at www.etnus.com.
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user