I had already tried that approach but it doesn't work with value objects.
See the code extracts below. The data object only contains methods based on
the persistent fields.

If I use a Date in the web service implementation then I get exactly the
same class cast exception being thrown but this time by axis trying to
convert the Calendar.

I guess my ideal scenario is not to have to use java.util.Date at all. e.g.
a CMP bean generated using XDoclet with value objects that use the Calendar
class. A session bean that is able to work with the Value objects, and
publish the session bean as a web service using an XDoclet tag. I believe
that this is posisble and an XDoclet tag for this does exist - I've just not
had a chance to look into it yet. If this is the case what happens with
Calendar/Date fields, and has anyone successfully managed to get these to
interact without having to write a conversion layer for each value object by
hand?

Cheers - Colin



 Jonathan.O'Connor wrote:
> Date: Wed, 11 Jun 2003 10:47:35 +0100
> Reply-To: [EMAIL PROTECTED]
>
> 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

This is an extract of what I tried for each Calendar property:

/**
* @ejb.interface-method view-type="local"
* @ejb.value-object match="normal"
* @ejb.value-object match="light"
**/
public Calendar getDateIssued() {
    Calendar i = Calendar.getInstance();
    i.setTime(getDTIssued());
    return i;
}
/**
* @ejb.interface-method view-type="local"
* @ejb.value-object match="normal"
* @ejb.value-object match="light"
*/
public void setDateIssued( Calendar value ) {
    setDTIssued(value.getTime());
}

/**
* @ejb.persistent-field
* @ejb.persistence column-name="issued"
* jdbc-type="TIMESTAMP"
* sql-type="DATETIME"
* @jboss.persistence not-null="true"
**/
abstract protected Date getDTIssued();
abstract protected void setDTIssued( Date value );

The difficulty comes when then trying to generate value objects, as the
underlying Data object only contains the methods for the persistent fields.

[javac] Compiling 5 source files to C:\src\backup-server\target\classes
[javac]
C:\src\backup-server\target\gen-src\com\incito\mirror\interfaces\TicketData.
java:40: cannot resolve symbol
[javac] symbol : method getDateIssued ()
[javac] location: class com.incito.mirror.interfaces.TicketData
[javac] TicketLightValue.setDateIssued( getDateIssued() );
[javac] ^
[javac]
C:\src\backup-server\target\gen-src\com\incito\mirror\interfaces\TicketData.
java:43: cannot resolve symbol
[javac] symbol : method getValidFrom ()
[javac] location: class com.incito.mirror.interfaces.TicketData
[javac] TicketLightValue.setValidFrom( getValidFrom() );
[javac] ^
[javac]
C:\src\backup-server\target\gen-src\com\incito\mirror\interfaces\TicketData.
java:44: cannot resolve symbol
[javac] symbol : method getValidTo ()
[javac] location: class com.incito.mirror.interfaces.TicketData
[javac] TicketLightValue.setValidTo( getValidTo() );
[javac] ^

>         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)
<snipped/>




-------------------------------------------------------
This SF.NET email is sponsored by: eBay
Great deals on office technology -- on eBay now! Click here:
http://adfarm.mediaplex.com/ad/ck/711-11697-6916-5
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to