cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Willerding <awillerd...@itsurcom.com>
Subject Re: Cayenne runtime error with DI
Date Thu, 12 Oct 2017 13:39:33 GMT
Hi Nikita,

Your hunch is correct and I'm even more confused. I deleted all the 
records in the database and re-ran my application.  It's complaining of 
a cast to Date but I don't have any Date fields or objects.  Now I'm 
getting the following exception:

org.apache.cayenne.CayenneRuntimeException: [v.4.0.B1 Jun 02 2017 
15:11:18] Commit Exception
     at 
org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:774)
     at 
org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:691)
     at 
com.callistacti.quest.crsolstasv2.ImportThread.run(ImportThread.java:258)
     at java.lang.Thread.run(Thread.java:748)
Caused by: java.sql.SQLException: Cannot convert class [B to SQL type 
requested due to java.lang.ClassCastException - [B cannot be cast to 
java.util.Date
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860)
     at 
com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:3761)
     at 
com.mysql.jdbc.JDBC42PreparedStatement.setObject(JDBC42PreparedStatement.java:99)
     at 
com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:3580)
     at 
com.mysql.jdbc.JDBC42PreparedStatement.setObject(JDBC42PreparedStatement.java:83)
     at 
org.apache.cayenne.access.types.ByteArrayType.setJdbcObject(ByteArrayType.java:157)
     at 
org.apache.cayenne.access.types.ByteArrayType.setJdbcObject(ByteArrayType.java:40)
     at 
org.apache.cayenne.access.types.ExtendedTypeDecorator.setJdbcObject(ExtendedTypeDecorator.java:63)
     at 
org.apache.cayenne.dba.JdbcAdapter.bindParameter(JdbcAdapter.java:548)
     at 
org.apache.cayenne.dba.mysql.MySQLAdapter.bindParameter(MySQLAdapter.java:216)
     at 
org.apache.cayenne.dba.AutoAdapter.bindParameter(AutoAdapter.java:204)
     at org.apache.cayenne.access.jdbc.BatchAction.bind(BatchAction.java:57)
     at 
org.apache.cayenne.access.jdbc.BatchAction.runAsBatch(BatchAction.java:114)
     at 
org.apache.cayenne.access.jdbc.BatchAction.performAction(BatchAction.java:85)
     at 
org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:97)
     at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:293)
     at 
org.apache.cayenne.access.DataDomainFlushAction.runQueries(DataDomainFlushAction.java:233)
     at 
org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:153)
     at 
org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:633)
     at 
org.apache.cayenne.access.DataDomain.onSyncNoFilters(DataDomain.java:603)
     at 
org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:764)
     at 
org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:73)
     at 
org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:70)
     at 
org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:87)
     at 
org.apache.cayenne.tx.DefaultTransactionManager.performInLocalTransaction(DefaultTransactionManager.java:59)
     at 
org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:52)
     at 
org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:40)
     at 
org.apache.cayenne.tx.TransactionFilter.onSync(TransactionFilter.java:70)
     at 
org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:764)
     at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:590)
     at 
org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:742)
     ... 3 more
Caused by: java.lang.ClassCastException: [B cannot be cast to java.util.Date
     at 
com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:3706)
     ... 32 more

My MySQL table looks like this...

+---------------------+-------------+------+-----+---------------------+-----------------------------+
| Field               | Type        | Null | Key | Default            
| 
Extra                       |
+---------------------+-------------+------+-----+---------------------+-----------------------------+
| AccountNumber       | varchar(32) | NO   | MUL | NULL               

|                             |
| Active              | char(1)     | NO   |     | NULL               

|                             |
| Address1            | varchar(64) | NO   |     | NULL               

|                             |
| Address2            | varchar(64) | YES  |     | NULL               

|                             |
| AmountDue           | varchar(16) | NO   |     | NULL               

|                             |
| City                | varchar(32) | YES  |     | NULL               

|                             |
| DTCreated           | timestamp   | NO   |     | CURRENT_TIMESTAMP  
| 
on update CURRENT_TIMESTAMP |
| DTUpdated           | timestamp   | YES  |     | NULL               

|                             |
| HashedAccountNumber | varchar(32) | NO   |     | NULL               

|                             |
| InvoiceDate         | timestamp   | NO   |     | 0000-00-00 00:00:00 
|                             |
| PatientName         | varchar(64) | NO   |     | NULL               

|                             |
| State               | varchar(2)  | YES  |     | NULL               

|                             |
| ZIP                 | varchar(12) | NO   |     | NULL               

|                             |
| id                  | int(11)     | NO   | PRI | NULL               

|                             |
+---------------------+-------------+------+-----+---------------------+-----------------------------+

My class is this...

public abstract class _MAMRecords extends CayenneDataObject {

     private static final long serialVersionUID = 1L;

     public static final String ID_PK_COLUMN = "id";

     public static final Property<String> ACCOUNT_NUMBER = 
Property.create("accountNumber", String.class);
     public static final Property<String> ACTIVE = 
Property.create("active", String.class);
     public static final Property<String> ADDRESS1 = 
Property.create("address1", String.class);
     public static final Property<String> ADDRESS2 = 
Property.create("address2", String.class);
     public static final Property<String> AMOUNT_DUE = 
Property.create("amountDue", String.class);
     public static final Property<String> CITY = Property.create("city", 
String.class);
     public static final Property<LocalDateTime> D_TCREATED = 
Property.create("dTCreated", LocalDateTime.class);
     public static final Property<LocalDateTime> D_TUPDATED = 
Property.create("dTUpdated", LocalDateTime.class);
     public static final Property<String> HASHED_ACCOUNT_NUMBER = 
Property.create("hashedAccountNumber", String.class);
     public static final Property<LocalDateTime> INVOICE_DATE = 
Property.create("invoiceDate", LocalDateTime.class);
     public static final Property<String> PATIENT_NAME = 
Property.create("patientName", String.class);
     public static final Property<String> STATE = 
Property.create("state", String.class);
     public static final Property<String> ZIP = Property.create("zip", 
String.class);
     public static final Property<List<Payments>> TO_PAYMENTS = 
Property.create("toPayments", List.class);


On 12/10/17 04:49 AM, Nikita Timofeev wrote:
> Hi Andrew,
>
> Your last exception seems like a Cayenne fallback to a serializable
> type when it doesn't now how to handle given value, are there any
> warnings preceding this exception?
> Something like "Haven't found suitable ExtendedType for class..."?
>
> On Wed, Oct 11, 2017 at 9:59 PM, Andrew Willerding
> <awillerding@itsurcom.com> wrote:
>> Sorry to bug the list but I seemed to have got around the DI issue by
>> deleting the Maven references to cayenne and reinstalling them but now I'm
>> getting another exception.  I'm sure I have the correct versions of Cayenne
>> v4.0.B1 server, java8 and removed di. Am I still missing some dependent
>> library?
>>
>>
>> Exception in thread "Thread-2" org.apache.cayenne.CayenneRuntimeException:
>> [v.4.0.B1 Jun 02 2017 15:11:18] Query exception.
>>      at
>> org.apache.cayenne.access.DataDomainQueryAction.nextQueryException(DataDomainQueryAction.java:614)
>>      at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:299)
>>      at
>> org.apache.cayenne.access.DataDomainQueryAction.runQuery(DataDomainQueryAction.java:471)
>>      at
>> org.apache.cayenne.access.DataDomainQueryAction.access$000(DataDomainQueryAction.java:72)
>>      at
>> org.apache.cayenne.access.DataDomainQueryAction$2.perform(DataDomainQueryAction.java:446)
>>      at
>> org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:87)
>>      at
>> org.apache.cayenne.tx.DefaultTransactionManager.performInLocalTransaction(DefaultTransactionManager.java:59)
>>      at
>> org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:52)
>>      at
>> org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:40)
>>      at
>> org.apache.cayenne.access.DataDomainQueryAction.runQueryInTransaction(DataDomainQueryAction.java:443)
>>      at
>> org.apache.cayenne.access.DataDomainQueryAction.execute(DataDomainQueryAction.java:122)
>>      at
>> org.apache.cayenne.access.DataDomain.onQueryNoFilters(DataDomain.java:564)
>>      at
>> org.apache.cayenne.access.DataDomain$DataDomainQueryFilterChain.onQuery(DataDomain.java:748)
>>      at
>> org.apache.cayenne.tx.TransactionFilter.onQuery(TransactionFilter.java:49)
>>      at
>> org.apache.cayenne.access.DataDomain$DataDomainQueryFilterChain.onQuery(DataDomain.java:748)
>>      at org.apache.cayenne.access.DataDomain.onQuery(DataDomain.java:556)
>>      at
>> org.apache.cayenne.util.ObjectContextQueryAction.runQuery(ObjectContextQueryAction.java:382)
>>      at
>> org.apache.cayenne.util.ObjectContextQueryAction.executePostCache(ObjectContextQueryAction.java:107)
>>      at
>> org.apache.cayenne.util.ObjectContextQueryAction.execute(ObjectContextQueryAction.java:94)
>>      at org.apache.cayenne.access.DataContext.onQuery(DataContext.java:965)
>>      at
>> org.apache.cayenne.access.DataContext.performQuery(DataContext.java:954)
>>      at org.apache.cayenne.BaseContext.select(BaseContext.java:307)
>>      at org.apache.cayenne.query.FluentSelect.select(FluentSelect.java:157)
>>      at
>> com.callistacti.quest.crsolstasv2.ImportThread.run(ImportThread.java:202)
>>      at java.lang.Thread.run(Thread.java:748)
>> Caused by: java.io.StreamCorruptedException: invalid stream header: 32303137
>>      at
>> java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:857)
>>      at java.io.ObjectInputStream.<init>(ObjectInputStream.java:349)
>>      at
>> org.apache.cayenne.access.types.SerializableTypeFactory$SerializableType.toJavaObject(SerializableTypeFactory.java:106)
>>      at
>> org.apache.cayenne.access.types.SerializableTypeFactory$SerializableType.toJavaObject(SerializableTypeFactory.java:70)
>>      at
>> org.apache.cayenne.access.types.ExtendedTypeDecorator.materializeObject(ExtendedTypeDecorator.java:53)
>>      at
>> org.apache.cayenne.access.jdbc.reader.FullRowReader.readRow(FullRowReader.java:52)
>>      at
>> org.apache.cayenne.access.jdbc.reader.FullRowReader.readRow(FullRowReader.java:32)
>>      at
>> org.apache.cayenne.access.jdbc.JDBCResultIterator.nextRow(JDBCResultIterator.java:104)
>>      at
>> org.apache.cayenne.access.jdbc.JDBCResultIterator.allRows(JDBCResultIterator.java:80)
>>      at
>> org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:138)
>>      at
>> org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:97)
>>      at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:293)
>>
>>
>>
>> On 11/10/17 07:16 AM, Andrew Willerding wrote:
>>> Hi,
>>>
>>> I'm not sure what I'm missing when I try to run my application jar file.
>>> The intention is to load the cayenne configuration file from the
>>> subdirectory etc.
>>>
>>> I'm getting the following error
>>>
>>> Exception in thread "main" org.apache.cayenne.di.DIRuntimeException: DI
>>> container has no binding for key <BindingKey:
>>> org.apache.cayenne.configuration.ObjectContextFactory>
>>>      at
>>> org.apache.cayenne.di.spi.DefaultInjector.getProvider(DefaultInjector.java:158)
>>>      at
>>> org.apache.cayenne.di.spi.DefaultInjector.getProvider(DefaultInjector.java:144)
>>>      at
>>> org.apache.cayenne.di.spi.DefaultInjector.getInstance(DefaultInjector.java:134)
>>>      at
>>> org.apache.cayenne.configuration.CayenneRuntime.newContext(CayenneRuntime.java:124)
>>>      at
>>> com.callistacti.quest.crsolstasv2.CRSolstas.main(CRSolstas.java:114)
>>>
>>> after executing the following code...
>>>
>>>      public static final String DB_FILE = "cayenne-CRSolstas.xml";
>>>
>>>          Module myModule = (Binder binder) -> {
>>>              binder.bind(ResourceLocator.class).toInstance(new
>>> FilesystemResourceLocator(new File("etc")));
>>>
>>> ServerModule.contributeProperties(binder).put(Constants.SERVER_CONTEXTS_SYNC_PROPERTY,
>>> "false");
>>>          };
>>>
>>>          ServerRuntime cayenneRuntime =
>>> ServerRuntime.builder().addConfig(DB_FILE)
>>>                  .addModule(myModule)
>>>                  .build();
>>>          ObjectContext test = cayenneRuntime.newContext();
>>>          test.commitChanges();
>>>
>>> When I run my code within my IDE (Netbeans) I do not get this error so I'm
>>> missing something from my jar package but I'm not sure what.
>>>
>>> Thanks,
>>>
>>> Andrew
>>>
>
>


Mime
View raw message