John

You may need to use a FieldConversion on the relevant field(s)/columns(s)

e.g

    <field-descriptor 
       name="intendedDateOfRelease" 
       column="RELEASE_DATE"
       jdbc-type="DATE"
 
conversion="org.apache.ojb.broker.accesslayer.conversions.JavaDate2SqlDateFi
eldConversion"
    />


Mark


-----Original Message-----
From: O'Reilly John [mailto:[EMAIL PROTECTED]
Sent: Tuesday, February 25, 2003 10:38 AM
To: 'OJB Users List'
Subject: ClassCastException persisting Date field


Hi,

Is there any known issue with persisting Date's using OJB.  I have defined
the field as follows:

    <field-descriptor name="intendedDateOfRelease" column="RELEASE_DATE"
jdbc-type="DATE"/>

The code that sets the date is as follows:

       Calendar today = Calendar.getInstance() ;
       today.set(Calendar.DAY_OF_MONTH, 28 );
       today.set(Calendar.MONTH, 8 );
       today.set(Calendar.YEAR, 2000);
       productModel.setIntendedDateOfRelease( today.getTime() );

When I try to persist the productModel object I get a ClassCastException (as
shown below).  I noticed that when I load an existing object from the db the
type of the field is java.sql.Date (subclass of java.util.Date) whereas the
type of the field I'm persisting is actaully a java.util.Date.

Rgds,
John


java.lang.ClassCastException: java.util.Date    at
oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement
.java:2051)     at
oracle.jdbc.driver.OraclePreparedStatement.setObject(OraclePreparedStatement
.java:2102)     at
com.p6spy.engine.spy.P6PreparedStatement.setObject(P6PreparedStatement.java:
282)    at
org.apache.ojb.broker.platforms.PlatformDefaultImpl.setObjectForStatement(Pl
atformDefaultImpl.java:229)     at
org.apache.ojb.broker.platforms.PlatformOracleImpl.setObjectForStatement(Pla
tformOracleImpl.java:126)       at
org.apache.ojb.broker.accesslayer.StatementManager.bindInsert(StatementManag
er.java:511)    at
org.apache.ojb.broker.accesslayer.JdbcAccessImpl.executeInsert(JdbcAccessImp
l.java:198)     at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.storeToDb(PersistenceBr
okerImpl.java:1742)     at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.store(PersistenceBroker
Impl.java:1683)         at
org.apache.ojb.broker.singlevm.PersistenceBrokerImpl.store(PersistenceBroker
Impl.java:632)  at
org.apache.ojb.broker.singlevm.DelegatingPersistenceBroker.store(DelegatingP
ersistenceBroker.java:151)      at
ie.mcps.product.dao.ProductDAO.addProduct(ProductDAO.java:65)   at
ie.mcps.product.dao.ProductDAOTest.testAddProduct(ProductDAOTest.java:191)
at java.lang.reflect.Method.invoke(Native Method)       at
junit.framework.TestCase.runTest(TestCase.java:166)     at
junit.framework.TestCase.runBare(TestCase.java:140)     at
junit.framework.TestResult$1.protect(TestResult.java:106)       at
junit.framework.TestResult.runProtected(TestResult.java:124)    at
junit.framework.TestResult.run(TestResult.java:109)     at
junit.framework.TestCase.run(TestCase.java:131)         at
junit.framework.TestSuite.runTest(TestSuite.java:173)   at
junit.framework.TestSuite.run(TestSuite.java:168)       at
com.borland.jbuilder.unittest.JBTestRunner.run(JBTestRunner.java:161)   at
com.borland.jbuilder.unittest.JBTestRunner.initiateTest(JBTestRunner.java:19
4)      at
com.borland.jbuilder.unittest.JBTestRunner.main(JBTestRunner.java:486) 
************************************************************************
This e-mail and any files transmitted with it are confidential and may be
privileged and are intended solely for the individual named/ for the use of
the individual or entity to whom they are addressed.If you are not the
intended addressee, you should not disseminate, distribute or copy this
e-mail.Please notify the sender immediately if you have received this e-mail
by mistake and delete this e-mail from your system.If you are not the
intended recipient, you are notified that reviewing, disclosing, copying,
distributing or taking any action in reliance on the contents of this e-mail
is strictly prohibited.Please note that any views or opinions expressed in
this e-mail are solely those of the author and do not necessarily represent
those of Traventec Limited.E-mail transmission cannot be guaranteed to be
secure or error-free as information could be intercepted, corrupted, lost,
destroyed, or arrive late or incomplete.Traventec Limited therefore does not
accept liability for any errors or omissions in the contents of this
message, which arise as a result of e-mail transmission.The recipient should
check this e-mail and any attachments for the presence of viruses.This
e-mail has been swept for computer viruses however Traventec Limited accepts
no liability for any damage caused by any virus transmitted by this e-mail.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

CreditTrade Limited is regulated by the FSA. (c) CreditTrade 2002. All rights 
reserved. The information and data contained in this email is provided for the 
information purposes of the addressee only and should not be reproduced and/or 
distributed to any other person. It is provided without any warranty whatsoever and 
unless stated otherwise consists purely of indicative market prices and other 
information.

Any opinion or comments expressed or assumption made in association with the data or 
information provided in this email is a reflection of CreditTrades judgement at the 
time of compiling the data and is subject to change. CreditTrade hereby makes no 
representation and accepts no responsibility or liability as to the completeness or 
accuracy of this email.

The content of this email is not intended as an offer or solicitation for, or 
recommendation of, the purchase or sale of any financial instrument, or as an official 
confirmation of any transaction, and should not be construed as investment advice.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to