cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrew Willerding <awillerd...@itsurcom.com>
Subject Re: MariaDB LocalDate field casting issue
Date Sun, 30 Apr 2017 15:44:59 GMT
Thank you!  I had seen a reference to this library in this list for I 
believe was M3 release but I skipped over it as I mistakenly thought it 
was baked into the later releases as I couldn't find a reference to 
adding this in the Cayenne guide as a requirement for Java8 or later.


On 30/04/17 04:17 AM, Andrus Adamchik wrote:
> Hi Andrew,
>
> You will need to add "cayenne-java8" library to your app. E.g. (if you are using Maven):
>
> <dependency>
>     <groupId>org.apache.cayenne</groupId>
>     <artifactId>cayenne-java8</artifactId>
>     <version>4.0.M5</version>
> </dependency>
>
> It contains support for java.time classes. Without it Cayenne doesn't know how to handle
LocalDate, and the default approach is to serialize it to a byte[] (which is of course wrong,
hence the error).
>
> Andrus
>
>> On Apr 30, 2017, at 12:07 AM, Andrew Willerding <awillerding@itsurcom.com>
wrote:
>>
>> Hi,
>>
>> I'm having an issue using a LocalDate field in my MariaDB table.
>>
>> I'm using mysql  Ver 15.1 Distrib 10.0.30-MariaDB, for debian-linux-gnu (x86_64)
using readline 5.2
>>
>> The table is defined as the following...
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <obj-attribute name="defaultTimeZone" type="java.lang.String" db-attribute-path="defaultTimeZone"/>
>> <obj-attribute name="expireDate" type="java.time.LocalDate" db-attribute-path="expireDate"/>
>> <obj-attribute name="maintenanceDate" type="java.time.LocalDate" db-attribute-path="maintenanceDate"/>
>> <obj-attribute name="name" type="java.lang.String" db-attribute-path="name"/>
>> <obj-attribute name="status" type="short" db-attribute-path="statusID"/>
>>
>> The code generating the error is the following ...
>>
>>             Client client = context.newObject(Client.class);
>>             client.setExpireDate(LocalDate.now());
>>             client.setMaintenanceDate(LocalDate.now());
>> client.setDefaultTimeZone(TimeZone.getDefault().getID());
>>             client.setName(CLIENT_TEMPLATE_NAME);
>> client.setStatus(EnumSimpleStatus.STATUS_INACTIVE.toShort());
>>             context.commitChanges();
>>
>> Upon execution of this code I'm getting
>>
>> java.sql.SQLException: Cannot convert class [B to SQL type requested due to java.lang.ClassCastException
- [B cannot be cast to java.util.Date
>>
>> I'm not sure why I'm getting the casting error.  Is there some underlying version
compatibility?
>>
>> Thanks,
>>
>> Andrew
>>
>> The full trace is as follows...
>>
>> 2017-04-29,16:56:45:263,INFO ,[http-nio-8080-exec-610],org.apache.cayenne.log.CommonsJdbcEventLogger,INSERT
INTO Client (contactID, defaultTimeZone, expireDate, id, maintenanceDate, name, statusID)
VALUES (?, ?, ?, ?, ?, ?, ?)
>> 2017-04-29,16:56:45:264,INFO ,[http-nio-8080-exec-610],org.apache.cayenne.log.CommonsJdbcEventLogger,[batch
bind: 1->contactID:NULL, 2->defaultTimeZone:'America/Toronto', 3->expireDate:2017-04-29,
4->id:200, 5->maintenanceDate:2017-04-29, 6->name:'Template', 7->statusID:1]
>> 2017-04-29,16:56:45:273,INFO ,[http-nio-8080-exec-610],org.apache.cayenne.log.CommonsJdbcEventLogger,***
error.
>> 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) ~[mysql-connector-java-5.1.41.jar:5.1.41]
>>     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897) ~[mysql-connector-java-5.1.41.jar:5.1.41]
>>     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886) ~[mysql-connector-java-5.1.41.jar:5.1.41]
>>     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:860) ~[mysql-connector-java-5.1.41.jar:5.1.41]
>>     at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:3761) ~[mysql-connector-java-5.1.41.jar:5.1.41]
>>     at com.mysql.jdbc.JDBC42PreparedStatement.setObject(JDBC42PreparedStatement.java:99)
~[mysql-connector-java-5.1.41.jar:5.1.41]
>>     at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:3580) ~[mysql-connector-java-5.1.41.jar:5.1.41]
>>     at com.mysql.jdbc.JDBC42PreparedStatement.setObject(JDBC42PreparedStatement.java:83)
~[mysql-connector-java-5.1.41.jar:5.1.41]
>>     at org.apache.cayenne.access.types.ByteArrayType.setJdbcObject(ByteArrayType.java:160)
~[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.access.types.ByteArrayType.setJdbcObject(ByteArrayType.java:40)
~[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.access.types.ExtendedTypeDecorator.setJdbcObject(ExtendedTypeDecorator.java:63)
~[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.dba.JdbcAdapter.bindParameter(JdbcAdapter.java:548) ~[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.dba.mysql.MySQLAdapter.bindParameter(MySQLAdapter.java:214)
~[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.dba.AutoAdapter.bindParameter(AutoAdapter.java:204) ~[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.access.jdbc.BatchAction.bind(BatchAction.java:57) ~[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.access.jdbc.BatchAction.runAsBatch(BatchAction.java:114)
~[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.access.jdbc.BatchAction.performAction(BatchAction.java:85)
~[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:97)
~[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:293) [cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.access.DataDomainFlushAction.runQueries(DataDomainFlushAction.java:239)
[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.access.DataDomainFlushAction.flush(DataDomainFlushAction.java:155)
[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.access.DataDomain.onSyncFlush(DataDomain.java:629) [cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.access.DataDomain.onSyncNoFilters(DataDomain.java:598)
[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:746)
[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:73)
[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.tx.TransactionFilter$1.perform(TransactionFilter.java:70)
[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:87)
[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.tx.DefaultTransactionManager.performInLocalTransaction(DefaultTransactionManager.java:59)
[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:52)
[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.tx.DefaultTransactionManager.performInTransaction(DefaultTransactionManager.java:40)
[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.tx.TransactionFilter.onSync(TransactionFilter.java:70)
[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.access.DataDomain$DataDomainSyncFilterChain.onSync(DataDomain.java:746)
[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.access.DataDomain.onSync(DataDomain.java:585) [cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.access.DataContext.flushToParent(DataContext.java:742)
[cayenne-server-4.0.M5.jar:4.0.M5]
>>     at org.apache.cayenne.access.DataContext.commitChanges(DataContext.java:691)
[cayenne-server-4.0.M5.jar:4.0.M5]
>>
>>
>> <?xml version="1.0" encoding="utf-8"?>
>> <obj-attribute name="defaultTimeZone" type="java.lang.String" db-attribute-path="defaultTimeZone"/>
>> <obj-attribute name="expireDate" type="java.time.LocalDate" db-attribute-path="expireDate"/>
>> <obj-attribute name="maintenanceDate" type="java.time.LocalDate" db-attribute-path="maintenanceDate"/>
>> <obj-attribute name="name" type="java.lang.String" db-attribute-path="name"/>
>> <obj-attribute name="status" type="short" db-attribute-path="statusID"/>
>>


Mime
View raw message