db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gus Heck <gus.h...@olin.edu>
Subject Re: Initialization of classes in Metadatamanager
Date Thu, 12 Feb 2004 22:25:24 GMT
Well, I get no new failing tests by adding this, and I can make the 
problem described work, but it turns out that any time you do 
FooClass.class it does a Class.forName that initializes anyway. So it 
seems to be that I am not following a good pattern. And maybe this 
shouldn't be encouraged since it basically breaks the use of 
FooClass.class...

This all fell out of an attempt to fix this exception:

Object exists. Instance with the same primary key is already in the 
PersistenceManager cache.
javax.jdo.JDOUserException: Object exists. Instance with the same 
primary key is already in the PersistenceManager cache.
        at com.sun.jdori.common.CacheManagerImpl.register(Unknown Source)
        at com.sun.jdori.common.PersistenceManagerImpl.register(Unknown 
Source)
        at 
com.sun.jdori.common.state.StateManagerImpl.initializeSM(Unknown Source)
        at 
com.sun.jdori.common.state.StateManagerImpl.makeAutoPersistent(Unknown 
Source)
        at 
com.sun.jdori.common.state.ReachabilityHandler$AutoPersistentProcessor.process(Unknown 
Source)
        at 
com.sun.jdori.common.state.ReachabilityHandler$AutoPersistentProcessor.processArray(Unknown

Source)
        at 
com.sun.jdori.common.state.ReachabilityHandler$AutoPersistentProcessor.process(Unknown 
Source)
        at 
com.sun.jdori.common.state.ReachabilityHandler.process(Unknown Source)
        at 
com.sun.jdori.common.state.StateManagerImpl.processReachability(Unknown 
Source)
        at 
com.sun.jdori.common.state.StateManagerImpl.makePersistent(Unknown Source)
        at com.sun.jdori.common.CacheManagerImpl.makePersistent(Unknown 
Source)
        at 
com.sun.jdori.common.PersistenceManagerImpl.makePersistentInternal(Unknown 
Source)
        at 
com.sun.jdori.common.PersistenceManagerImpl.makePersistent(Unknown Source)
        at 
com.sun.jdori.common.PersistenceManagerWrapper.makePersistent(Unknown 
Source)
        at 
org.cs101.fdb.impl.jdo.PersonImpl.aquireUniqueID(PersonImpl.java:114)
        at org.cs101.fdb.impl.jdo.PersonImpl.store(PersonImpl.java:156)
        at org.cs101.fdb.test.PersonTest.storePerson(PersonTest.java:140)
        at org.cs101.fdb.test.PersonTest.testStore(PersonTest.java:150)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

Which is really annoying because it doesn't say what object already 
exists.... I implemented InstanceCallbacks prestore on every single 
persistant class I have and made them all print something unique, and 
apparently this error is occuring before any instance of any persistent 
class is stored. (unless something is sneaking in without instance 
callbacks). Alternately, things are getting cached before I make them 
persistent which seems wrong. If I ignore this exception by catching it, 
commit gives me messages about SQL errors because PERSON_ID in my 
indirection table is not allowed to be null. It would seem that an 
instance with id=null is getting cached and then re-cached before any 
jdoPreStore calls are made. Alternately, the error message is 
inappropriate and  nearly anything is happening. The really vexing thing 
I set the Id field immediately before this exception is generated so I 
don't see how it can be null.

Anyone have a clue what I am doing wrong?

-Gus

Gus Heck wrote:

> I'll tweak the true to a false in ClassHelper.getClass (line 89) and 
> see what breaks in the tests if anything, and let you know how it 
> turns out... If all seems ok in your tests and my app I'll send you a 
> micro patch :) I've been browsing through and looking at where the 
> class is pulled back out of the class descriptor, and I see nothing 
> that looks like reflection to find the values of initialized fields, 
> which is the only thing I can think of that would care if the class 
> got initialized. before it was put in there... Mostly it seems to be 
> used for getting the class name, or finding the toplevel class.
>
> -Gus
>
> Armin Waibel wrote:
>
>> Hi Gus,
>>
>> Gus Heck wrote:
>>
>>> It seems that in the process of loading MetadataManager each 
>>> persistant class is loaded with a class.forName(classname, true, 
>>> Thread.currentThread().getContextClassLoader()). (in 
>>> org.apache.ojb.broker.util.ClassHelper) I think the second argument 
>>> true is causing java to do a test initialization of the 0 arg 
>>> constructor. Is this neccessary? I am getting the following stack 
>>> trace when I tried to have a persistent class grab an ID from a 
>>> static instance of my own IDManager class. The result was an NPE in 
>>> the *constructor* of my class which really shouldn't be called until 
>>> I actually instantiate an instance. Since IdManager is itself 
>>> persistant I can't set this value at class initialization for the 
>>> same reason....
>>>
>>> Does passing true to class.forName have an important benefit that I 
>>> am not aware of?
>>
>>
>>
>> For the pc objects AFAIK no! Interesting problem. All metadata 
>> classes use the 'initialize true' parameter. The class object was 
>> only loaded to verifiy the existence of the class on metadata read, 
>> no need to initialize the pc object.
>> Should we change this?
>>
>> regards,
>> Armin
>>
>>>
>>> Gus
>>>
>>> Exception in thread "main" java.lang.ExceptionInInitializerError
>>>        at java.lang.Class.forName0(Native Method)
>>>        at java.lang.Class.forName(Class.java:219)
>>>        at 
>>> org.apache.ojb.broker.util.ClassHelper.getClass(ClassHelper.java:21)
>>>        at 
>>> org.apache.ojb.broker.util.ClassHelper.getClass(ClassHelper.java:89)
>>>        at 
>>> org.apache.ojb.broker.metadata.RepositoryXmlHandler.startElement(RepositoryXmlHandler.java:235)

>>>
>>>        at 
>>> org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1637)
>>>        at org.apache.crimson.parser.Parser2.content(Parser2.java:1926)
>>>        at 
>>> org.apache.crimson.parser.Parser2.externalParsedEntity(Parser2.java:2984) 
>>>
>>>        at 
>>> org.apache.crimson.parser.Parser2.expandEntityInContent(Parser2.java:2702) 
>>>
>>>        at 
>>> org.apache.crimson.parser.Parser2.maybeReferenceInContent(Parser2.java:2569)

>>>
>>>        at org.apache.crimson.parser.Parser2.content(Parser2.java:1980)
>>>        at 
>>> org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1654)
>>>        at 
>>> org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:634)
>>>        at org.apache.crimson.parser.Parser2.parse(Parser2.java:333)
>>>        at 
>>> org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:448)
>>>        at 
>>> org.apache.ojb.broker.metadata.RepositoryPersistor.readMetadataFromXML(RepositoryPersistor.java:343)

>>>
>>>        at 
>>> org.apache.ojb.broker.metadata.RepositoryPersistor.buildRepository(RepositoryPersistor.java:300)

>>>
>>>        at 
>>> org.apache.ojb.broker.metadata.RepositoryPersistor.readDescriptorRepository(RepositoryPersistor.java:215)

>>>
>>>        at 
>>> org.apache.ojb.broker.metadata.MetadataManager.init(MetadataManager.java:133)

>>>
>>>        at 
>>> org.apache.ojb.broker.metadata.MetadataManager.<init>(MetadataManager.java:123)

>>>
>>>        at 
>>> org.apache.ojb.broker.metadata.MetadataManager.<clinit>(MetadataManager.java:112)

>>>
>>>        at 
>>> org.apache.ojb.broker.core.PersistenceBrokerFactoryBaseImpl.getDefaultKey(PersistenceBrokerFactoryBaseImpl.java:114)

>>>
>>>        at 
>>> org.apache.ojb.broker.core.PersistenceBrokerFactoryBaseImpl.defaultPersistenceBroker(PersistenceBrokerFactoryBaseImpl.java:196)

>>>
>>>        at 
>>> org.apache.ojb.broker.PersistenceBrokerFactory.defaultPersistenceBroker(PersistenceBrokerFactory.java:104)

>>>
>>>        at 
>>> org.cs101.fdb.impl.jdo.PersistenceHelper.getDirectDBCon(PersistenceHelper.java:145)

>>>
>>>        at 
>>> org.cs101.fdb.impl.jdo.PersistenceHelper.<clinit>(PersistenceHelper.java:74)

>>>
>>>        at org.cs101.fdb.test.DbTestCase.<clinit>(DbTestCase.java:36)
>>>        at java.lang.Class.forName0(Native Method)
>>>        at java.lang.Class.forName(Class.java:141)
>>>        at 
>>> org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.<init>(JUnitTestRunner.java:237)

>>>
>>>        at 
>>> org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.<init>(JUnitTestRunner.java:210)

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

>>>
>>> Caused by: java.lang.NullPointerException
>>>        at org.cs101.fdb.impl.jdo.PersonBase.<init>(PersonBase.java:87)
>>>        at org.cs101.fdb.impl.jdo.PersonBase.<clinit>(PersonBase.java)
>>>        ... 32 more
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> 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
>>
>
>
>
> ---------------------------------------------------------------------
> 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