cayenne-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Borut BolĨina <borut.bolc...@gmail.com>
Subject SQLTemplate SELECT max(ordering) ClassCastException
Date Mon, 04 Oct 2010 15:51:16 GMT
Hello,

after upgrading from 3.0 to 3.0.1 I am getting

java.lang.ClassCastException: java.lang.Byte cannot be cast to
java.lang.Integer

    @SuppressWarnings("unchecked")
    private Integer getMaxOrderingFromUserBookmark(DataContext context, User
user) {
        SQLTemplate template = new SQLTemplate(UserBookmark.class,
            "SELECT max(ordering) FROM user_bookmark WHERE userid=$uid");
        template.setParameters(Collections.singletonMap("uid",
user.getId()));
        template.setFetchingDataRows(true);
        List<UserBookmark> res = context.performQuery(template);

        Integer maxOrdering = null;
        if (res != null) {
            Map row = (Map) res.get(0);
            if (row != null) {
                *maxOrdering = (Integer) row.get("max(ordering)"); // <==
ClassCastException*
            }
        }
        return maxOrdering;
    }

In my mapping file the user_bookmark is defined as

    <db-entity name="user_bookmark">
        <db-attribute name="bookmarkid" type="INTEGER" isMandatory="true"/>
        <db-attribute name="id" type="INTEGER" isPrimaryKey="true"
isMandatory="true"/>
        <db-attribute name="ordering" type="INTEGER" isMandatory="true"/>
        <db-attribute name="userid" type="INTEGER" isMandatory="true"/>
    </db-entity>


Does this somehow relate to https://issues.apache.org/jira/browse/CAY-1354?

Why is row.get("max(ordering)") returning Byte?

Regards,
Borut

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message