cayenne-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Malcolm Edgar (JIRA)" <>
Subject [jira] [Commented] (CAY-1734) Add NuoDB database support
Date Thu, 23 Aug 2012 13:48:42 GMT


Malcolm Edgar commented on CAY-1734:

One issue I have been facing is the NuoDB JDBC drivers strict typing with the PreparedStatement
method setObject :,
java.lang.Object, int)

The first case I hit with this was converting a Java Boolean value into a database INTEGER
value via setObject(). Some relational databases such as Oracle don't have support the the
SQL BOOLEAN data type, so in our database schema we use the INTEGER to store boolean values
and rely on Cayenne / JDBC driver to handle to marshal these values in and out of storage.
This strategy has worked for the MySQL, Oracle and SQL Server JDBC drivers, but not with the
NuoDB driver.

The work around for this was to handle this marshaling in the Cayenne BooleanType class, by
adding an Type.INTEGER switch below:

    public void setJdbcObject(
            PreparedStatement st,
            Object val,
            int pos,
            int type,
            int precision) throws Exception {

        if (val == null) {
            st.setNull(pos, type);
        else if (type == Types.BIT || type == Types.BOOLEAN) {
            boolean flag = Boolean.TRUE.equals(val);
            st.setBoolean(pos, flag);
        else if (type == Types.INTEGER) {
            int intVal = Boolean.TRUE.equals(val) ? 1 : 0;
            st.setInt(pos, intVal);
        else {
            st.setObject(pos, val, type);

The next related issue was with passing PK string values into Cayenne queries where the underlying
database data type was a BIGINT.  While this is arguably not very type safe, the Cayenne API's
don't prevent this, and the MySQL, Oracle and SQL Server JDBC drivers have no problem marshalling
numeric string values into BIGINT values. An example NuoDB exception stack is provided below:

java.lang.String cannot be cast to java.lang.Long
 at com.nuodb.jdbc.ValueLong.<init>(
 at com.nuodb.jdbc.RemPreparedStatement.setObject(
 at com.nuodb.jdbc.RemPreparedStatement.setObject(

This issue could be addressed in a number of ways:
* changed to NuoDB driver
* modify the Cayenne CharType to marshal the value into the correct JDBC type
* update calling application code to marshal value into the matching Java/JDBC type

While the Boolean conversion could be arguably handled with Cayenne BooleanType, I think using
CharType to marshal string values into arbitrary JDBC type is more problematic, and probably
should not be the role of this class.
> Add NuoDB database support
> --------------------------
>                 Key: CAY-1734
>                 URL:
>             Project: Cayenne
>          Issue Type: Improvement
>          Components: Core Library, Modeler
>            Reporter: Malcolm Edgar
>            Assignee: Malcolm Edgar
>             Fix For: 3.0.3, 3.1B2
> Add support for NuoDB database (

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message