i checked in a quick fix using column alias.
jakob
Jakob Braeuchi wrote:
hi terry,
i can reproduce the problem and i posted it to the developer list:
http://article.gmane.org/gmane.comp.jakarta.ojb.devel/4830
thanks for the testcase. jakob
Terry Brick wrote:
Thanks Jakob for your interest... took me a while to get back because I didn't see the response. Anyway, I've included all info necessary to reproduce the problem... a) Table Structures b) Repository c) source code d) SQL generated on my system In the case below, the 'foo' property in 'table1' objects will have values from the 'foo' property of 'table2'.
DDL ========================================================= drop table table1; #---------------------------- # Table structure for table1 #---------------------------- create table table1 ( TABLE1_ID int(10) not null default '0', TABLE2_ID int(10) not null default '0', FOO varchar(10) not null, T1_COL varchar(10) not null, primary key (TABLE1_ID)) type=MyISAM;
#----------------------------
# Records for table table1
#----------------------------
insert into table1 values (1, 1, 'T1_FOO_A', 'T1_A'), (2, 2, 'T1_FOO_B', 'T1_B');
drop table table2; #---------------------------- # Table structure for table2 #---------------------------- create table table2 ( TABLE2_ID int(10) not null default '0', FOO varchar(10) not null, T2_COL varchar(10) not null, primary key (TABLE2_ID)) type=MyISAM;
#----------------------------
# Records for table table2
#----------------------------
insert into table2 values (1, 'T2_FOO_A', 'T2_A'), (2, 'T2_FOO_B', 'T2_B');
Repository
===============================================
<class-descriptor class="com.ibeque.epique.businessobjects.Table1" table="table1">
<field-descriptor name="oid" column="TABLE1_ID" jdbc-type="BIGINT" primarykey="true"
autoincrement="true" required="true" length="5"/>
<field-descriptor name="table2_id" column="TABLE2_ID" jdbc-type="BIGINT" required="true"
length="10"/>
<field-descriptor name="foo" column="FOO" jdbc-type="VARCHAR" required="true" length="10"/>
<field-descriptor name="t1_col" column="T1_COL" jdbc-type="VARCHAR" required="true"
length="10"/>
<reference-descriptor name="table2_id_ref" class-ref="com.ibeque.epique.businessobjects.Table2"
auto-retrieve="false">
<foreignkey field-ref="table2_id"/>
</reference-descriptor>
</class-descriptor>
<class-descriptor class="com.ibeque.epique.businessobjects.Table2" table="table2">
<field-descriptor name="oid" column="TABLE2_ID" jdbc-type="BIGINT" primarykey="true"
autoincrement="true" required="true" length="5"/>
<field-descriptor name="foo" column="FOO" jdbc-type="VARCHAR" required="true" length="10"/>
<field-descriptor name="t2_col" column="T2_COL" jdbc-type="VARCHAR" required="true"
length="10"/>
</class-descriptor>
Source Code ======================================================= Criteria criteria = new Criteria(); QueryByCriteria q = QueryFactory.newQuery(Table1.class, criteria); q.addOrderBy("table2_id_ref.foo",true); results = (List) broker.getCollectionByQuery(q);
Generated SQL
=======================================
SELECT A0.T1_COL,
A0.TABLE2_ID,
A0.FOO,A0.TABLE1_ID,
A1.FOO FROM table1 A0 INNER JOIN table2 A1 ON A0.TABLE2_ID=A1.TABLE2_ID ORDER BY 5
--- Jakob Braeuchi <[EMAIL PROTECTED]> wrote:
hi terry,
please post the repository and the generated sql.
jakob
Terry Brick wrote:
I have a class descriptor (CLASS_A) with a reference to another (CLASS_B). Both CLASS_A and CLASS_B have a property called "NAME".
-If I retrieve CLASS_A objects (using PB) with no orderby, everything is fine.
-If I retrieve CLASS_A objects in the same manner, but add a "CLASS_B_REF.SOME_OTHER_PROPERTY" orderby, everything is fine.
-However, if I retrieve CLASS_A objects after adding a "CLASS_B_REF.NAME" orderby, the NAME value from CLASS_B gets populated in the NAME properties of *both* the CLASS_A and CLASS_B objects!
In other words, if I add an orderby to my criteria and that orderby is a referenced class with a property name that exists in both the parent class and referenced class, the referenced value is populated in both the parent object and referenced object (they get identical values).
So for example, in the database, it may look like this..... TABLE_A.NAME = "FOO" TABLE_B.NAME = "BAR"
But in scenario described above, I get..... CLASS_A.NAME = "BAR" CLASS_B.NAME = "BAR
One other note, in my mappings, my classes are the same name as my tables and properties same names as the columns.... in case that has anything to do with it. If necessary, I'll try to provide an exact example with real mappings, sql, etc. so someone can try to reproduce the effect. I've tried this on both RC4 and RC5. I'm using MySQL.
Any ideas? Thanks!
__________________________________ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/
--------------------------------------------------------------------- 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]
__________________________________ Do you Yahoo!? New Yahoo! Photos - easier uploading and sharing. http://photos.yahoo.com/
--------------------------------------------------------------------- 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]
