You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by "Malcolm Edgar (JIRA)" <de...@cayenne.apache.org> on 2008/04/17 12:05:52 UTC

[jira] Created: (CAY-1034) ObjectId key singleValue is byte[]

ObjectId key singleValue is byte[]
----------------------------------

                 Key: CAY-1034
                 URL: https://issues.apache.org/cayenne/browse/CAY-1034
             Project: Cayenne
          Issue Type: Bug
          Components: Cayenne Core Library
    Affects Versions: 3.0
         Environment: Cayenne 3.0 M3, JDK 1.5.0_15
            Reporter: Malcolm Edgar
            Assignee: Andrus Adamchik


I have a nasty problem with attempting to perform a refetchObject() on a hollow object.  This is the DataObject toString(), note the primary key column 'schema_config_oid' has a value of 'B@ceaf8c>'

The primary key column of this database is an BIGINT, this table only has one record and its PK value is '1'

{<ObjectId:SchemaConfig, schema_config_oid=[B@ceaf8c>; hollow; []}

When I try to refetchObject(), I get a stacktrace of:

Caused by: java.sql.SQLException: Cannot convert class [B to SQL type requested due to java.lang.ClassCastException - [B
	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2744)

	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2532)
	at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.setObject(WrappedPreparedStatement.java:420)
	at org.apache.cayenne.access.types.AbstractType.setJdbcObject(AbstractType.java:79)

	at org.apache.cayenne.access.types.ByteArrayType.setJdbcObject(ByteArrayType.java:191)
	at org.apache.cayenne.dba.JdbcAdapter.bindParameter(JdbcAdapter.java:481)
	at org.apache.cayenne.access.trans.QueryAssembler.initStatement(QueryAssembler.java:123)

	at org.apache.cayenne.access.trans.QueryAssembler.createStatement(QueryAssembler.java:99)
	at org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:71)
	at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:58)

	at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:230)
	... 60 more

Some more analysis on this problem the ObjectId singleValue value is a byte[] of the table primary key value "3456", and the ObjectId is returning the raw byte array as the single primary key value.

This is making a mess of Cayenne refreshing objects, lazy loading, etc.  

I am wondering if this is a JDK 1.5 coercion issue, I have never seen this issue before with JDK 1.4 and Cayenne 1.x.

A solution to this problem is provided below in the patch to org.apache.cayenne.ObjectId. 

+    /**
+     * Creates a portable permanent ObjectId as a compound primary key.
+     * 
+     * @param entityName The entity name which this object id is for
+     * @param idMap Keys are usually the attribute names for each part of the primary key.
+     *            Values are unique when taken as a whole.
+     * @since 1.2
+     */
+    public ObjectId(String entityName, Map<String, ?> idMap) {
+        this.entityName = entityName;
+
+        if (idMap == null || idMap.size() == 0) {
+
+        }
+        else if (idMap.size() == 1) {
+            Map.Entry<String, ?> e = idMap.entrySet().iterator().next();
+            this.singleKey = String.valueOf(e.getKey());
+            
+            if (e.getValue() != null) {
+            	Class valueClass = e.getValue().getClass();
+            	if (valueClass.isArray()) {
+			if ("byte[]".equals(valueClass.getCanonicalName())) {
+				this.singleValue = new String((byte[]) e.getValue());
+			}
+            	}
+            }
+            	
+            if (this.singleValue == null) {
+            	this.singleValue = e.getValue();
+            }
+        }
+        else {
+
+            // we have to create a copy of the map, otherwise we may run into
+            // serialization
+            // problems with hessian
+            this.objectIdKeys = new HashMap<String, Object>(idMap);
+        }
+    }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (CAY-1034) ObjectId key singleValue is byte[]

Posted by "Malcolm Edgar (JIRA)" <de...@cayenne.apache.org>.
     [ https://issues.apache.org/cayenne/browse/CAY-1034?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Malcolm Edgar closed CAY-1034.
------------------------------

    Resolution: Incomplete

User error, I had the foreign key value defined as a BINARY type

> ObjectId key singleValue is byte[]
> ----------------------------------
>
>                 Key: CAY-1034
>                 URL: https://issues.apache.org/cayenne/browse/CAY-1034
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Cayenne Core Library
>    Affects Versions: 3.0
>         Environment: Cayenne 3.0 M3, JDK 1.5.0_15
>            Reporter: Malcolm Edgar
>            Assignee: Andrus Adamchik
>         Attachments: ObjectId.java
>
>
> I have a nasty problem with attempting to perform a refetchObject() on a hollow object.  This is the DataObject toString(), note the primary key column 'schema_config_oid' has a value of 'B@ceaf8c>'
> The primary key column of this database is an BIGINT, this table only has one record and its PK value is '1'
> {<ObjectId:SchemaConfig, schema_config_oid=[B@ceaf8c>; hollow; []}
> When I try to refetchObject(), I get a stacktrace of:
> Caused by: java.sql.SQLException: Cannot convert class [B to SQL type requested due to java.lang.ClassCastException - [B
> 	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2744)
> 	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2532)
> 	at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.setObject(WrappedPreparedStatement.java:420)
> 	at org.apache.cayenne.access.types.AbstractType.setJdbcObject(AbstractType.java:79)
> 	at org.apache.cayenne.access.types.ByteArrayType.setJdbcObject(ByteArrayType.java:191)
> 	at org.apache.cayenne.dba.JdbcAdapter.bindParameter(JdbcAdapter.java:481)
> 	at org.apache.cayenne.access.trans.QueryAssembler.initStatement(QueryAssembler.java:123)
> 	at org.apache.cayenne.access.trans.QueryAssembler.createStatement(QueryAssembler.java:99)
> 	at org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:71)
> 	at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:58)
> 	at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:230)
> 	... 60 more
> Some more analysis on this problem the ObjectId singleValue value is a byte[] of the table primary key value "3456", and the ObjectId is returning the raw byte array as the single primary key value.
> This is making a mess of Cayenne refreshing objects, lazy loading, etc.  
> I am wondering if this is a JDK 1.5 coercion issue, I have never seen this issue before with JDK 1.4 and Cayenne 1.x.
> A solution to this problem is provided in the attached org.apache.cayenne.ObjectId file.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAY-1034) ObjectId key singleValue is byte[]

Posted by "Andrus Adamchik (JIRA)" <de...@cayenne.apache.org>.
    [ https://issues.apache.org/cayenne/browse/CAY-1034?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12815#action_12815 ] 

Andrus Adamchik commented on CAY-1034:
--------------------------------------

Hmm... byte[] PK's worked just fine, and there is no need to convert them to String... What we need to do is to determine what environment causes this error... I incorrectly assumed PostgreSQL in my mailing list message. But from the stack trace this is MySQL... But the question remains - what MySQL column type this is and how is it mapped in Cayenne? 

> ObjectId key singleValue is byte[]
> ----------------------------------
>
>                 Key: CAY-1034
>                 URL: https://issues.apache.org/cayenne/browse/CAY-1034
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Cayenne Core Library
>    Affects Versions: 3.0
>         Environment: Cayenne 3.0 M3, JDK 1.5.0_15
>            Reporter: Malcolm Edgar
>            Assignee: Andrus Adamchik
>         Attachments: ObjectId.java
>
>
> I have a nasty problem with attempting to perform a refetchObject() on a hollow object.  This is the DataObject toString(), note the primary key column 'schema_config_oid' has a value of 'B@ceaf8c>'
> The primary key column of this database is an BIGINT, this table only has one record and its PK value is '1'
> {<ObjectId:SchemaConfig, schema_config_oid=[B@ceaf8c>; hollow; []}
> When I try to refetchObject(), I get a stacktrace of:
> Caused by: java.sql.SQLException: Cannot convert class [B to SQL type requested due to java.lang.ClassCastException - [B
> 	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2744)
> 	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2532)
> 	at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.setObject(WrappedPreparedStatement.java:420)
> 	at org.apache.cayenne.access.types.AbstractType.setJdbcObject(AbstractType.java:79)
> 	at org.apache.cayenne.access.types.ByteArrayType.setJdbcObject(ByteArrayType.java:191)
> 	at org.apache.cayenne.dba.JdbcAdapter.bindParameter(JdbcAdapter.java:481)
> 	at org.apache.cayenne.access.trans.QueryAssembler.initStatement(QueryAssembler.java:123)
> 	at org.apache.cayenne.access.trans.QueryAssembler.createStatement(QueryAssembler.java:99)
> 	at org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:71)
> 	at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:58)
> 	at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:230)
> 	... 60 more
> Some more analysis on this problem the ObjectId singleValue value is a byte[] of the table primary key value "3456", and the ObjectId is returning the raw byte array as the single primary key value.
> This is making a mess of Cayenne refreshing objects, lazy loading, etc.  
> I am wondering if this is a JDK 1.5 coercion issue, I have never seen this issue before with JDK 1.4 and Cayenne 1.x.
> A solution to this problem is provided in the attached org.apache.cayenne.ObjectId file.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAY-1034) ObjectId key singleValue is byte[]

Posted by "Malcolm Edgar (JIRA)" <de...@cayenne.apache.org>.
     [ https://issues.apache.org/cayenne/browse/CAY-1034?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Malcolm Edgar updated CAY-1034:
-------------------------------

    Attachment: ObjectId.java

The method :  public ObjectId(String entityName, Map<String, ?> idMap)     has been updated, byte array test appears a bit klunky, not sure how else to do this.

> ObjectId key singleValue is byte[]
> ----------------------------------
>
>                 Key: CAY-1034
>                 URL: https://issues.apache.org/cayenne/browse/CAY-1034
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Cayenne Core Library
>    Affects Versions: 3.0
>         Environment: Cayenne 3.0 M3, JDK 1.5.0_15
>            Reporter: Malcolm Edgar
>            Assignee: Andrus Adamchik
>         Attachments: ObjectId.java
>
>
> I have a nasty problem with attempting to perform a refetchObject() on a hollow object.  This is the DataObject toString(), note the primary key column 'schema_config_oid' has a value of 'B@ceaf8c>'
> The primary key column of this database is an BIGINT, this table only has one record and its PK value is '1'
> {<ObjectId:SchemaConfig, schema_config_oid=[B@ceaf8c>; hollow; []}
> When I try to refetchObject(), I get a stacktrace of:
> Caused by: java.sql.SQLException: Cannot convert class [B to SQL type requested due to java.lang.ClassCastException - [B
> 	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2744)
> 	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2532)
> 	at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.setObject(WrappedPreparedStatement.java:420)
> 	at org.apache.cayenne.access.types.AbstractType.setJdbcObject(AbstractType.java:79)
> 	at org.apache.cayenne.access.types.ByteArrayType.setJdbcObject(ByteArrayType.java:191)
> 	at org.apache.cayenne.dba.JdbcAdapter.bindParameter(JdbcAdapter.java:481)
> 	at org.apache.cayenne.access.trans.QueryAssembler.initStatement(QueryAssembler.java:123)
> 	at org.apache.cayenne.access.trans.QueryAssembler.createStatement(QueryAssembler.java:99)
> 	at org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:71)
> 	at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:58)
> 	at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:230)
> 	... 60 more
> Some more analysis on this problem the ObjectId singleValue value is a byte[] of the table primary key value "3456", and the ObjectId is returning the raw byte array as the single primary key value.
> This is making a mess of Cayenne refreshing objects, lazy loading, etc.  
> I am wondering if this is a JDK 1.5 coercion issue, I have never seen this issue before with JDK 1.4 and Cayenne 1.x.
> A solution to this problem is provided below in the patch to org.apache.cayenne.ObjectId. 
> +    /**
> +     * Creates a portable permanent ObjectId as a compound primary key.
> +     * 
> +     * @param entityName The entity name which this object id is for
> +     * @param idMap Keys are usually the attribute names for each part of the primary key.
> +     *            Values are unique when taken as a whole.
> +     * @since 1.2
> +     */
> +    public ObjectId(String entityName, Map<String, ?> idMap) {
> +        this.entityName = entityName;
> +
> +        if (idMap == null || idMap.size() == 0) {
> +
> +        }
> +        else if (idMap.size() == 1) {
> +            Map.Entry<String, ?> e = idMap.entrySet().iterator().next();
> +            this.singleKey = String.valueOf(e.getKey());
> +            
> +            if (e.getValue() != null) {
> +            	Class valueClass = e.getValue().getClass();
> +            	if (valueClass.isArray()) {
> +			if ("byte[]".equals(valueClass.getCanonicalName())) {
> +				this.singleValue = new String((byte[]) e.getValue());
> +			}
> +            	}
> +            }
> +            	
> +            if (this.singleValue == null) {
> +            	this.singleValue = e.getValue();
> +            }
> +        }
> +        else {
> +
> +            // we have to create a copy of the map, otherwise we may run into
> +            // serialization
> +            // problems with hessian
> +            this.objectIdKeys = new HashMap<String, Object>(idMap);
> +        }
> +    }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (CAY-1034) ObjectId key singleValue is byte[]

Posted by "Malcolm Edgar (JIRA)" <de...@cayenne.apache.org>.
    [ https://issues.apache.org/cayenne/browse/CAY-1034?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12816#action_12816 ] 

medgar edited comment on CAY-1034 at 4/17/08 3:18 AM:
-------------------------------------------------------------

The MySQL column type is BIGINT(20) and is the entity primary key.

This problem is very strange because there are about 30 tables in this schema which has an idential primary key type, and this is the first time I have seen this issue.

      was (Author: medgar):
    The MySQL column type is BIGINT(20), 

This problem is very strange because there are about 30 tables in this schema which has an idential primary key type, and this is the first time I have seen this issue.
  
> ObjectId key singleValue is byte[]
> ----------------------------------
>
>                 Key: CAY-1034
>                 URL: https://issues.apache.org/cayenne/browse/CAY-1034
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Cayenne Core Library
>    Affects Versions: 3.0
>         Environment: Cayenne 3.0 M3, JDK 1.5.0_15
>            Reporter: Malcolm Edgar
>            Assignee: Andrus Adamchik
>         Attachments: ObjectId.java
>
>
> I have a nasty problem with attempting to perform a refetchObject() on a hollow object.  This is the DataObject toString(), note the primary key column 'schema_config_oid' has a value of 'B@ceaf8c>'
> The primary key column of this database is an BIGINT, this table only has one record and its PK value is '1'
> {<ObjectId:SchemaConfig, schema_config_oid=[B@ceaf8c>; hollow; []}
> When I try to refetchObject(), I get a stacktrace of:
> Caused by: java.sql.SQLException: Cannot convert class [B to SQL type requested due to java.lang.ClassCastException - [B
> 	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2744)
> 	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2532)
> 	at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.setObject(WrappedPreparedStatement.java:420)
> 	at org.apache.cayenne.access.types.AbstractType.setJdbcObject(AbstractType.java:79)
> 	at org.apache.cayenne.access.types.ByteArrayType.setJdbcObject(ByteArrayType.java:191)
> 	at org.apache.cayenne.dba.JdbcAdapter.bindParameter(JdbcAdapter.java:481)
> 	at org.apache.cayenne.access.trans.QueryAssembler.initStatement(QueryAssembler.java:123)
> 	at org.apache.cayenne.access.trans.QueryAssembler.createStatement(QueryAssembler.java:99)
> 	at org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:71)
> 	at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:58)
> 	at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:230)
> 	... 60 more
> Some more analysis on this problem the ObjectId singleValue value is a byte[] of the table primary key value "3456", and the ObjectId is returning the raw byte array as the single primary key value.
> This is making a mess of Cayenne refreshing objects, lazy loading, etc.  
> I am wondering if this is a JDK 1.5 coercion issue, I have never seen this issue before with JDK 1.4 and Cayenne 1.x.
> A solution to this problem is provided in the attached org.apache.cayenne.ObjectId file.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (CAY-1034) ObjectId key singleValue is byte[]

Posted by "Malcolm Edgar (JIRA)" <de...@cayenne.apache.org>.
    [ https://issues.apache.org/cayenne/browse/CAY-1034?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12816#action_12816 ] 

Malcolm Edgar commented on CAY-1034:
------------------------------------

The MySQL column type is BIGINT(20), 

This problem is very strange because there are about 30 tables in this schema which has an idential primary key type, and this is the first time I have seen this issue.

> ObjectId key singleValue is byte[]
> ----------------------------------
>
>                 Key: CAY-1034
>                 URL: https://issues.apache.org/cayenne/browse/CAY-1034
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Cayenne Core Library
>    Affects Versions: 3.0
>         Environment: Cayenne 3.0 M3, JDK 1.5.0_15
>            Reporter: Malcolm Edgar
>            Assignee: Andrus Adamchik
>         Attachments: ObjectId.java
>
>
> I have a nasty problem with attempting to perform a refetchObject() on a hollow object.  This is the DataObject toString(), note the primary key column 'schema_config_oid' has a value of 'B@ceaf8c>'
> The primary key column of this database is an BIGINT, this table only has one record and its PK value is '1'
> {<ObjectId:SchemaConfig, schema_config_oid=[B@ceaf8c>; hollow; []}
> When I try to refetchObject(), I get a stacktrace of:
> Caused by: java.sql.SQLException: Cannot convert class [B to SQL type requested due to java.lang.ClassCastException - [B
> 	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2744)
> 	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2532)
> 	at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.setObject(WrappedPreparedStatement.java:420)
> 	at org.apache.cayenne.access.types.AbstractType.setJdbcObject(AbstractType.java:79)
> 	at org.apache.cayenne.access.types.ByteArrayType.setJdbcObject(ByteArrayType.java:191)
> 	at org.apache.cayenne.dba.JdbcAdapter.bindParameter(JdbcAdapter.java:481)
> 	at org.apache.cayenne.access.trans.QueryAssembler.initStatement(QueryAssembler.java:123)
> 	at org.apache.cayenne.access.trans.QueryAssembler.createStatement(QueryAssembler.java:99)
> 	at org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:71)
> 	at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:58)
> 	at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:230)
> 	... 60 more
> Some more analysis on this problem the ObjectId singleValue value is a byte[] of the table primary key value "3456", and the ObjectId is returning the raw byte array as the single primary key value.
> This is making a mess of Cayenne refreshing objects, lazy loading, etc.  
> I am wondering if this is a JDK 1.5 coercion issue, I have never seen this issue before with JDK 1.4 and Cayenne 1.x.
> A solution to this problem is provided in the attached org.apache.cayenne.ObjectId file.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (CAY-1034) ObjectId key singleValue is byte[]

Posted by "Malcolm Edgar (JIRA)" <de...@cayenne.apache.org>.
     [ https://issues.apache.org/cayenne/browse/CAY-1034?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Malcolm Edgar updated CAY-1034:
-------------------------------

    Description: 
I have a nasty problem with attempting to perform a refetchObject() on a hollow object.  This is the DataObject toString(), note the primary key column 'schema_config_oid' has a value of 'B@ceaf8c>'

The primary key column of this database is an BIGINT, this table only has one record and its PK value is '1'

{<ObjectId:SchemaConfig, schema_config_oid=[B@ceaf8c>; hollow; []}

When I try to refetchObject(), I get a stacktrace of:

Caused by: java.sql.SQLException: Cannot convert class [B to SQL type requested due to java.lang.ClassCastException - [B
	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2744)

	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2532)
	at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.setObject(WrappedPreparedStatement.java:420)
	at org.apache.cayenne.access.types.AbstractType.setJdbcObject(AbstractType.java:79)

	at org.apache.cayenne.access.types.ByteArrayType.setJdbcObject(ByteArrayType.java:191)
	at org.apache.cayenne.dba.JdbcAdapter.bindParameter(JdbcAdapter.java:481)
	at org.apache.cayenne.access.trans.QueryAssembler.initStatement(QueryAssembler.java:123)

	at org.apache.cayenne.access.trans.QueryAssembler.createStatement(QueryAssembler.java:99)
	at org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:71)
	at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:58)

	at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:230)
	... 60 more

Some more analysis on this problem the ObjectId singleValue value is a byte[] of the table primary key value "3456", and the ObjectId is returning the raw byte array as the single primary key value.

This is making a mess of Cayenne refreshing objects, lazy loading, etc.  

I am wondering if this is a JDK 1.5 coercion issue, I have never seen this issue before with JDK 1.4 and Cayenne 1.x.

A solution to this problem is provided in the attached org.apache.cayenne.ObjectId file.

  was:
I have a nasty problem with attempting to perform a refetchObject() on a hollow object.  This is the DataObject toString(), note the primary key column 'schema_config_oid' has a value of 'B@ceaf8c>'

The primary key column of this database is an BIGINT, this table only has one record and its PK value is '1'

{<ObjectId:SchemaConfig, schema_config_oid=[B@ceaf8c>; hollow; []}

When I try to refetchObject(), I get a stacktrace of:

Caused by: java.sql.SQLException: Cannot convert class [B to SQL type requested due to java.lang.ClassCastException - [B
	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2744)

	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2532)
	at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.setObject(WrappedPreparedStatement.java:420)
	at org.apache.cayenne.access.types.AbstractType.setJdbcObject(AbstractType.java:79)

	at org.apache.cayenne.access.types.ByteArrayType.setJdbcObject(ByteArrayType.java:191)
	at org.apache.cayenne.dba.JdbcAdapter.bindParameter(JdbcAdapter.java:481)
	at org.apache.cayenne.access.trans.QueryAssembler.initStatement(QueryAssembler.java:123)

	at org.apache.cayenne.access.trans.QueryAssembler.createStatement(QueryAssembler.java:99)
	at org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:71)
	at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:58)

	at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:230)
	... 60 more

Some more analysis on this problem the ObjectId singleValue value is a byte[] of the table primary key value "3456", and the ObjectId is returning the raw byte array as the single primary key value.

This is making a mess of Cayenne refreshing objects, lazy loading, etc.  

I am wondering if this is a JDK 1.5 coercion issue, I have never seen this issue before with JDK 1.4 and Cayenne 1.x.

A solution to this problem is provided below in the patch to org.apache.cayenne.ObjectId. 

+    /**
+     * Creates a portable permanent ObjectId as a compound primary key.
+     * 
+     * @param entityName The entity name which this object id is for
+     * @param idMap Keys are usually the attribute names for each part of the primary key.
+     *            Values are unique when taken as a whole.
+     * @since 1.2
+     */
+    public ObjectId(String entityName, Map<String, ?> idMap) {
+        this.entityName = entityName;
+
+        if (idMap == null || idMap.size() == 0) {
+
+        }
+        else if (idMap.size() == 1) {
+            Map.Entry<String, ?> e = idMap.entrySet().iterator().next();
+            this.singleKey = String.valueOf(e.getKey());
+            
+            if (e.getValue() != null) {
+            	Class valueClass = e.getValue().getClass();
+            	if (valueClass.isArray()) {
+			if ("byte[]".equals(valueClass.getCanonicalName())) {
+				this.singleValue = new String((byte[]) e.getValue());
+			}
+            	}
+            }
+            	
+            if (this.singleValue == null) {
+            	this.singleValue = e.getValue();
+            }
+        }
+        else {
+
+            // we have to create a copy of the map, otherwise we may run into
+            // serialization
+            // problems with hessian
+            this.objectIdKeys = new HashMap<String, Object>(idMap);
+        }
+    }


> ObjectId key singleValue is byte[]
> ----------------------------------
>
>                 Key: CAY-1034
>                 URL: https://issues.apache.org/cayenne/browse/CAY-1034
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Cayenne Core Library
>    Affects Versions: 3.0
>         Environment: Cayenne 3.0 M3, JDK 1.5.0_15
>            Reporter: Malcolm Edgar
>            Assignee: Andrus Adamchik
>         Attachments: ObjectId.java
>
>
> I have a nasty problem with attempting to perform a refetchObject() on a hollow object.  This is the DataObject toString(), note the primary key column 'schema_config_oid' has a value of 'B@ceaf8c>'
> The primary key column of this database is an BIGINT, this table only has one record and its PK value is '1'
> {<ObjectId:SchemaConfig, schema_config_oid=[B@ceaf8c>; hollow; []}
> When I try to refetchObject(), I get a stacktrace of:
> Caused by: java.sql.SQLException: Cannot convert class [B to SQL type requested due to java.lang.ClassCastException - [B
> 	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2744)
> 	at com.mysql.jdbc.PreparedStatement.setObject(PreparedStatement.java:2532)
> 	at org.jboss.resource.adapter.jdbc.WrappedPreparedStatement.setObject(WrappedPreparedStatement.java:420)
> 	at org.apache.cayenne.access.types.AbstractType.setJdbcObject(AbstractType.java:79)
> 	at org.apache.cayenne.access.types.ByteArrayType.setJdbcObject(ByteArrayType.java:191)
> 	at org.apache.cayenne.dba.JdbcAdapter.bindParameter(JdbcAdapter.java:481)
> 	at org.apache.cayenne.access.trans.QueryAssembler.initStatement(QueryAssembler.java:123)
> 	at org.apache.cayenne.access.trans.QueryAssembler.createStatement(QueryAssembler.java:99)
> 	at org.apache.cayenne.access.jdbc.SelectAction.performAction(SelectAction.java:71)
> 	at org.apache.cayenne.access.DataNodeQueryAction.runQuery(DataNodeQueryAction.java:58)
> 	at org.apache.cayenne.access.DataNode.performQueries(DataNode.java:230)
> 	... 60 more
> Some more analysis on this problem the ObjectId singleValue value is a byte[] of the table primary key value "3456", and the ObjectId is returning the raw byte array as the single primary key value.
> This is making a mess of Cayenne refreshing objects, lazy loading, etc.  
> I am wondering if this is a JDK 1.5 coercion issue, I have never seen this issue before with JDK 1.4 and Cayenne 1.x.
> A solution to this problem is provided in the attached org.apache.cayenne.ObjectId file.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.