hi,
what version of ojb are you using ? could you please provide the line number where the npe occurs ?
jakob
[EMAIL PROTECTED] schrieb:
Hi All,
I'm firing this at both lists as I can't figure out whether it's a bug in the code or my mapping.
I'm trying to accomplish a pretty simple mn relationship (user/group type arrangement). The mapping file for the section in question is attached below. I have some test data (also below, in dbunit dataset format) which I've verified in the database and everytime I try to load a group it throws a null pointer at me. Any assistance would be appreciated. Let me know if you would like any more information.
:Mapping File:
<class-descriptor class="com.interlinkj.ac.User" table="USERS" row-reader="com.interlinkj.db.UserRowReader"> <field-descriptor name="id" column="id" jdbc-type="INTEGER" primarykey="true" autoincrement="true"/> <field-descriptor name="firstName" column="firstname" jdbc-type="VARCHAR" nullable="false"/> <field-descriptor name="lastName" column="lastname" jdbc-type="VARCHAR" nullable="false"/> <field-descriptor name="userName" column="username" jdbc-type="VARCHAR" nullable="false"/> <field-descriptor name="passwordHash" column="credentials" jdbc-type="VARCHAR" nullable="false"/> <collection-descriptor name="groups" element-class-ref="com.interlinkj.ac.Group" indirection-table="USER_GROUP_LINK" auto-delete="link" auto-update="object" auto-retrieve="true" orderby="id" sort="ASC" > <fk-pointing-to-this-class column="user_id"/> <fk-pointing-to-element-class column="group_id"/> </collection-descriptor> </class-descriptor>
<class-descriptor class="com.interlinkj.ac.Group" table="GROUPS" row-reader="com.interlinkj.db.GroupRowReader"> <field-descriptor name="id" column="id" jdbc-type="INTEGER" primarykey="true" autoincrement="true"/> <field-descriptor name="name" column="name" jdbc-type="VARCHAR" nullable="false"/> <field-descriptor name="description" column="description" jdbc-type="VARCHAR" nullable="true"/> <field-descriptor name="type" column="type" jdbc-type="VARCHAR" nullable="false" conversion="com.interlinkj.db.GroupTypeConversion"/> <collection-descriptor name="users" element-class-ref="com.interlinkj.ac.User" indirection-table="USER_GROUP_LINK" auto-delete="link" auto-update="object" auto-retrieve="true" orderby="id" sort="ASC" > <fk-pointing-to-this-class column="group_id"/> <fk-pointing-to-element-class column="user_id"/> </collection-descriptor> </class-descriptor>
:Test Data (for those not familiar with DBUnit, the element name is the table, the attributes are the columns, and each element represents a row [in order]):
<dataset> <GROUPS id="1" type="Designer Group" name="Designer Group" description="This is a designer group."/> <GROUPS id="2" type="Data Entry Group" name="Data Entry Group" description="This is a data entry group."/> <USERS id="1" firstname="Bernard" lastname="Black" username="blblack" credentials="jamjamjam"/> <USERS id="2" firstname="Manny" lastname="Bianco" username="manny" credentials="brilliant"/> <USER_GROUP_LINK group_id="1" user_id="1"/> <USER_GROUP_LINK group_id="2" user_id="2"/> </dataset>
:Stack Trace:
java.lang.NullPointerException at org.apache.ojb.broker.accesslayer.MtoNCollectionPrefetcher.associateBatched(Unknown Source) at org.apache.ojb.broker.accesslayer.MtoNCollectionPrefetcher.prefetchRelationship(Unknown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.performRetrievalTasks(Unknown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.getCollectionByQuery(Unknown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.retrieveCollection(Unknown Source) at org.apache.ojb.broker.core.QueryReferenceBroker.retrieveCollections(Unknown Source) at org.apache.ojb.broker.accesslayer.RsIterator.getObjectFromResultSet(Unknown Source) at org.apache.ojb.broker.accesslayer.RsIterator.next(Unknown Source) at org.apache.ojb.broker.core.PersistenceBrokerImpl.getObjectByQuery(Unknown Source) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getObjectByQuery(Unknown Source) at org.apache.ojb.broker.core.DelegatingPersistenceBroker.getObjectByQuery(Unknown Source) at com.interlinkj.db.DatabaseManager.loadByFieldValue(Unknown Source) at com.interlinkj.db.GroupManager.loadById(Unknown Source) at com.interlinkj.db.TestGroupManager.testLoadWithIndividualUser(Unknown Source) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:585) at junit.framework.TestCase.runTest(TestCase.java:154) at junit.framework.TestCase.runBare(TestCase.java:127)
:Calling Code:
Criteria crit = new Criteria(); crit.addEqualTo("id", new Integer(1)); Query q = newQuery(Group.class, crit); broker = newPersistenceBroker(); //just a helper method to default broker Object tmp = broker.getObjectByQuery(q);
//Null pointer before it gets here
if(tmp == null){ throw new FindException( getShortClassName(clazzToLoad) + " with " + fieldName + " of " + fieldValue + " does not exist." ); } return (T)tmp;
------------------------------------------------------------ This email was sent from Netspace Webmail: http://www.netspace.net.au
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
