Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unclear exceptions for class casting #206

Open
CyborTronik opened this issue Nov 20, 2015 · 3 comments
Open

Unclear exceptions for class casting #206

CyborTronik opened this issue Nov 20, 2015 · 3 comments
Labels

Comments

@CyborTronik
Copy link

I got next exception which is not clear what library tries to do:

registry-server> java.lang.IllegalArgumentException: java.lang.ClassCastException@3580b6d5
registry-server> at sun.reflect.GeneratedMethodAccessor10.invoke(Unknown Source)
registry-server> at org.sql2o.reflection.MethodAccessorsGenerator$2.setProperty(MethodAccessorsGenerator.java:126)
registry-server> at org.sql2o.DefaultResultSetHandlerFactory$4.handle(DefaultResultSetHandlerFactory.java:180)
registry-server> at org.sql2o.PojoResultSetIterator.readNext(PojoResultSetIterator.java:34)
registry-server> at org.sql2o.ResultSetIteratorBase.safeReadNext(ResultSetIteratorBase.java:87)
registry-server> at org.sql2o.ResultSetIteratorBase.hasNext(ResultSetIteratorBase.java:52)
registry-server> at org.sql2o.Query.executeAndFetchFirst(Query.java:482)
registry-server> at org.sql2o.Query.executeAndFetchFirst(Query.java:469)
@aaberg
Copy link
Owner

aaberg commented Nov 23, 2015

Hmm. I've never seen this before. Do you have a code snippet that can reproduce the exception?

@aaberg aaberg added the bug label Nov 23, 2015
@CyborTronik
Copy link
Author

I think I had a field with type java.time.OffsetDateTime.
So this kind of exception happens when you have no converter for such type.
So exception should be meaningfull like: org.sql2o.DataConvertException: Please provide a convertor for type any.package.CustomDataType

@toshim45
Copy link

i think i got the same problem:
java.lang.IllegalArgumentException: java.lang.ClassCastException@65bcf7c2 at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source) at org.sql2o.reflection.MethodAccessorsGenerator$3.setProperty(MethodAccessorsGenerator.java:145) at org.sql2o.DefaultResultSetHandlerFactory$6.handle(DefaultResultSetHandlerFactory.java:236) at org.sql2o.PojoResultSetIterator.readNext(PojoResultSetIterator.java:33) at org.sql2o.ResultSetIteratorBase.safeReadNext(ResultSetIteratorBase.java:88) at org.sql2o.ResultSetIteratorBase.hasNext(ResultSetIteratorBase.java:52) at org.sql2o.Query.executeAndFetch(Query.java:588) at org.sql2o.Query.executeAndFetch(Query.java:574)

the line causing this one is:
migrationHistories = conn.createQuery("SELECT * FROM migration_history_bu") .addColumnMapping("migration_number", "migrationNumber") .addColumnMapping("migration_data", "migrationData") .addColumnMapping("migration_date", "migrationDate") .addColumnMapping("migration_trial", "migrationTrial") .executeAndFetch(MigrationHistory.class);

and the DTO is:
public class MigrationHistory { private BigInteger id; private Integer migrationNumber; private Integer migrationTrial; private String migrationData; private Date migrationDate; //getter setter

and if you need sql
CREATE TABLE migration_history_bu ( id SERIAL NOT NULL, migration_number integer NOT NULL, migration_trial integer NOT NULL, migration_date timestamp without time zone NOT NULL, migration_data character varying(1024), PRIMARY KEY (id) );

for now the work around is don't put asterisk on select, if I change the query line:
migrationHistories = conn.createQuery("SELECT migration_date, migration_number, migration_data, migration_trial FROM migration_history_bu") .addColumnMapping("migration_number", "migrationNumber") .addColumnMapping("migration_data", "migrationData") .addColumnMapping("migration_date", "migrationDate") .addColumnMapping("migration_trial", "migrationTrial") .executeAndFetch(MigrationHistory.class);

then no exception raised, can you explain ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants