You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-user@db.apache.org by Ray <ra...@yahoo.co.uk> on 2004/12/24 09:37:58 UTC

Referenced object not being picked up ...

Hi there ...

I wonder if someone could help me with a little snag I've hit with OJB.

I retrieve an object using the getObjectByIdentity call, but for some 
reason, I cannot get hold of the objects that it references.

Here's the repository definition:

---------------------------------------
<class-descriptor
     class="com.organisation.resources.schemas.database.PageCalendar"
     table="pageCalendar">

     <field-descriptor column="id"
         jdbc-type="BIGINT"
         name="id"
         primarykey="true"
         autoincrement="true"
         access="readonly"/>

     <field-descriptor
         name="active"
         column="active"
         jdbc-type="BIT"/>

     <field-descriptor
         name="showFrom"
         column="showFrom"
         jdbc-type="DATE"/>

     <field-descriptor
         name="showTo"
         column="showTo"
         jdbc-type="DATE"/>

     <field-descriptor
         name="contentId"
         column="contentId"
         jdbc-type="BIGINT"/>

     <field-descriptor
         name="templateId"
         column="templateId"
         jdbc-type="BIGINT"/>

     <reference-descriptor
        name="content"
        class-ref="com.organisation.resources.schemas.database.Content">

        <foreignkey field-ref="contentId"/>

     </reference-descriptor>

     <reference-descriptor
        name="template"
        class-ref="com.organisation.resources.schemas.database.Content">

        <foreignkey field-ref="templateId"/>

     </reference-descriptor>

</class-descriptor>
---------------------------------------

Now if I use a query to retrieve the record, then the references to 
content and template work fine .... btu if I retrieve the pageCalendar 
object using a primary key, and then try to call ...

pageCalendar.getContent or pageCalendar.getTemplate, I get null values 
returned.

I've checked the databases (MySQL), and the records are all saved 
correctly, and the references have been set up; so I'm at a bit of a 
loss as to why this doesn't work.

Any pointers would be very much appreciated ...


... and if you celebrate it, Merry Christmas! .... :-D




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


Re: Referenced object not being picked up ...

Posted by Ray <ra...@yahoo.co.uk>.
Thanks Jakob ... :-)

retrieveAllReferences did the trick ...


Jakob Braeuchi wrote:
> hi ray,
> 
> when getObjectByIdentity does not trigger a select then the object is 
> already in the cache.
> 
> from your sqls i only can see inserts into pageCalendar. try to clear 
> the cache after the inserts and then do getObjectByIdentity(); this 
> should trigger a select.
> 
> btw. have you tried to retrieve all references ? 
> broker#retrieveAllReferences(obj)
> 
> jakob
> 
> Ray schrieb:
> 
>> Hi Jakob.
>>
>> Got p6spy running, but the result was pretty much the same; all I got 
>> was this:
>>
>> ----------------------------------------------------
>> 1104080183441|0|0|statement|INSERT INTO pageCalendar 
>> (active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) 
>> |INSERT INTO pageCalendar 
>> (active,showFrom,showTo,contentId,templateId) VALUES ('true','Sun Dec 
>> 26 16:56:14 GMT 2004','Sun Dec 26 16:56:14 GMT 2004','1','2')
>> 1104080183472|10|0|statement||SELECT LAST_INSERT_ID() FROM 
>> pageCalendar LIMIT 1
>> 1104080183502|0|0|commit||
>> 1104080851692|60|0|statement|INSERT INTO pageCalendar 
>> (active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) 
>> |INSERT INTO pageCalendar 
>> (active,showFrom,showTo,contentId,templateId) VALUES ('true','Sun Dec 
>> 26 17:07:19 GMT 2004','Sun Dec 26 17:07:19 GMT 2004','1','2')
>> 1104080851742|20|0|statement||SELECT LAST_INSERT_ID() FROM 
>> pageCalendar LIMIT 1
>> 1104080851783|0|0|commit||
>> 1104080993226|0|0|statement|INSERT INTO pageCalendar 
>> (active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) 
>> |INSERT INTO pageCalendar 
>> (active,showFrom,showTo,contentId,templateId) VALUES ('true','Sun Dec 
>> 26 17:09:44 GMT 2004','Sun Dec 26 17:09:44 GMT 2004','1','2')
>> 1104080993256|20|0|statement||SELECT LAST_INSERT_ID() FROM 
>> pageCalendar LIMIT 1
>> 1104080993296|0|0|commit||
>> 1104081197389|0|0|statement|INSERT INTO pageCalendar 
>> (active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) 
>> |INSERT INTO pageCalendar 
>> (active,showFrom,showTo,contentId,templateId) VALUES ('true','Sun Dec 
>> 26 17:13:08 GMT 2004','Sun Dec 26 17:13:08 GMT 2004','1','2')
>> 1104081197440|20|0|statement||SELECT LAST_INSERT_ID() FROM 
>> pageCalendar LIMIT 1
>> 1104081197480|0|0|commit||
>> 1104084153861|231|0|statement|INSERT INTO pageCalendar 
>> (active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) 
>> |INSERT INTO pageCalendar 
>> (active,showFrom,showTo,contentId,templateId) VALUES ('true','Sun Dec 
>> 26 18:02:22 GMT 2004','Sun Dec 26 18:02:22 GMT 2004','1','2')
>> 1104084153921|20|0|statement||SELECT LAST_INSERT_ID() FROM 
>> pageCalendar LIMIT 1
>> 1104084154021|10|0|rollback||
>> 1104084379075|0|0|statement|INSERT INTO pageCalendar 
>> (active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) 
>> |INSERT INTO pageCalendar 
>> (active,showFrom,showTo,contentId,templateId) VALUES ('true','Sun Dec 
>> 26 18:06:10 GMT 2004','Sun Dec 26 18:06:10 GMT 2004','1','2')
>> 1104084379135|20|0|statement||SELECT LAST_INSERT_ID() FROM 
>> pageCalendar LIMIT 1
>> 1104084379175|0|0|commit||
>> 1104086278976|150|0|statement|INSERT INTO pageCalendar 
>> (active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) 
>> |INSERT INTO pageCalendar 
>> (active,showFrom,showTo,contentId,templateId) VALUES ('true','Sun Dec 
>> 26 18:37:49 GMT 2004','Sun Dec 26 18:37:49 GMT 2004','1','2')
>> 1104086279057|20|0|statement||SELECT LAST_INSERT_ID() FROM 
>> pageCalendar LIMIT 1
>> 1104086279097|0|0|commit||
>> ----------------------------------------------------------
>>
>> Seems that the getObjectIdentity doesn't generate any SQL code that 
>> shows up.
>>
>> As far as I can tell, what I've done seems fine, except that I 
>> referencing the same table twice; my only guess is that that is 
>> causing OJB a problem (other references work OK).
>>
>>
>>
>> Jakob Braeuchi wrote:
>>
>>> hi ray,
>>>
>>> i'd better use p6spy to log the sql.
>>>
>>> replace the mysql-driver in database.xml with the p6spy-driver:
>>> ...
>>> driver="org.hsqldb.jdbcDriver"
>>> ...
>>>
>>> in spy.properties you'll have to tell p6spy the real-driver:
>>> ...
>>> # mysql Connector/J driver
>>> realdriver=com.mysql.jdbc.Driver
>>> ...
>>>
>>>
>>> jakob
>>>
>>> Ray schrieb:
>>>
>>>> Yep. Okay.
>>>>
>>>> --------------------------------------
>>>> 12:17:32,875 DEBUG ConnectionFactoryPooledImpl:96 - createPool was 
>>>> called
>>>> 12:17:32,946 DEBUG ConnectionFactoryPooledImpl:230 - makeObject called
>>>> 12:17:36,390 DEBUG ConnectionFactoryAbstractImpl:273 - Create new 
>>>> connection using DriverManager: com.mysql.jdbc.Connection@79e304
>>>> 12:17:36,441 DEBUG ConnectionManagerImpl:118 - Request new 
>>>> connection from ConnectionFactory: com.mysql.jdbc.Connection@79e304
>>>> 12:17:36,471 DEBUG ConnectionManagerImpl:156 - localBegin was called 
>>>> for con com.mysql.jdbc.Connection@79e304
>>>> 12:17:36,481 DEBUG ConnectionManagerImpl:159 - Try to change 
>>>> autoCommit state to 'false'
>>>> 12:17:36,631  INFO PersistenceBrokerImpl:777 - Cascade store for 
>>>> this reference-descriptor (content) was set to false.
>>>> 12:17:36,641  INFO PersistenceBrokerImpl:777 - Cascade store for 
>>>> this reference-descriptor (template) was set to false.
>>>> 12:17:36,941 DEBUG JdbcAccessImpl:182 - executeInsert : 
>>>> com.organisation.resources.schemas.database.PageCalendar@1a116c9
>>>> 12:17:36,971 DEBUG SqlGeneratorDefaultImpl:114 - SQL:INSERT INTO 
>>>> pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
>>>> (?,?,?,?,?)
>>>> 12:17:37,092 DEBUG JdbcAccessImpl:196 - executeInsert: 
>>>> com.mysql.jdbc.PreparedStatement@3fa5ac: INSERT INTO pageCalendar 
>>>> (active,showFrom,showTo,contentId,templateId) VALUES 
>>>> ('1','2004-12-24','2004-12-24',1,2)
>>>> 12:17:37,252 DEBUG StatementManager:89 - closeResources was called
>>>> 12:17:37,272 DEBUG SequenceManagerNativeImpl:231 - After store - 
>>>> newid=5
>>>> 12:17:37,282  INFO CacheDistributor:98 - Create new 
>>>> ObjectCacheImplementation for 'school'
>>>> 12:17:37,302 DEBUG ConnectionManagerImpl:170 - commit was called
>>>> 12:17:37,312 DEBUG PersistenceBrokerImpl:329 - PB.close was called: 
>>>> org.apache.ojb.broker.core.PersistenceBrokerImpl@18825b3
>>>> New page calendar id is ==> 5
>>>> 12:17:37,322 DEBUG PersistenceBrokerFactoryDefaultImpl:86 - Obtain 
>>>> broker from pool, used PBKey is org.apache.ojb.broker.PBKey: 
>>>> jcdAlias=school, user=*****, password=*****
>>>> 12:17:37,342 DEBUG PersistenceBrokerImpl:1360 - getObjectByIdentity 
>>>> com.organisation.resources.schemas.database.PageCalendar{5}
>>>> 12:17:37,352 DEBUG PersistenceBrokerImpl:329 - PB.close was called: 
>>>> org.apache.ojb.broker.core.PersistenceBrokerImpl@18825b3
>>>> Retrieved page calendar id is ==> 5
>>>>
>>>> junit.framework.AssertionFailedError: Must have some content
>>>>     at 
>>>> com.organisation.database.delegate.DelegateTest.testGetPageCalendarById(DelegateTest.java:338) 
>>>>
>>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>     at 
>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
>>>>
>>>>     at 
>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
>>>>
>>>>     at 
>>>> com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31) 
>>>>
>>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>>     at 
>>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
>>>>
>>>>     at 
>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
>>>>
>>>>     at 
>>>> com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
>>>>
>>>>
>>>> Process finished with exit code -1
>>>>
>>>> -----------------------------------------------------
>>>>
>>>> There is a bit of SQL that inserts the record, I then try to read it 
>>>> back. The record comes back Ok with the getObjectByIdentity (which 
>>>> doesn't seem to generate any SQL), but no objects attached, which I 
>>>> try to access with a bit of test code ...
>>>>
>>>> -----------------------------------------------------
>>>>
>>>>         pageCalendar = dao.getPageCalendarById(id);
>>>>
>>>>         System.out.println("Retrieved page calendar id is ==> " + 
>>>> pageCalendar.getId());
>>>>         assertTrue("The ids should be equal", pageCalendar.getId() 
>>>> == id);
>>>>
>>>>         Content content = pageCalendar.getContent();
>>>>         Content template = pageCalendar.getTemplate();
>>>>
>>>>         assertNotNull("Must have some content", content);
>>>>
>>>>         System.out.println("Content ==> " + content.getTitle());
>>>>         System.out.println("Template ==> " + template.getTitle());
>>>> ---------------------------------------------------------
>>>>
>>>>
>>>>    public PageCalendar getPageCalendarById(long id, 
>>>> PersistenceBroker broker) throws OperationException {
>>>>
>>>>         Identity oid = 
>>>> broker.serviceIdentity().buildIdentity(PageCalendar.class, new 
>>>> Long(id));
>>>>         PageCalendar pageCalendar = (PageCalendar) 
>>>> broker.getObjectByIdentity(oid);
>>>>         return pageCalendar;
>>>>     }
>>>>
>>>>
>>>> Jakob Braeuchi wrote:
>>>>
>>>>> hi ray,
>>>>>
>>>>> sorry i missed that. could you please post the generated sql.
>>>>>
>>>>> jakob
>>>>>
>>>>> Ray schrieb:
>>>>>
>>>>>> Thanks Jakob ...
>>>>>>
>>>>>> I tried addind the auto-retrieve and it had no effect (I think 
>>>>>> that auto-retrieve defaults to 'true' anyway).
>>>>>>
>>>>>> One thing that has occurred to me, is that both references point 
>>>>>> to the same table (content), so could that be causing OJB a problem?
>>>>>>
>>>>>>
>>>>>> Jakob Braeuchi wrote:
>>>>>>
>>>>>>> hi ray,
>>>>>>>
>>>>>>> to retrieve referenced objects automatically you'll have to use 
>>>>>>> auto-retrieve='true' in the reference descriptor.
>>>>>>>
>>>>>>> hth
>>>>>>> jakob
>>>>>>>
>>>>>>> Ray schrieb:
>>>>>>>
>>>>>>>> Hi there ...
>>>>>>>>
>>>>>>>> I wonder if someone could help me with a little snag I've hit 
>>>>>>>> with OJB.
>>>>>>>>
>>>>>>>> I retrieve an object using the getObjectByIdentity call, but for 
>>>>>>>> some reason, I cannot get hold of the objects that it references.
>>>>>>>>
>>>>>>>> Here's the repository definition:
>>>>>>>>
>>>>>>>> ---------------------------------------
>>>>>>>> <class-descriptor
>>>>>>>>     
>>>>>>>> class="com.organisation.resources.schemas.database.PageCalendar"
>>>>>>>>     table="pageCalendar">
>>>>>>>>
>>>>>>>>     <field-descriptor column="id"
>>>>>>>>         jdbc-type="BIGINT"
>>>>>>>>         name="id"
>>>>>>>>         primarykey="true"
>>>>>>>>         autoincrement="true"
>>>>>>>>         access="readonly"/>
>>>>>>>>
>>>>>>>>     <field-descriptor
>>>>>>>>         name="active"
>>>>>>>>         column="active"
>>>>>>>>         jdbc-type="BIT"/>
>>>>>>>>
>>>>>>>>     <field-descriptor
>>>>>>>>         name="showFrom"
>>>>>>>>         column="showFrom"
>>>>>>>>         jdbc-type="DATE"/>
>>>>>>>>
>>>>>>>>     <field-descriptor
>>>>>>>>         name="showTo"
>>>>>>>>         column="showTo"
>>>>>>>>         jdbc-type="DATE"/>
>>>>>>>>
>>>>>>>>     <field-descriptor
>>>>>>>>         name="contentId"
>>>>>>>>         column="contentId"
>>>>>>>>         jdbc-type="BIGINT"/>
>>>>>>>>
>>>>>>>>     <field-descriptor
>>>>>>>>         name="templateId"
>>>>>>>>         column="templateId"
>>>>>>>>         jdbc-type="BIGINT"/>
>>>>>>>>
>>>>>>>>     <reference-descriptor
>>>>>>>>        name="content"
>>>>>>>>        
>>>>>>>> class-ref="com.organisation.resources.schemas.database.Content">
>>>>>>>>
>>>>>>>>        <foreignkey field-ref="contentId"/>
>>>>>>>>
>>>>>>>>     </reference-descriptor>
>>>>>>>>
>>>>>>>>     <reference-descriptor
>>>>>>>>        name="template"
>>>>>>>>        
>>>>>>>> class-ref="com.organisation.resources.schemas.database.Content">
>>>>>>>>
>>>>>>>>        <foreignkey field-ref="templateId"/>
>>>>>>>>
>>>>>>>>     </reference-descriptor>
>>>>>>>>
>>>>>>>> </class-descriptor>
>>>>>>>> ---------------------------------------
>>>>>>>>
>>>>>>>> Now if I use a query to retrieve the record, then the references 
>>>>>>>> to content and template work fine .... btu if I retrieve the 
>>>>>>>> pageCalendar object using a primary key, and then try to call ...
>>>>>>>>
>>>>>>>> pageCalendar.getContent or pageCalendar.getTemplate, I get null 
>>>>>>>> values returned.
>>>>>>>>
>>>>>>>> I've checked the databases (MySQL), and the records are all 
>>>>>>>> saved correctly, and the references have been set up; so I'm at 
>>>>>>>> a bit of a loss as to why this doesn't work.
>>>>>>>>
>>>>>>>> Any pointers would be very much appreciated ...
>>>>>>>>
>>>>>>>>
>>>>>>>> ... and if you celebrate it, Merry Christmas! .... :-D
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> --------------------------------------------------------------------- 
>>>>>>>>
>>>>>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>> --------------------------------------------------------------------- 
>>>>>>>
>>>>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>>
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 


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


Re: Referenced object not being picked up ...

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi ray,

when getObjectByIdentity does not trigger a select then the object is 
already in the cache.

from your sqls i only can see inserts into pageCalendar. try to clear 
the cache after the inserts and then do getObjectByIdentity(); this 
should trigger a select.

btw. have you tried to retrieve all references ? 
broker#retrieveAllReferences(obj)

jakob

Ray schrieb:
> Hi Jakob.
> 
> Got p6spy running, but the result was pretty much the same; all I got 
> was this:
> 
> ----------------------------------------------------
> 1104080183441|0|0|statement|INSERT INTO pageCalendar 
> (active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) |INSERT 
> INTO pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
> ('true','Sun Dec 26 16:56:14 GMT 2004','Sun Dec 26 16:56:14 GMT 
> 2004','1','2')
> 1104080183472|10|0|statement||SELECT LAST_INSERT_ID() FROM pageCalendar 
> LIMIT 1
> 1104080183502|0|0|commit||
> 1104080851692|60|0|statement|INSERT INTO pageCalendar 
> (active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) |INSERT 
> INTO pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
> ('true','Sun Dec 26 17:07:19 GMT 2004','Sun Dec 26 17:07:19 GMT 
> 2004','1','2')
> 1104080851742|20|0|statement||SELECT LAST_INSERT_ID() FROM pageCalendar 
> LIMIT 1
> 1104080851783|0|0|commit||
> 1104080993226|0|0|statement|INSERT INTO pageCalendar 
> (active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) |INSERT 
> INTO pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
> ('true','Sun Dec 26 17:09:44 GMT 2004','Sun Dec 26 17:09:44 GMT 
> 2004','1','2')
> 1104080993256|20|0|statement||SELECT LAST_INSERT_ID() FROM pageCalendar 
> LIMIT 1
> 1104080993296|0|0|commit||
> 1104081197389|0|0|statement|INSERT INTO pageCalendar 
> (active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) |INSERT 
> INTO pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
> ('true','Sun Dec 26 17:13:08 GMT 2004','Sun Dec 26 17:13:08 GMT 
> 2004','1','2')
> 1104081197440|20|0|statement||SELECT LAST_INSERT_ID() FROM pageCalendar 
> LIMIT 1
> 1104081197480|0|0|commit||
> 1104084153861|231|0|statement|INSERT INTO pageCalendar 
> (active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) |INSERT 
> INTO pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
> ('true','Sun Dec 26 18:02:22 GMT 2004','Sun Dec 26 18:02:22 GMT 
> 2004','1','2')
> 1104084153921|20|0|statement||SELECT LAST_INSERT_ID() FROM pageCalendar 
> LIMIT 1
> 1104084154021|10|0|rollback||
> 1104084379075|0|0|statement|INSERT INTO pageCalendar 
> (active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) |INSERT 
> INTO pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
> ('true','Sun Dec 26 18:06:10 GMT 2004','Sun Dec 26 18:06:10 GMT 
> 2004','1','2')
> 1104084379135|20|0|statement||SELECT LAST_INSERT_ID() FROM pageCalendar 
> LIMIT 1
> 1104084379175|0|0|commit||
> 1104086278976|150|0|statement|INSERT INTO pageCalendar 
> (active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) |INSERT 
> INTO pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
> ('true','Sun Dec 26 18:37:49 GMT 2004','Sun Dec 26 18:37:49 GMT 
> 2004','1','2')
> 1104086279057|20|0|statement||SELECT LAST_INSERT_ID() FROM pageCalendar 
> LIMIT 1
> 1104086279097|0|0|commit||
> ----------------------------------------------------------
> 
> Seems that the getObjectIdentity doesn't generate any SQL code that 
> shows up.
> 
> As far as I can tell, what I've done seems fine, except that I 
> referencing the same table twice; my only guess is that that is causing 
> OJB a problem (other references work OK).
> 
> 
> 
> Jakob Braeuchi wrote:
> 
>> hi ray,
>>
>> i'd better use p6spy to log the sql.
>>
>> replace the mysql-driver in database.xml with the p6spy-driver:
>> ...
>> driver="org.hsqldb.jdbcDriver"
>> ...
>>
>> in spy.properties you'll have to tell p6spy the real-driver:
>> ...
>> # mysql Connector/J driver
>> realdriver=com.mysql.jdbc.Driver
>> ...
>>
>>
>> jakob
>>
>> Ray schrieb:
>>
>>> Yep. Okay.
>>>
>>> --------------------------------------
>>> 12:17:32,875 DEBUG ConnectionFactoryPooledImpl:96 - createPool was 
>>> called
>>> 12:17:32,946 DEBUG ConnectionFactoryPooledImpl:230 - makeObject called
>>> 12:17:36,390 DEBUG ConnectionFactoryAbstractImpl:273 - Create new 
>>> connection using DriverManager: com.mysql.jdbc.Connection@79e304
>>> 12:17:36,441 DEBUG ConnectionManagerImpl:118 - Request new connection 
>>> from ConnectionFactory: com.mysql.jdbc.Connection@79e304
>>> 12:17:36,471 DEBUG ConnectionManagerImpl:156 - localBegin was called 
>>> for con com.mysql.jdbc.Connection@79e304
>>> 12:17:36,481 DEBUG ConnectionManagerImpl:159 - Try to change 
>>> autoCommit state to 'false'
>>> 12:17:36,631  INFO PersistenceBrokerImpl:777 - Cascade store for this 
>>> reference-descriptor (content) was set to false.
>>> 12:17:36,641  INFO PersistenceBrokerImpl:777 - Cascade store for this 
>>> reference-descriptor (template) was set to false.
>>> 12:17:36,941 DEBUG JdbcAccessImpl:182 - executeInsert : 
>>> com.organisation.resources.schemas.database.PageCalendar@1a116c9
>>> 12:17:36,971 DEBUG SqlGeneratorDefaultImpl:114 - SQL:INSERT INTO 
>>> pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
>>> (?,?,?,?,?)
>>> 12:17:37,092 DEBUG JdbcAccessImpl:196 - executeInsert: 
>>> com.mysql.jdbc.PreparedStatement@3fa5ac: INSERT INTO pageCalendar 
>>> (active,showFrom,showTo,contentId,templateId) VALUES 
>>> ('1','2004-12-24','2004-12-24',1,2)
>>> 12:17:37,252 DEBUG StatementManager:89 - closeResources was called
>>> 12:17:37,272 DEBUG SequenceManagerNativeImpl:231 - After store - newid=5
>>> 12:17:37,282  INFO CacheDistributor:98 - Create new 
>>> ObjectCacheImplementation for 'school'
>>> 12:17:37,302 DEBUG ConnectionManagerImpl:170 - commit was called
>>> 12:17:37,312 DEBUG PersistenceBrokerImpl:329 - PB.close was called: 
>>> org.apache.ojb.broker.core.PersistenceBrokerImpl@18825b3
>>> New page calendar id is ==> 5
>>> 12:17:37,322 DEBUG PersistenceBrokerFactoryDefaultImpl:86 - Obtain 
>>> broker from pool, used PBKey is org.apache.ojb.broker.PBKey: 
>>> jcdAlias=school, user=*****, password=*****
>>> 12:17:37,342 DEBUG PersistenceBrokerImpl:1360 - getObjectByIdentity 
>>> com.organisation.resources.schemas.database.PageCalendar{5}
>>> 12:17:37,352 DEBUG PersistenceBrokerImpl:329 - PB.close was called: 
>>> org.apache.ojb.broker.core.PersistenceBrokerImpl@18825b3
>>> Retrieved page calendar id is ==> 5
>>>
>>> junit.framework.AssertionFailedError: Must have some content
>>>     at 
>>> com.organisation.database.delegate.DelegateTest.testGetPageCalendarById(DelegateTest.java:338) 
>>>
>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>     at 
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
>>>
>>>     at 
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
>>>
>>>     at 
>>> com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)
>>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>>     at 
>>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
>>>
>>>     at 
>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
>>>
>>>     at 
>>> com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
>>>
>>>
>>> Process finished with exit code -1
>>>
>>> -----------------------------------------------------
>>>
>>> There is a bit of SQL that inserts the record, I then try to read it 
>>> back. The record comes back Ok with the getObjectByIdentity (which 
>>> doesn't seem to generate any SQL), but no objects attached, which I 
>>> try to access with a bit of test code ...
>>>
>>> -----------------------------------------------------
>>>
>>>         pageCalendar = dao.getPageCalendarById(id);
>>>
>>>         System.out.println("Retrieved page calendar id is ==> " + 
>>> pageCalendar.getId());
>>>         assertTrue("The ids should be equal", pageCalendar.getId() == 
>>> id);
>>>
>>>         Content content = pageCalendar.getContent();
>>>         Content template = pageCalendar.getTemplate();
>>>
>>>         assertNotNull("Must have some content", content);
>>>
>>>         System.out.println("Content ==> " + content.getTitle());
>>>         System.out.println("Template ==> " + template.getTitle());
>>> ---------------------------------------------------------
>>>
>>>
>>>    public PageCalendar getPageCalendarById(long id, PersistenceBroker 
>>> broker) throws OperationException {
>>>
>>>         Identity oid = 
>>> broker.serviceIdentity().buildIdentity(PageCalendar.class, new 
>>> Long(id));
>>>         PageCalendar pageCalendar = (PageCalendar) 
>>> broker.getObjectByIdentity(oid);
>>>         return pageCalendar;
>>>     }
>>>
>>>
>>> Jakob Braeuchi wrote:
>>>
>>>> hi ray,
>>>>
>>>> sorry i missed that. could you please post the generated sql.
>>>>
>>>> jakob
>>>>
>>>> Ray schrieb:
>>>>
>>>>> Thanks Jakob ...
>>>>>
>>>>> I tried addind the auto-retrieve and it had no effect (I think that 
>>>>> auto-retrieve defaults to 'true' anyway).
>>>>>
>>>>> One thing that has occurred to me, is that both references point to 
>>>>> the same table (content), so could that be causing OJB a problem?
>>>>>
>>>>>
>>>>> Jakob Braeuchi wrote:
>>>>>
>>>>>> hi ray,
>>>>>>
>>>>>> to retrieve referenced objects automatically you'll have to use 
>>>>>> auto-retrieve='true' in the reference descriptor.
>>>>>>
>>>>>> hth
>>>>>> jakob
>>>>>>
>>>>>> Ray schrieb:
>>>>>>
>>>>>>> Hi there ...
>>>>>>>
>>>>>>> I wonder if someone could help me with a little snag I've hit 
>>>>>>> with OJB.
>>>>>>>
>>>>>>> I retrieve an object using the getObjectByIdentity call, but for 
>>>>>>> some reason, I cannot get hold of the objects that it references.
>>>>>>>
>>>>>>> Here's the repository definition:
>>>>>>>
>>>>>>> ---------------------------------------
>>>>>>> <class-descriptor
>>>>>>>     class="com.organisation.resources.schemas.database.PageCalendar"
>>>>>>>     table="pageCalendar">
>>>>>>>
>>>>>>>     <field-descriptor column="id"
>>>>>>>         jdbc-type="BIGINT"
>>>>>>>         name="id"
>>>>>>>         primarykey="true"
>>>>>>>         autoincrement="true"
>>>>>>>         access="readonly"/>
>>>>>>>
>>>>>>>     <field-descriptor
>>>>>>>         name="active"
>>>>>>>         column="active"
>>>>>>>         jdbc-type="BIT"/>
>>>>>>>
>>>>>>>     <field-descriptor
>>>>>>>         name="showFrom"
>>>>>>>         column="showFrom"
>>>>>>>         jdbc-type="DATE"/>
>>>>>>>
>>>>>>>     <field-descriptor
>>>>>>>         name="showTo"
>>>>>>>         column="showTo"
>>>>>>>         jdbc-type="DATE"/>
>>>>>>>
>>>>>>>     <field-descriptor
>>>>>>>         name="contentId"
>>>>>>>         column="contentId"
>>>>>>>         jdbc-type="BIGINT"/>
>>>>>>>
>>>>>>>     <field-descriptor
>>>>>>>         name="templateId"
>>>>>>>         column="templateId"
>>>>>>>         jdbc-type="BIGINT"/>
>>>>>>>
>>>>>>>     <reference-descriptor
>>>>>>>        name="content"
>>>>>>>        
>>>>>>> class-ref="com.organisation.resources.schemas.database.Content">
>>>>>>>
>>>>>>>        <foreignkey field-ref="contentId"/>
>>>>>>>
>>>>>>>     </reference-descriptor>
>>>>>>>
>>>>>>>     <reference-descriptor
>>>>>>>        name="template"
>>>>>>>        
>>>>>>> class-ref="com.organisation.resources.schemas.database.Content">
>>>>>>>
>>>>>>>        <foreignkey field-ref="templateId"/>
>>>>>>>
>>>>>>>     </reference-descriptor>
>>>>>>>
>>>>>>> </class-descriptor>
>>>>>>> ---------------------------------------
>>>>>>>
>>>>>>> Now if I use a query to retrieve the record, then the references 
>>>>>>> to content and template work fine .... btu if I retrieve the 
>>>>>>> pageCalendar object using a primary key, and then try to call ...
>>>>>>>
>>>>>>> pageCalendar.getContent or pageCalendar.getTemplate, I get null 
>>>>>>> values returned.
>>>>>>>
>>>>>>> I've checked the databases (MySQL), and the records are all saved 
>>>>>>> correctly, and the references have been set up; so I'm at a bit 
>>>>>>> of a loss as to why this doesn't work.
>>>>>>>
>>>>>>> Any pointers would be very much appreciated ...
>>>>>>>
>>>>>>>
>>>>>>> ... and if you celebrate it, Merry Christmas! .... :-D
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> --------------------------------------------------------------------- 
>>>>>>>
>>>>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>>>
>>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 

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


Re: Referenced object not being picked up ...

Posted by Ray <ra...@yahoo.co.uk>.
Hi Jakob.

Got p6spy running, but the result was pretty much the same; all I got 
was this:

----------------------------------------------------
1104080183441|0|0|statement|INSERT INTO pageCalendar 
(active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) |INSERT 
INTO pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
('true','Sun Dec 26 16:56:14 GMT 2004','Sun Dec 26 16:56:14 GMT 
2004','1','2')
1104080183472|10|0|statement||SELECT LAST_INSERT_ID() FROM pageCalendar 
LIMIT 1
1104080183502|0|0|commit||
1104080851692|60|0|statement|INSERT INTO pageCalendar 
(active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) |INSERT 
INTO pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
('true','Sun Dec 26 17:07:19 GMT 2004','Sun Dec 26 17:07:19 GMT 
2004','1','2')
1104080851742|20|0|statement||SELECT LAST_INSERT_ID() FROM pageCalendar 
LIMIT 1
1104080851783|0|0|commit||
1104080993226|0|0|statement|INSERT INTO pageCalendar 
(active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) |INSERT 
INTO pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
('true','Sun Dec 26 17:09:44 GMT 2004','Sun Dec 26 17:09:44 GMT 
2004','1','2')
1104080993256|20|0|statement||SELECT LAST_INSERT_ID() FROM pageCalendar 
LIMIT 1
1104080993296|0|0|commit||
1104081197389|0|0|statement|INSERT INTO pageCalendar 
(active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) |INSERT 
INTO pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
('true','Sun Dec 26 17:13:08 GMT 2004','Sun Dec 26 17:13:08 GMT 
2004','1','2')
1104081197440|20|0|statement||SELECT LAST_INSERT_ID() FROM pageCalendar 
LIMIT 1
1104081197480|0|0|commit||
1104084153861|231|0|statement|INSERT INTO pageCalendar 
(active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) |INSERT 
INTO pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
('true','Sun Dec 26 18:02:22 GMT 2004','Sun Dec 26 18:02:22 GMT 
2004','1','2')
1104084153921|20|0|statement||SELECT LAST_INSERT_ID() FROM pageCalendar 
LIMIT 1
1104084154021|10|0|rollback||
1104084379075|0|0|statement|INSERT INTO pageCalendar 
(active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) |INSERT 
INTO pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
('true','Sun Dec 26 18:06:10 GMT 2004','Sun Dec 26 18:06:10 GMT 
2004','1','2')
1104084379135|20|0|statement||SELECT LAST_INSERT_ID() FROM pageCalendar 
LIMIT 1
1104084379175|0|0|commit||
1104086278976|150|0|statement|INSERT INTO pageCalendar 
(active,showFrom,showTo,contentId,templateId) VALUES (?,?,?,?,?) |INSERT 
INTO pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
('true','Sun Dec 26 18:37:49 GMT 2004','Sun Dec 26 18:37:49 GMT 
2004','1','2')
1104086279057|20|0|statement||SELECT LAST_INSERT_ID() FROM pageCalendar 
LIMIT 1
1104086279097|0|0|commit||
----------------------------------------------------------

Seems that the getObjectIdentity doesn't generate any SQL code that 
shows up.

As far as I can tell, what I've done seems fine, except that I 
referencing the same table twice; my only guess is that that is causing 
OJB a problem (other references work OK).



Jakob Braeuchi wrote:
> hi ray,
> 
> i'd better use p6spy to log the sql.
> 
> replace the mysql-driver in database.xml with the p6spy-driver:
> ...
> driver="org.hsqldb.jdbcDriver"
> ...
> 
> in spy.properties you'll have to tell p6spy the real-driver:
> ...
> # mysql Connector/J driver
> realdriver=com.mysql.jdbc.Driver
> ...
> 
> 
> jakob
> 
> Ray schrieb:
> 
>> Yep. Okay.
>>
>> --------------------------------------
>> 12:17:32,875 DEBUG ConnectionFactoryPooledImpl:96 - createPool was called
>> 12:17:32,946 DEBUG ConnectionFactoryPooledImpl:230 - makeObject called
>> 12:17:36,390 DEBUG ConnectionFactoryAbstractImpl:273 - Create new 
>> connection using DriverManager: com.mysql.jdbc.Connection@79e304
>> 12:17:36,441 DEBUG ConnectionManagerImpl:118 - Request new connection 
>> from ConnectionFactory: com.mysql.jdbc.Connection@79e304
>> 12:17:36,471 DEBUG ConnectionManagerImpl:156 - localBegin was called 
>> for con com.mysql.jdbc.Connection@79e304
>> 12:17:36,481 DEBUG ConnectionManagerImpl:159 - Try to change 
>> autoCommit state to 'false'
>> 12:17:36,631  INFO PersistenceBrokerImpl:777 - Cascade store for this 
>> reference-descriptor (content) was set to false.
>> 12:17:36,641  INFO PersistenceBrokerImpl:777 - Cascade store for this 
>> reference-descriptor (template) was set to false.
>> 12:17:36,941 DEBUG JdbcAccessImpl:182 - executeInsert : 
>> com.organisation.resources.schemas.database.PageCalendar@1a116c9
>> 12:17:36,971 DEBUG SqlGeneratorDefaultImpl:114 - SQL:INSERT INTO 
>> pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
>> (?,?,?,?,?)
>> 12:17:37,092 DEBUG JdbcAccessImpl:196 - executeInsert: 
>> com.mysql.jdbc.PreparedStatement@3fa5ac: INSERT INTO pageCalendar 
>> (active,showFrom,showTo,contentId,templateId) VALUES 
>> ('1','2004-12-24','2004-12-24',1,2)
>> 12:17:37,252 DEBUG StatementManager:89 - closeResources was called
>> 12:17:37,272 DEBUG SequenceManagerNativeImpl:231 - After store - newid=5
>> 12:17:37,282  INFO CacheDistributor:98 - Create new 
>> ObjectCacheImplementation for 'school'
>> 12:17:37,302 DEBUG ConnectionManagerImpl:170 - commit was called
>> 12:17:37,312 DEBUG PersistenceBrokerImpl:329 - PB.close was called: 
>> org.apache.ojb.broker.core.PersistenceBrokerImpl@18825b3
>> New page calendar id is ==> 5
>> 12:17:37,322 DEBUG PersistenceBrokerFactoryDefaultImpl:86 - Obtain 
>> broker from pool, used PBKey is org.apache.ojb.broker.PBKey: 
>> jcdAlias=school, user=*****, password=*****
>> 12:17:37,342 DEBUG PersistenceBrokerImpl:1360 - getObjectByIdentity 
>> com.organisation.resources.schemas.database.PageCalendar{5}
>> 12:17:37,352 DEBUG PersistenceBrokerImpl:329 - PB.close was called: 
>> org.apache.ojb.broker.core.PersistenceBrokerImpl@18825b3
>> Retrieved page calendar id is ==> 5
>>
>> junit.framework.AssertionFailedError: Must have some content
>>     at 
>> com.organisation.database.delegate.DelegateTest.testGetPageCalendarById(DelegateTest.java:338) 
>>
>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>     at 
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
>>
>>     at 
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
>>
>>     at 
>> com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)
>>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>     at 
>> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
>>
>>     at 
>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
>>
>>     at 
>> com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
>>
>>
>> Process finished with exit code -1
>>
>> -----------------------------------------------------
>>
>> There is a bit of SQL that inserts the record, I then try to read it 
>> back. The record comes back Ok with the getObjectByIdentity (which 
>> doesn't seem to generate any SQL), but no objects attached, which I 
>> try to access with a bit of test code ...
>>
>> -----------------------------------------------------
>>
>>         pageCalendar = dao.getPageCalendarById(id);
>>
>>         System.out.println("Retrieved page calendar id is ==> " + 
>> pageCalendar.getId());
>>         assertTrue("The ids should be equal", pageCalendar.getId() == 
>> id);
>>
>>         Content content = pageCalendar.getContent();
>>         Content template = pageCalendar.getTemplate();
>>
>>         assertNotNull("Must have some content", content);
>>
>>         System.out.println("Content ==> " + content.getTitle());
>>         System.out.println("Template ==> " + template.getTitle());
>> ---------------------------------------------------------
>>
>>
>>    public PageCalendar getPageCalendarById(long id, PersistenceBroker 
>> broker) throws OperationException {
>>
>>         Identity oid = 
>> broker.serviceIdentity().buildIdentity(PageCalendar.class, new Long(id));
>>         PageCalendar pageCalendar = (PageCalendar) 
>> broker.getObjectByIdentity(oid);
>>         return pageCalendar;
>>     }
>>
>>
>> Jakob Braeuchi wrote:
>>
>>> hi ray,
>>>
>>> sorry i missed that. could you please post the generated sql.
>>>
>>> jakob
>>>
>>> Ray schrieb:
>>>
>>>> Thanks Jakob ...
>>>>
>>>> I tried addind the auto-retrieve and it had no effect (I think that 
>>>> auto-retrieve defaults to 'true' anyway).
>>>>
>>>> One thing that has occurred to me, is that both references point to 
>>>> the same table (content), so could that be causing OJB a problem?
>>>>
>>>>
>>>> Jakob Braeuchi wrote:
>>>>
>>>>> hi ray,
>>>>>
>>>>> to retrieve referenced objects automatically you'll have to use 
>>>>> auto-retrieve='true' in the reference descriptor.
>>>>>
>>>>> hth
>>>>> jakob
>>>>>
>>>>> Ray schrieb:
>>>>>
>>>>>> Hi there ...
>>>>>>
>>>>>> I wonder if someone could help me with a little snag I've hit with 
>>>>>> OJB.
>>>>>>
>>>>>> I retrieve an object using the getObjectByIdentity call, but for 
>>>>>> some reason, I cannot get hold of the objects that it references.
>>>>>>
>>>>>> Here's the repository definition:
>>>>>>
>>>>>> ---------------------------------------
>>>>>> <class-descriptor
>>>>>>     class="com.organisation.resources.schemas.database.PageCalendar"
>>>>>>     table="pageCalendar">
>>>>>>
>>>>>>     <field-descriptor column="id"
>>>>>>         jdbc-type="BIGINT"
>>>>>>         name="id"
>>>>>>         primarykey="true"
>>>>>>         autoincrement="true"
>>>>>>         access="readonly"/>
>>>>>>
>>>>>>     <field-descriptor
>>>>>>         name="active"
>>>>>>         column="active"
>>>>>>         jdbc-type="BIT"/>
>>>>>>
>>>>>>     <field-descriptor
>>>>>>         name="showFrom"
>>>>>>         column="showFrom"
>>>>>>         jdbc-type="DATE"/>
>>>>>>
>>>>>>     <field-descriptor
>>>>>>         name="showTo"
>>>>>>         column="showTo"
>>>>>>         jdbc-type="DATE"/>
>>>>>>
>>>>>>     <field-descriptor
>>>>>>         name="contentId"
>>>>>>         column="contentId"
>>>>>>         jdbc-type="BIGINT"/>
>>>>>>
>>>>>>     <field-descriptor
>>>>>>         name="templateId"
>>>>>>         column="templateId"
>>>>>>         jdbc-type="BIGINT"/>
>>>>>>
>>>>>>     <reference-descriptor
>>>>>>        name="content"
>>>>>>        
>>>>>> class-ref="com.organisation.resources.schemas.database.Content">
>>>>>>
>>>>>>        <foreignkey field-ref="contentId"/>
>>>>>>
>>>>>>     </reference-descriptor>
>>>>>>
>>>>>>     <reference-descriptor
>>>>>>        name="template"
>>>>>>        
>>>>>> class-ref="com.organisation.resources.schemas.database.Content">
>>>>>>
>>>>>>        <foreignkey field-ref="templateId"/>
>>>>>>
>>>>>>     </reference-descriptor>
>>>>>>
>>>>>> </class-descriptor>
>>>>>> ---------------------------------------
>>>>>>
>>>>>> Now if I use a query to retrieve the record, then the references 
>>>>>> to content and template work fine .... btu if I retrieve the 
>>>>>> pageCalendar object using a primary key, and then try to call ...
>>>>>>
>>>>>> pageCalendar.getContent or pageCalendar.getTemplate, I get null 
>>>>>> values returned.
>>>>>>
>>>>>> I've checked the databases (MySQL), and the records are all saved 
>>>>>> correctly, and the references have been set up; so I'm at a bit of 
>>>>>> a loss as to why this doesn't work.
>>>>>>
>>>>>> Any pointers would be very much appreciated ...
>>>>>>
>>>>>>
>>>>>> ... and if you celebrate it, Merry Christmas! .... :-D
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> ---------------------------------------------------------------------
>>>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>>
>>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 


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


Re: Referenced object not being picked up ...

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi ray,

i'd better use p6spy to log the sql.

replace the mysql-driver in database.xml with the p6spy-driver:
...
driver="org.hsqldb.jdbcDriver"
...

in spy.properties you'll have to tell p6spy the real-driver:
...
# mysql Connector/J driver
realdriver=com.mysql.jdbc.Driver
...


jakob

Ray schrieb:
> Yep. Okay.
> 
> --------------------------------------
> 12:17:32,875 DEBUG ConnectionFactoryPooledImpl:96 - createPool was called
> 12:17:32,946 DEBUG ConnectionFactoryPooledImpl:230 - makeObject called
> 12:17:36,390 DEBUG ConnectionFactoryAbstractImpl:273 - Create new 
> connection using DriverManager: com.mysql.jdbc.Connection@79e304
> 12:17:36,441 DEBUG ConnectionManagerImpl:118 - Request new connection 
> from ConnectionFactory: com.mysql.jdbc.Connection@79e304
> 12:17:36,471 DEBUG ConnectionManagerImpl:156 - localBegin was called for 
> con com.mysql.jdbc.Connection@79e304
> 12:17:36,481 DEBUG ConnectionManagerImpl:159 - Try to change autoCommit 
> state to 'false'
> 12:17:36,631  INFO PersistenceBrokerImpl:777 - Cascade store for this 
> reference-descriptor (content) was set to false.
> 12:17:36,641  INFO PersistenceBrokerImpl:777 - Cascade store for this 
> reference-descriptor (template) was set to false.
> 12:17:36,941 DEBUG JdbcAccessImpl:182 - executeInsert : 
> com.organisation.resources.schemas.database.PageCalendar@1a116c9
> 12:17:36,971 DEBUG SqlGeneratorDefaultImpl:114 - SQL:INSERT INTO 
> pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
> (?,?,?,?,?)
> 12:17:37,092 DEBUG JdbcAccessImpl:196 - executeInsert: 
> com.mysql.jdbc.PreparedStatement@3fa5ac: INSERT INTO pageCalendar 
> (active,showFrom,showTo,contentId,templateId) VALUES 
> ('1','2004-12-24','2004-12-24',1,2)
> 12:17:37,252 DEBUG StatementManager:89 - closeResources was called
> 12:17:37,272 DEBUG SequenceManagerNativeImpl:231 - After store - newid=5
> 12:17:37,282  INFO CacheDistributor:98 - Create new 
> ObjectCacheImplementation for 'school'
> 12:17:37,302 DEBUG ConnectionManagerImpl:170 - commit was called
> 12:17:37,312 DEBUG PersistenceBrokerImpl:329 - PB.close was called: 
> org.apache.ojb.broker.core.PersistenceBrokerImpl@18825b3
> New page calendar id is ==> 5
> 12:17:37,322 DEBUG PersistenceBrokerFactoryDefaultImpl:86 - Obtain 
> broker from pool, used PBKey is org.apache.ojb.broker.PBKey: 
> jcdAlias=school, user=*****, password=*****
> 12:17:37,342 DEBUG PersistenceBrokerImpl:1360 - getObjectByIdentity 
> com.organisation.resources.schemas.database.PageCalendar{5}
> 12:17:37,352 DEBUG PersistenceBrokerImpl:329 - PB.close was called: 
> org.apache.ojb.broker.core.PersistenceBrokerImpl@18825b3
> Retrieved page calendar id is ==> 5
> 
> junit.framework.AssertionFailedError: Must have some content
>     at 
> com.organisation.database.delegate.DelegateTest.testGetPageCalendarById(DelegateTest.java:338) 
> 
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
> 
>     at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
> 
>     at 
> com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)
>     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>     at 
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
> 
>     at 
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
> 
>     at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
> 
> 
> Process finished with exit code -1
> 
> -----------------------------------------------------
> 
> There is a bit of SQL that inserts the record, I then try to read it 
> back. The record comes back Ok with the getObjectByIdentity (which 
> doesn't seem to generate any SQL), but no objects attached, which I try 
> to access with a bit of test code ...
> 
> -----------------------------------------------------
> 
>         pageCalendar = dao.getPageCalendarById(id);
> 
>         System.out.println("Retrieved page calendar id is ==> " + 
> pageCalendar.getId());
>         assertTrue("The ids should be equal", pageCalendar.getId() == id);
> 
>         Content content = pageCalendar.getContent();
>         Content template = pageCalendar.getTemplate();
> 
>         assertNotNull("Must have some content", content);
> 
>         System.out.println("Content ==> " + content.getTitle());
>         System.out.println("Template ==> " + template.getTitle());
> ---------------------------------------------------------
> 
> 
>    public PageCalendar getPageCalendarById(long id, PersistenceBroker 
> broker) throws OperationException {
> 
>         Identity oid = 
> broker.serviceIdentity().buildIdentity(PageCalendar.class, new Long(id));
>         PageCalendar pageCalendar = (PageCalendar) 
> broker.getObjectByIdentity(oid);
>         return pageCalendar;
>     }
> 
> 
> Jakob Braeuchi wrote:
> 
>> hi ray,
>>
>> sorry i missed that. could you please post the generated sql.
>>
>> jakob
>>
>> Ray schrieb:
>>
>>> Thanks Jakob ...
>>>
>>> I tried addind the auto-retrieve and it had no effect (I think that 
>>> auto-retrieve defaults to 'true' anyway).
>>>
>>> One thing that has occurred to me, is that both references point to 
>>> the same table (content), so could that be causing OJB a problem?
>>>
>>>
>>> Jakob Braeuchi wrote:
>>>
>>>> hi ray,
>>>>
>>>> to retrieve referenced objects automatically you'll have to use 
>>>> auto-retrieve='true' in the reference descriptor.
>>>>
>>>> hth
>>>> jakob
>>>>
>>>> Ray schrieb:
>>>>
>>>>> Hi there ...
>>>>>
>>>>> I wonder if someone could help me with a little snag I've hit with 
>>>>> OJB.
>>>>>
>>>>> I retrieve an object using the getObjectByIdentity call, but for 
>>>>> some reason, I cannot get hold of the objects that it references.
>>>>>
>>>>> Here's the repository definition:
>>>>>
>>>>> ---------------------------------------
>>>>> <class-descriptor
>>>>>     class="com.organisation.resources.schemas.database.PageCalendar"
>>>>>     table="pageCalendar">
>>>>>
>>>>>     <field-descriptor column="id"
>>>>>         jdbc-type="BIGINT"
>>>>>         name="id"
>>>>>         primarykey="true"
>>>>>         autoincrement="true"
>>>>>         access="readonly"/>
>>>>>
>>>>>     <field-descriptor
>>>>>         name="active"
>>>>>         column="active"
>>>>>         jdbc-type="BIT"/>
>>>>>
>>>>>     <field-descriptor
>>>>>         name="showFrom"
>>>>>         column="showFrom"
>>>>>         jdbc-type="DATE"/>
>>>>>
>>>>>     <field-descriptor
>>>>>         name="showTo"
>>>>>         column="showTo"
>>>>>         jdbc-type="DATE"/>
>>>>>
>>>>>     <field-descriptor
>>>>>         name="contentId"
>>>>>         column="contentId"
>>>>>         jdbc-type="BIGINT"/>
>>>>>
>>>>>     <field-descriptor
>>>>>         name="templateId"
>>>>>         column="templateId"
>>>>>         jdbc-type="BIGINT"/>
>>>>>
>>>>>     <reference-descriptor
>>>>>        name="content"
>>>>>        
>>>>> class-ref="com.organisation.resources.schemas.database.Content">
>>>>>
>>>>>        <foreignkey field-ref="contentId"/>
>>>>>
>>>>>     </reference-descriptor>
>>>>>
>>>>>     <reference-descriptor
>>>>>        name="template"
>>>>>        
>>>>> class-ref="com.organisation.resources.schemas.database.Content">
>>>>>
>>>>>        <foreignkey field-ref="templateId"/>
>>>>>
>>>>>     </reference-descriptor>
>>>>>
>>>>> </class-descriptor>
>>>>> ---------------------------------------
>>>>>
>>>>> Now if I use a query to retrieve the record, then the references to 
>>>>> content and template work fine .... btu if I retrieve the 
>>>>> pageCalendar object using a primary key, and then try to call ...
>>>>>
>>>>> pageCalendar.getContent or pageCalendar.getTemplate, I get null 
>>>>> values returned.
>>>>>
>>>>> I've checked the databases (MySQL), and the records are all saved 
>>>>> correctly, and the references have been set up; so I'm at a bit of 
>>>>> a loss as to why this doesn't work.
>>>>>
>>>>> Any pointers would be very much appreciated ...
>>>>>
>>>>>
>>>>> ... and if you celebrate it, Merry Christmas! .... :-D
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>>
>>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 

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


Re: Referenced object not being picked up ...

Posted by Ray <ra...@yahoo.co.uk>.
Yep. Okay.

--------------------------------------
12:17:32,875 DEBUG ConnectionFactoryPooledImpl:96 - createPool was called
12:17:32,946 DEBUG ConnectionFactoryPooledImpl:230 - makeObject called
12:17:36,390 DEBUG ConnectionFactoryAbstractImpl:273 - Create new 
connection using DriverManager: com.mysql.jdbc.Connection@79e304
12:17:36,441 DEBUG ConnectionManagerImpl:118 - Request new connection 
from ConnectionFactory: com.mysql.jdbc.Connection@79e304
12:17:36,471 DEBUG ConnectionManagerImpl:156 - localBegin was called for 
con com.mysql.jdbc.Connection@79e304
12:17:36,481 DEBUG ConnectionManagerImpl:159 - Try to change autoCommit 
state to 'false'
12:17:36,631  INFO PersistenceBrokerImpl:777 - Cascade store for this 
reference-descriptor (content) was set to false.
12:17:36,641  INFO PersistenceBrokerImpl:777 - Cascade store for this 
reference-descriptor (template) was set to false.
12:17:36,941 DEBUG JdbcAccessImpl:182 - executeInsert : 
com.organisation.resources.schemas.database.PageCalendar@1a116c9
12:17:36,971 DEBUG SqlGeneratorDefaultImpl:114 - SQL:INSERT INTO 
pageCalendar (active,showFrom,showTo,contentId,templateId) VALUES 
(?,?,?,?,?)
12:17:37,092 DEBUG JdbcAccessImpl:196 - executeInsert: 
com.mysql.jdbc.PreparedStatement@3fa5ac: INSERT INTO pageCalendar 
(active,showFrom,showTo,contentId,templateId) VALUES 
('1','2004-12-24','2004-12-24',1,2)
12:17:37,252 DEBUG StatementManager:89 - closeResources was called
12:17:37,272 DEBUG SequenceManagerNativeImpl:231 - After store - newid=5
12:17:37,282  INFO CacheDistributor:98 - Create new 
ObjectCacheImplementation for 'school'
12:17:37,302 DEBUG ConnectionManagerImpl:170 - commit was called
12:17:37,312 DEBUG PersistenceBrokerImpl:329 - PB.close was called: 
org.apache.ojb.broker.core.PersistenceBrokerImpl@18825b3
New page calendar id is ==> 5
12:17:37,322 DEBUG PersistenceBrokerFactoryDefaultImpl:86 - Obtain 
broker from pool, used PBKey is org.apache.ojb.broker.PBKey: 
jcdAlias=school, user=*****, password=*****
12:17:37,342 DEBUG PersistenceBrokerImpl:1360 - getObjectByIdentity 
com.organisation.resources.schemas.database.PageCalendar{5}
12:17:37,352 DEBUG PersistenceBrokerImpl:329 - PB.close was called: 
org.apache.ojb.broker.core.PersistenceBrokerImpl@18825b3
Retrieved page calendar id is ==> 5

junit.framework.AssertionFailedError: Must have some content
	at 
com.organisation.database.delegate.DelegateTest.testGetPageCalendarById(DelegateTest.java:338)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at com.intellij.rt.execution.junit2.JUnitStarter.main(JUnitStarter.java:31)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at 
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
	at 
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
	at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)


Process finished with exit code -1

-----------------------------------------------------

There is a bit of SQL that inserts the record, I then try to read it 
back. The record comes back Ok with the getObjectByIdentity (which 
doesn't seem to generate any SQL), but no objects attached, which I try 
to access with a bit of test code ...

-----------------------------------------------------

         pageCalendar = dao.getPageCalendarById(id);

         System.out.println("Retrieved page calendar id is ==> " + 
pageCalendar.getId());
         assertTrue("The ids should be equal", pageCalendar.getId() == id);

         Content content = pageCalendar.getContent();
         Content template = pageCalendar.getTemplate();

         assertNotNull("Must have some content", content);

         System.out.println("Content ==> " + content.getTitle());
         System.out.println("Template ==> " + template.getTitle());
---------------------------------------------------------


    public PageCalendar getPageCalendarById(long id, PersistenceBroker 
broker) throws OperationException {

         Identity oid = 
broker.serviceIdentity().buildIdentity(PageCalendar.class, new Long(id));
         PageCalendar pageCalendar = (PageCalendar) 
broker.getObjectByIdentity(oid);
         return pageCalendar;
     }


Jakob Braeuchi wrote:
> hi ray,
> 
> sorry i missed that. could you please post the generated sql.
> 
> jakob
> 
> Ray schrieb:
> 
>> Thanks Jakob ...
>>
>> I tried addind the auto-retrieve and it had no effect (I think that 
>> auto-retrieve defaults to 'true' anyway).
>>
>> One thing that has occurred to me, is that both references point to 
>> the same table (content), so could that be causing OJB a problem?
>>
>>
>> Jakob Braeuchi wrote:
>>
>>> hi ray,
>>>
>>> to retrieve referenced objects automatically you'll have to use 
>>> auto-retrieve='true' in the reference descriptor.
>>>
>>> hth
>>> jakob
>>>
>>> Ray schrieb:
>>>
>>>> Hi there ...
>>>>
>>>> I wonder if someone could help me with a little snag I've hit with OJB.
>>>>
>>>> I retrieve an object using the getObjectByIdentity call, but for 
>>>> some reason, I cannot get hold of the objects that it references.
>>>>
>>>> Here's the repository definition:
>>>>
>>>> ---------------------------------------
>>>> <class-descriptor
>>>>     class="com.organisation.resources.schemas.database.PageCalendar"
>>>>     table="pageCalendar">
>>>>
>>>>     <field-descriptor column="id"
>>>>         jdbc-type="BIGINT"
>>>>         name="id"
>>>>         primarykey="true"
>>>>         autoincrement="true"
>>>>         access="readonly"/>
>>>>
>>>>     <field-descriptor
>>>>         name="active"
>>>>         column="active"
>>>>         jdbc-type="BIT"/>
>>>>
>>>>     <field-descriptor
>>>>         name="showFrom"
>>>>         column="showFrom"
>>>>         jdbc-type="DATE"/>
>>>>
>>>>     <field-descriptor
>>>>         name="showTo"
>>>>         column="showTo"
>>>>         jdbc-type="DATE"/>
>>>>
>>>>     <field-descriptor
>>>>         name="contentId"
>>>>         column="contentId"
>>>>         jdbc-type="BIGINT"/>
>>>>
>>>>     <field-descriptor
>>>>         name="templateId"
>>>>         column="templateId"
>>>>         jdbc-type="BIGINT"/>
>>>>
>>>>     <reference-descriptor
>>>>        name="content"
>>>>        class-ref="com.organisation.resources.schemas.database.Content">
>>>>
>>>>        <foreignkey field-ref="contentId"/>
>>>>
>>>>     </reference-descriptor>
>>>>
>>>>     <reference-descriptor
>>>>        name="template"
>>>>        class-ref="com.organisation.resources.schemas.database.Content">
>>>>
>>>>        <foreignkey field-ref="templateId"/>
>>>>
>>>>     </reference-descriptor>
>>>>
>>>> </class-descriptor>
>>>> ---------------------------------------
>>>>
>>>> Now if I use a query to retrieve the record, then the references to 
>>>> content and template work fine .... btu if I retrieve the 
>>>> pageCalendar object using a primary key, and then try to call ...
>>>>
>>>> pageCalendar.getContent or pageCalendar.getTemplate, I get null 
>>>> values returned.
>>>>
>>>> I've checked the databases (MySQL), and the records are all saved 
>>>> correctly, and the references have been set up; so I'm at a bit of a 
>>>> loss as to why this doesn't work.
>>>>
>>>> Any pointers would be very much appreciated ...
>>>>
>>>>
>>>> ... and if you celebrate it, Merry Christmas! .... :-D
>>>>
>>>>
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>>
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 


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


Re: Referenced object not being picked up ...

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi ray,

sorry i missed that. could you please post the generated sql.

jakob

Ray schrieb:
> Thanks Jakob ...
> 
> I tried addind the auto-retrieve and it had no effect (I think that 
> auto-retrieve defaults to 'true' anyway).
> 
> One thing that has occurred to me, is that both references point to the 
> same table (content), so could that be causing OJB a problem?
> 
> 
> Jakob Braeuchi wrote:
> 
>> hi ray,
>>
>> to retrieve referenced objects automatically you'll have to use 
>> auto-retrieve='true' in the reference descriptor.
>>
>> hth
>> jakob
>>
>> Ray schrieb:
>>
>>> Hi there ...
>>>
>>> I wonder if someone could help me with a little snag I've hit with OJB.
>>>
>>> I retrieve an object using the getObjectByIdentity call, but for some 
>>> reason, I cannot get hold of the objects that it references.
>>>
>>> Here's the repository definition:
>>>
>>> ---------------------------------------
>>> <class-descriptor
>>>     class="com.organisation.resources.schemas.database.PageCalendar"
>>>     table="pageCalendar">
>>>
>>>     <field-descriptor column="id"
>>>         jdbc-type="BIGINT"
>>>         name="id"
>>>         primarykey="true"
>>>         autoincrement="true"
>>>         access="readonly"/>
>>>
>>>     <field-descriptor
>>>         name="active"
>>>         column="active"
>>>         jdbc-type="BIT"/>
>>>
>>>     <field-descriptor
>>>         name="showFrom"
>>>         column="showFrom"
>>>         jdbc-type="DATE"/>
>>>
>>>     <field-descriptor
>>>         name="showTo"
>>>         column="showTo"
>>>         jdbc-type="DATE"/>
>>>
>>>     <field-descriptor
>>>         name="contentId"
>>>         column="contentId"
>>>         jdbc-type="BIGINT"/>
>>>
>>>     <field-descriptor
>>>         name="templateId"
>>>         column="templateId"
>>>         jdbc-type="BIGINT"/>
>>>
>>>     <reference-descriptor
>>>        name="content"
>>>        class-ref="com.organisation.resources.schemas.database.Content">
>>>
>>>        <foreignkey field-ref="contentId"/>
>>>
>>>     </reference-descriptor>
>>>
>>>     <reference-descriptor
>>>        name="template"
>>>        class-ref="com.organisation.resources.schemas.database.Content">
>>>
>>>        <foreignkey field-ref="templateId"/>
>>>
>>>     </reference-descriptor>
>>>
>>> </class-descriptor>
>>> ---------------------------------------
>>>
>>> Now if I use a query to retrieve the record, then the references to 
>>> content and template work fine .... btu if I retrieve the 
>>> pageCalendar object using a primary key, and then try to call ...
>>>
>>> pageCalendar.getContent or pageCalendar.getTemplate, I get null 
>>> values returned.
>>>
>>> I've checked the databases (MySQL), and the records are all saved 
>>> correctly, and the references have been set up; so I'm at a bit of a 
>>> loss as to why this doesn't work.
>>>
>>> Any pointers would be very much appreciated ...
>>>
>>>
>>> ... and if you celebrate it, Merry Christmas! .... :-D
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
>>
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 

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


Re: Referenced object not being picked up ...

Posted by Ray <ra...@yahoo.co.uk>.
Thanks Jakob ...

I tried addind the auto-retrieve and it had no effect (I think that 
auto-retrieve defaults to 'true' anyway).

One thing that has occurred to me, is that both references point to the 
same table (content), so could that be causing OJB a problem?


Jakob Braeuchi wrote:
> hi ray,
> 
> to retrieve referenced objects automatically you'll have to use 
> auto-retrieve='true' in the reference descriptor.
> 
> hth
> jakob
> 
> Ray schrieb:
> 
>> Hi there ...
>>
>> I wonder if someone could help me with a little snag I've hit with OJB.
>>
>> I retrieve an object using the getObjectByIdentity call, but for some 
>> reason, I cannot get hold of the objects that it references.
>>
>> Here's the repository definition:
>>
>> ---------------------------------------
>> <class-descriptor
>>     class="com.organisation.resources.schemas.database.PageCalendar"
>>     table="pageCalendar">
>>
>>     <field-descriptor column="id"
>>         jdbc-type="BIGINT"
>>         name="id"
>>         primarykey="true"
>>         autoincrement="true"
>>         access="readonly"/>
>>
>>     <field-descriptor
>>         name="active"
>>         column="active"
>>         jdbc-type="BIT"/>
>>
>>     <field-descriptor
>>         name="showFrom"
>>         column="showFrom"
>>         jdbc-type="DATE"/>
>>
>>     <field-descriptor
>>         name="showTo"
>>         column="showTo"
>>         jdbc-type="DATE"/>
>>
>>     <field-descriptor
>>         name="contentId"
>>         column="contentId"
>>         jdbc-type="BIGINT"/>
>>
>>     <field-descriptor
>>         name="templateId"
>>         column="templateId"
>>         jdbc-type="BIGINT"/>
>>
>>     <reference-descriptor
>>        name="content"
>>        class-ref="com.organisation.resources.schemas.database.Content">
>>
>>        <foreignkey field-ref="contentId"/>
>>
>>     </reference-descriptor>
>>
>>     <reference-descriptor
>>        name="template"
>>        class-ref="com.organisation.resources.schemas.database.Content">
>>
>>        <foreignkey field-ref="templateId"/>
>>
>>     </reference-descriptor>
>>
>> </class-descriptor>
>> ---------------------------------------
>>
>> Now if I use a query to retrieve the record, then the references to 
>> content and template work fine .... btu if I retrieve the pageCalendar 
>> object using a primary key, and then try to call ...
>>
>> pageCalendar.getContent or pageCalendar.getTemplate, I get null values 
>> returned.
>>
>> I've checked the databases (MySQL), and the records are all saved 
>> correctly, and the references have been set up; so I'm at a bit of a 
>> loss as to why this doesn't work.
>>
>> Any pointers would be very much appreciated ...
>>
>>
>> ... and if you celebrate it, Merry Christmas! .... :-D
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
>> For additional commands, e-mail: ojb-user-help@db.apache.org
>>
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 
> 


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


Re: Referenced object not being picked up ...

Posted by Jakob Braeuchi <jb...@gmx.ch>.
hi ray,

to retrieve referenced objects automatically you'll have to use 
auto-retrieve='true' in the reference descriptor.

hth
jakob

Ray schrieb:
> Hi there ...
> 
> I wonder if someone could help me with a little snag I've hit with OJB.
> 
> I retrieve an object using the getObjectByIdentity call, but for some 
> reason, I cannot get hold of the objects that it references.
> 
> Here's the repository definition:
> 
> ---------------------------------------
> <class-descriptor
>     class="com.organisation.resources.schemas.database.PageCalendar"
>     table="pageCalendar">
> 
>     <field-descriptor column="id"
>         jdbc-type="BIGINT"
>         name="id"
>         primarykey="true"
>         autoincrement="true"
>         access="readonly"/>
> 
>     <field-descriptor
>         name="active"
>         column="active"
>         jdbc-type="BIT"/>
> 
>     <field-descriptor
>         name="showFrom"
>         column="showFrom"
>         jdbc-type="DATE"/>
> 
>     <field-descriptor
>         name="showTo"
>         column="showTo"
>         jdbc-type="DATE"/>
> 
>     <field-descriptor
>         name="contentId"
>         column="contentId"
>         jdbc-type="BIGINT"/>
> 
>     <field-descriptor
>         name="templateId"
>         column="templateId"
>         jdbc-type="BIGINT"/>
> 
>     <reference-descriptor
>        name="content"
>        class-ref="com.organisation.resources.schemas.database.Content">
> 
>        <foreignkey field-ref="contentId"/>
> 
>     </reference-descriptor>
> 
>     <reference-descriptor
>        name="template"
>        class-ref="com.organisation.resources.schemas.database.Content">
> 
>        <foreignkey field-ref="templateId"/>
> 
>     </reference-descriptor>
> 
> </class-descriptor>
> ---------------------------------------
> 
> Now if I use a query to retrieve the record, then the references to 
> content and template work fine .... btu if I retrieve the pageCalendar 
> object using a primary key, and then try to call ...
> 
> pageCalendar.getContent or pageCalendar.getTemplate, I get null values 
> returned.
> 
> I've checked the databases (MySQL), and the records are all saved 
> correctly, and the references have been set up; so I'm at a bit of a 
> loss as to why this doesn't work.
> 
> Any pointers would be very much appreciated ...
> 
> 
> ... and if you celebrate it, Merry Christmas! .... :-D
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
> For additional commands, e-mail: ojb-user-help@db.apache.org
> 
> 

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