[ 
http://issues.apache.org/jira/browse/OPENJPA-69?page=comments#action_12445525 ] 
            
Rusanov Dmitry commented on OPENJPA-69:
---------------------------------------

Stack trace is on OpenJPA 0.9.0 (openjpa-project-0.9.0-incubating.zip) and 
Apache Derby 10.1.2.1
Complete stack trace is here:
---------------------------------------

<2|true|0.9.0-incubating> org.apache.openjpa.persistence.RollbackException: The 
transaction has been rolled back.  See the nested exceptions for details on the 
errors that occurred.
        at 
org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:387)
        at app.WriteData.main(WriteData.java:28)
Caused by: <0|true|0.9.0-incubating> 
org.apache.openjpa.persistence.PersistenceException: The transaction has been 
rolled back.  See the nested exceptions for details on the errors that occurred.
        at 
org.apache.openjpa.kernel.BrokerImpl.newFlushException(BrokerImpl.java:2081)
        at org.apache.openjpa.kernel.BrokerImpl.flush(BrokerImpl.java:1928)
        at org.apache.openjpa.kernel.BrokerImpl.flushSafe(BrokerImpl.java:1826)
        at 
org.apache.openjpa.kernel.BrokerImpl.beforeCompletion(BrokerImpl.java:1757)
        at 
org.apache.openjpa.kernel.LocalManagedRuntime.commit(LocalManagedRuntime.java:76)
        at org.apache.openjpa.kernel.BrokerImpl.commit(BrokerImpl.java:1314)
        at 
org.apache.openjpa.kernel.DelegatingBroker.commit(DelegatingBroker.java:863)
        at 
org.apache.openjpa.persistence.EntityManagerImpl.commit(EntityManagerImpl.java:376)
        ... 1 more
Caused by: <0|false|0.9.0-incubating> 
org.apache.openjpa.persistence.PersistenceException: An attempt was made to get 
a data value of type 'CHAR () FOR BIT DATA' from a data value of type 'BLOB'.
        at 
org.apache.openjpa.jdbc.sql.DBDictionary.newStoreException(DBDictionary.java:3729)
        at 
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:94)
        at 
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:80)
        at 
org.apache.openjpa.jdbc.sql.SQLExceptions.getStore(SQLExceptions.java:56)
        at 
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:70)
        at 
org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager.flushPrimaryRow(OperationOrderUpdateManager.java:200)
        at 
org.apache.openjpa.jdbc.kernel.OperationOrderUpdateManager.flush(OperationOrderUpdateManager.java:86)
        at 
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:86)
        at 
org.apache.openjpa.jdbc.kernel.AbstractUpdateManager.flush(AbstractUpdateManager.java:69)
        at 
org.apache.openjpa.jdbc.kernel.JDBCStoreManager.flush(JDBCStoreManager.java:512)
        at 
org.apache.openjpa.kernel.DelegatingStoreManager.flush(DelegatingStoreManager.java:127)
        ... 8 more
Caused by: SQL Exception: An attempt was made to get a data value of type 'CHAR 
() FOR BIT DATA' from a data value of type 'BLOB'.
        at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Util.java:80)
        at org.apache.derby.impl.jdbc.Util.newEmbedSQLException(Util.java:87)
        at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Util.java:173)
        at 
org.apache.derby.impl.jdbc.EmbedConnection.newSQLException(EmbedConnection.java:1911)
        at 
org.apache.derby.impl.jdbc.ConnectionChild.newSQLException(ConnectionChild.java:180)
        at 
org.apache.derby.impl.jdbc.EmbedPreparedStatement.dataTypeConversion(EmbedPreparedStatement.java:1328)
        at 
org.apache.derby.impl.jdbc.EmbedPreparedStatement.setNull(EmbedPreparedStatement.java:282)
        at 
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.setNull(DelegatingPreparedStatement.java:270)
        at 
org.apache.openjpa.lib.jdbc.LoggingConnectionDecorator$LoggingConnection$LoggingPreparedStatement.setNull(LoggingConnectionDecorator.java:932)
        at 
org.apache.openjpa.lib.jdbc.DelegatingPreparedStatement.setNull(DelegatingPreparedStatement.java:270)
        at 
org.apache.openjpa.jdbc.sql.DBDictionary.setNull(DBDictionary.java:958)
        at 
org.apache.openjpa.jdbc.sql.DBDictionary.setTyped(DBDictionary.java:1070)
        at org.apache.openjpa.jdbc.sql.RowImpl.flush(RowImpl.java:876)
        at org.apache.openjpa.jdbc.sql.RowImpl.flush(RowImpl.java:835)
        at 
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flushInternal(PreparedStatementManagerImpl.java:90)
        at 
org.apache.openjpa.jdbc.kernel.PreparedStatementManagerImpl.flush(PreparedStatementManagerImpl.java:68)
        ... 14 more
----------------

In my opinion root of the problem could be found near  
'org.apache.openjpa.jdbc.sql.DBDictionary.setTyped(DBDictionary.java:1070)', 
where value NULL is assigned to database column. In case of NULL value SQL-type 
of this NULL is taken from OpenJPA metadata, where type of column has been 
determined as BLOB (corresponding object field is reference to object with id 
of byte[]). This time database table field has type CHAR(16) FOR BIT DATA. 
Derby detects that types are different and rejects assignment. In case of 
non-NULL values SQL-type of assigned value determined on value itself.


> Null reference from one Entity to other causes fault with OpenJPA 0.9.0 and 
> Apache Derby 10.1 when byte[] used as identity
> --------------------------------------------------------------------------------------------------------------------------
>
>                 Key: OPENJPA-69
>                 URL: http://issues.apache.org/jira/browse/OPENJPA-69
>             Project: OpenJPA
>          Issue Type: Bug
>          Components: jpa
>         Environment: Windows XP, Java SE 1.5 (Sun JRE 1.5_06)
>            Reporter: Rusanov Dmitry
>         Attachments: sample.zip
>
>
> Suppose we have following stuff:
> Foo.java:
> ------------
> package entity;
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.Id;
> import javax.persistence.IdClass;
> import javax.persistence.ManyToOne;
> import javax.persistence.Table;
> @Entity
> @Table(name="FOO")
> @IdClass(BinaryId.class)
> public class Foo
> {
>     @Id
>     @Column(name="ID", length=16, nullable=false)
>     private byte[] id;
>     @ManyToOne
>     private Bar bar;
>     public void setId(byte[] id)
>     {
>         this.id = id;
>     }
>     public byte[] getId()
>     {
>         return id;
>     }
>     
>     public void setBar(Bar bar)
>     {
>         this.bar = bar;
>     }
>     public Bar getBar()
>     {
>         return bar;
>     }
> }
> Bar.java
> -----------
> package entity;
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.Id;
> import javax.persistence.IdClass;
> import javax.persistence.Table;
> @Entity
> @Table(name="FOO")
> @IdClass(BinaryId.class)
> public class Bar
> {
>     @Id
>     @Column(name="ID", length=16, nullable=false)
>     private byte[] id;
>     @Column(length=32)
>     private String name;
>     public void setId(byte[] id)
>     {
>         this.id = id;
>     }
>     public byte[] getId()
>     {
>         return id;
>     }
>     
>     public void setName(String name)
>     {
>         this.name = name;
>     }
>     public String getName()
>     {
>         return name;
>     }
> }
> BinaryId.java (Identity class for byte[] identity):
> --------------------------------------------
> package entity;
> public class BinaryId
> {
>     private byte[] id;
>     
>     public boolean equals(Object other)
>     {
>         if (other == this)
>             return true;
>         if (!(other instanceof BinaryId))
>             return false;
>         BinaryId bi = (BinaryId)other;
>         if (id == bi.id)
>             return true;
>         if (id == null)
>             return false;
>         if (id.length != bi.id.length)
>             return false;
>         for (int i = 0; i < id.length; i++)
>         {
>             if (id[i] != bi.id[i])
>                 return false;
>         }
>         return true;
>     }
>     
>     public int hashCode()
>     {
>         if (id == null)
>             return 0;
>         int hash = 0;
>         for (int i = 0; i < id.length; i++)
>             hash += id[i];
>         return hash;
>     }
> }
> persistence.xml
> ----------------------
> <persistence xmlns="http://java.sun.com/xml/ns/persistence";
>       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd";
>       version="1.0">
>       <persistence-unit name="openjpa">
>         
> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
>         <class>entity.Foo</class>
>         <class>entity.Bar</class>
>         <properties>
>             <property name="openjpa.ConnectionURL" 
> value="jdbc:derby:c:/derbydb/ojpa-bug"/>
>             <property name="openjpa.ConnectionDriverName" 
> value="org.apache.derby.jdbc.EmbeddedDriver"/>
>             <property name="openjpa.Log" value="DefaultLevel=WARN, 
> Tool=INFO"/>
>         </properties>
>     </persistence-unit>
> </persistence>
> create.sql
> -------------
> CREATE TABLE APP.foo (
>   id CHAR(16) FOR BIT DATA NOT NULL, 
>   bar_id CHAR(16) FOR BIT DATA,
>   PRIMARY KEY(id) );
> CREATE TABLE APP.bar (
>   id CHAR(16) FOR BIT DATA NOT NULL, 
>   name VARCHAR(32),
>   PRIMARY KEY(id) );
>     
> With all this stuff following portion of code causes exception:
>         EntityManagerFactory emf = 
> Persistence.createEntityManagerFactory("openjpa");
>         EntityManager entityManager = emf.createEntityManager();
>         Foo foo = new Foo();
>         byte[] id = new byte[16];
>         for (int i = 0; i < 16; i++)
>             id[i] = (byte)(i + 16);
>         foo.setId(id);
>         
>         EntityTransaction txn = entityManager.getTransaction();
>         try
>         {
>             txn.begin();
>             entityManager.persist(foo);
>             txn.commit();
>         }
>         catch (Exception e)
>         {
>             e.printStackTrace();
>         }
> If run the same code with  MS SQL Server 2000 in place of Derby everything is 
> working. Seems to me this problem is caused by typed nature of NULL in Apache 
> Derby. If so the same problem should be with IBM DB2.
> I couldn't attach full packaged sample (don't know how). But I can send it if 
> needed.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to