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: [EMAIL PROTECTED]
12:17:36,441 DEBUG ConnectionManagerImpl:118 - Request new connection from ConnectionFactory: [EMAIL PROTECTED]
12:17:36,471 DEBUG ConnectionManagerImpl:156 - localBegin was called for con [EMAIL PROTECTED]
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 : [EMAIL PROTECTED]
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: [EMAIL PROTECTED]: 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: [EMAIL PROTECTED]
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: [EMAIL PROTECTED]
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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--------------------------------------------------------------------- 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]
--------------------------------------------------------------------- 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]
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
