db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ate Douma <...@douma.nu>
Subject Re: Jetspeed-2: Cannot get FieldConversion working on autoIncrement field
Date Fri, 23 Apr 2004 11:52:08 GMT
I've been browsing through the bugs in scarab and issue OJB136 look very 
much like our problem, only in our case it concern a PK field while 
OJB136 is related to FK fields. Can it be that the fix for OJB136 is now 
causing our problems with autoincrement PK fields with a FieldConversion?

Note: I'm now on the ojb-dev list so just posting a response there I 
will see as well.

Regards,

Ate

Ate Douma wrote:

> Hello,
> 
> I'm trying to get the OJB model for Jetspeed 2 working against an Oracle 
> database (9.2.0.1).
> Up until now the model was only used against HSQLDB. After trying to 
> switch to Oracle a few blocking issues were encountered which we didn't 
> notice when using HSQLDB.
> 
> One of these is that for a PK of a table we use a custom object which is 
> mapped onto a INTEGER field in the database. That field also has 
> autoincrement=true.
> On HSQLDB we didn't have a FieldConversion defined for the object which 
> strangly does work (HSQLDB probably *fixes* this error with new 
> Integer(object.toString())).
> On Oracle it throwed correctly a ClassCastException (by the Oracle jdbc 
> driver).
> So now we defined the FieldConversion but were confronted with another
> exception: IllegalArgumentException from 
> sun.reflect.UnsafeIntegerFieldAccessorImpl.set (see below).
> 
> The field definition looks like this:
> 
>       <field-descriptor
>          name="id"
>          column="APPLICATION_ID"
>          jdbc-type="INTEGER"
>          primarykey="true"
>          autoincrement="true" 
> conversion="org.apache.jetspeed.util.ojb.ObjectIDtoLongFieldConversion"
>       />
> 
> and the FieldConvertion is as follows:
> 
> public class ObjectIDtoLongFieldConversion implements FieldConversion
> {
>    public Object javaToSql(Object arg0) throws ConversionException
>     {
>         if (arg0 instanceof JetspeedObjectID)
>         {
>             JetspeedObjectID oid = (JetspeedObjectID) arg0;
>             return new Integer(oid.intValue());
>         }
>         else
>         {
>             return arg0;
>         }
>     }
> 
>     public Object sqlToJava(Object arg0) throws ConversionException
>     {
>         if (arg0 instanceof Number)
>         {
>             return new JetspeedObjectID(((Number)arg0).intValue());
>         }
>         else
>         {
>             return arg0;
>         }
>     }
> }
> 
> When running a unit test we get the following errors:
> 
> [PersistentField] ERROR: while set field:
> [try to set 'object value' in 'target object'
> target obj class: 
> org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImplid
> target field type: int
> object value class: org.apache.jetspeed.util.JetspeedObjectID
> object value: 41
> ]
> null
> ------------- ---------------- ---------------
> ------------- Standard Error -----------------
> java.lang.IllegalArgumentException
>     at 
> sun.reflect.UnsafeIntegerFieldAccessorImpl.set(UnsafeIntegerFieldAccessorImpl.java:80)

> 
>     at java.lang.reflect.Field.set(Field.java:519)
>     at 
> org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessImpl.doSet(PersistentFieldDirectAccessImpl.java:71)

> 
>     at 
> org.apache.ojb.broker.metadata.fieldaccess.AbstractPersistentField.set(AbstractPersistentField.java:98)

> 
>     at 
> org.apache.ojb.broker.util.BrokerHelper.getAutoIncrementValue(BrokerHelper.java:302)

> 
>     at 
> org.apache.ojb.broker.util.BrokerHelper.getValuesForObject(BrokerHelper.java:345) 
> 
>     at 
> org.apache.ojb.broker.util.BrokerHelper.getKeyValues(BrokerHelper.java:171)
>     at org.apache.ojb.broker.Identity.init(Identity.java:118)
>     at org.apache.ojb.broker.Identity.<init>(Identity.java:87)
>     at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.store(PersistenceBrokerImpl.java:679)

> 
>     at 
> org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(DelegatingPersistenceBroker.java:174)

> 
>     at 
> org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(DelegatingPersistenceBroker.java:174)

> 
>     at 
> org.apache.jetspeed.components.persistence.store.ojb.pb.PBStore.store(PBStore.java:362)

> 
>     at 
> org.apache.jetspeed.components.persistence.store.ojb.pb.PBStore.makePersistent(PBStore.java:346)

> 
>     at 
> org.apache.jetspeed.components.portletentity.TestPortletEntityAccessComponent.setupTestData(TestPortletEntityAccessComponent.java:162)

> 
>     at 
> org.apache.jetspeed.components.portletentity.TestPortletEntityAccessComponent.setUp(TestPortletEntityAccessComponent.java:66)

> 
>     at junit.framework.TestCase.runBare(TestCase.java:125)
>     at junit.framework.TestResult$1.protect(TestResult.java:106)
>     at junit.framework.TestResult.runProtected(TestResult.java:124)
>     at junit.framework.TestResult.run(TestResult.java:109)
>     at junit.framework.TestCase.run(TestCase.java:118)
>     at junit.framework.TestSuite.runTest(TestSuite.java:208)
>     at 
> org.apache.jetspeed.components.ComponentAwareTestSuite.runTest(ComponentAwareTestSuite.java:141)

> 
>     at junit.framework.TestSuite.run(TestSuite.java:203)
>     at 
> org.apache.jetspeed.components.ComponentAwareTestSuite.run(ComponentAwareTestSuite.java:108)

> 
>     at 
> org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.run(JUnitTestRunner.java:325)

> 
>     at 
> org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(JUnitTestRunner.java:536)

> 
> ------------- ---------------- ---------------
> 
> Testcase: testEntities took 0.75 sec
>     Caused an ERROR
> Can not init Identity for given object 
> org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl@1d2b9b7 
> 
> org.apache.ojb.broker.metadata.ClassNotPersistenceCapableException: Can 
> not init Identity for given object 
> org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl@1d2b9b7 
> 
>     at org.apache.ojb.broker.Identity.init(Identity.java:125)
>     at org.apache.ojb.broker.Identity.<init>(Identity.java:87)
>     at 
> org.apache.ojb.broker.core.PersistenceBrokerImpl.store(PersistenceBrokerImpl.java:679)

> 
>     at 
> org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(DelegatingPersistenceBroker.java:174)

> 
>     at 
> org.apache.ojb.broker.core.DelegatingPersistenceBroker.store(DelegatingPersistenceBroker.java:174)

> 
>     at 
> org.apache.jetspeed.components.persistence.store.ojb.pb.PBStore.store(PBStore.java:362)

> 
>     at 
> org.apache.jetspeed.components.persistence.store.ojb.pb.PBStore.makePersistent(PBStore.java:346)

> 
>     at 
> org.apache.jetspeed.components.portletentity.TestPortletEntityAccessComponent.setupTestData(TestPortletEntityAccessComponent.java:162)

> 
>     at 
> org.apache.jetspeed.components.portletentity.TestPortletEntityAccessComponent.setUp(TestPortletEntityAccessComponent.java:66)

> 
>     at 
> org.apache.jetspeed.components.ComponentAwareTestSuite.runTest(ComponentAwareTestSuite.java:141)

> 
>     at 
> org.apache.jetspeed.components.ComponentAwareTestSuite.run(ComponentAwareTestSuite.java:108)

> 
> Caused by: org.apache.ojb.broker.PersistenceBrokerException: Error while 
> trying to autoincrement field class 
> org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl#id
>     at 
> org.apache.ojb.broker.util.BrokerHelper.getAutoIncrementValue(BrokerHelper.java:307)

> 
>     at 
> org.apache.ojb.broker.util.BrokerHelper.getValuesForObject(BrokerHelper.java:345) 
> 
>     at 
> org.apache.ojb.broker.util.BrokerHelper.getKeyValues(BrokerHelper.java:171)
>     at org.apache.ojb.broker.Identity.init(Identity.java:118)
>     ... 19 more
> Caused by: org.apache.ojb.broker.metadata.MetadataException: Error 
> setting field:id in 
> object:org.apache.jetspeed.om.portlet.impl.PortletApplicationDefinitionImpl
>     at 
> org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessImpl.doSet(PersistentFieldDirectAccessImpl.java:88)

> 
>     at 
> org.apache.ojb.broker.metadata.fieldaccess.AbstractPersistentField.set(AbstractPersistentField.java:98)

> 
>     at 
> org.apache.ojb.broker.util.BrokerHelper.getAutoIncrementValue(BrokerHelper.java:302)

> 
>     ... 22 more
> Caused by: java.lang.IllegalArgumentException
>     at 
> sun.reflect.UnsafeIntegerFieldAccessorImpl.set(UnsafeIntegerFieldAccessorImpl.java:80)

> 
>     at java.lang.reflect.Field.set(Field.java:519)
>     at 
> org.apache.ojb.broker.metadata.fieldaccess.PersistentFieldDirectAccessImpl.doSet(PersistentFieldDirectAccessImpl.java:71)

> 
>     ... 24 more
> 
> 
> Now, I have been looking long and hard at the code in BrokerHelper but I 
>  don't have a real understanding whats going on.
> 
> As far as I can tell the generated id value has been converted to our 
> JetspeedObjectID correctly but then OJB tries to set that back into the 
> persistentField without converting it back (or maybe I got this the 
> wrong way around).
> 
> We would very much appriciate any help because this really is a Blocking 
> situation for us.
> 
> If possible please report back on this to the Jetspeed dev list 
> (jetspeed-dev@jakarta.apache.org) and/or directly to me: ate@douma.nu as 
> I'm currently not subscribed to the ojb list.
> 
> Regards,
> 
> Ate Douma
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-dev-help@db.apache.org
> 
> 
> 
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message