I believe you have stumbled across one of the OJB gotcha's. field-descriptor id's should be 1-based, not 0-based, since it is internally Handled as an index, rather than an ID. At least, that was how it was implemented last time I looked. It would explain the SQL you see, since "username" is the first field, and inverse-foreignkey field-id-ref is 1.
Hope that helps. /Soee -----Oprindelig meddelelse----- Fra: Anders Hermansen [mailto:[EMAIL PROTECTED]] Sendt: 20. december 2002 13:28 Til: [EMAIL PROTECTED] Emne: Wrong sql generated Hello again all, I'm still trying to get ojb to work with my database. I've come much further, but there is still some errors to be fixed. Thanks to everybody who have helped so far. First, the java code: PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker(); Query query1 = QueryFactory.newQuery(Roles.class, new Criteria()); Collection allRoles = broker.getCollectionByQuery(query1); Iterator iter1 = allRoles.iterator(); while (iter1.hasNext()) { Roles role = (Roles) iter1.next(); System.out.println("Role: " + role.getRole()); } This works as expected; the output is correct. But when I look in the postgresql debug log I see some sql that was executed that is probably wrong. postgres[1677]: [2101] DEBUG: query: SELECT A0.userna me,A0.role FROM userroles A0 WHERE A0.username = 'translateown ' One for each of the roles in the row table. This is all wrong, it should have been "WHERE A0.role = 'translateown ' Looking at the relevant code in repository.xml: <class-descriptor class="no.yoyo.pdfmaker.ojb.Roles" table="roles"> <field-descriptor id="0" name="role" column="role" jdbc-type="CHAR" primarykey="true"/> <field-descriptor id="1" name="descr" column="descr" jdbc-type="CHAR"/> <collection-descriptor name="collUserroles" element-class-ref="no.yoyo.pdfmaker.ojb.Userroles" auto-retrieve="true" auto-update="false" auto-delete="false"> <inverse-foreignkey field-id-ref="1"/> </collection-descriptor> </class-descriptor> <class-descriptor class="no.yoyo.pdfmaker.ojb.Userroles" table="userroles"> <field-descriptor id="0" name="username" column="username" jdbc-type="CHAR" primarykey="true"/> <field-descriptor id="1" name="role" column="role" jdbc-type="CHAR" primarykey="true"/> <reference-descriptor name="aRoles" class-ref="no.yoyo.pdfmaker.ojb.Roles" auto-retrieve="true" auto-update="false" auto-delete="false"> <foreignkey field-id-ref="1"/> </reference-descriptor> <reference-descriptor name="aUsers" class-ref="no.yoyo.pdfmaker.ojb.Users" auto-retrieve="true" auto-update="false" auto-delete="false"> <foreignkey field-id-ref="0"/> </reference-descriptor> </class-descriptor> This error probably occurs when ojb is trying to fill up the collUserroles collection. I think there is probably something I am missing, but I can't find out what. The error is not critical here, but it's a simple example. The error becomes critical when I do more advanced operations (other tables with more references). Anybody know what is wrong? Thanks, Anders -- Anders Hermansen YoYo Mobile as -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
