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 Renaud Lévy <re...@laposte.net> on 2006/01/11 17:15:22 UTC
Collection problem 1:n relationship
Hello,
I've got a simple problem of collection's retrieve :
There are 2 tables : InfoData and ValueData with foreign key and
datetime field
as it's describe in my repository
<class-descriptor class="InfoData" table="INFO_DATA">
<field-descriptor name="id" column="ID" jdbc-type="INTEGER"
primarykey="true"/>
<field-descriptor name="name" column="NAME" jdbc-type="VARCHAR"/>
<collection-descriptor
name="listeValueData"
element-class-ref="ValueData"
auto-retrieve="true" auto-update="false" auto-delete="false">
<inverse-foreignkey field-ref="id"/>
</collection-descriptor>
</class-descriptor>
<class-descriptor class="ValueData" table="VALUE_DATA">
<field-descriptor name="id" column="ID" jdbc-type="INTEGER"
primarykey="true"/>
<field-descriptor name="date" column="DATE" jdbc-type="TIMESTAMP"
primarykey="true"/>
<field-descriptor name="value" column="VALUE" jdbc-type="REAL"/>
</class-descriptor>
So i would like , only record in my collection for an id and a date given
I try many of solutions to have a correct results like this one
Criteria criteres = new Criteria();
criteres.addEqualTo("id", new Integer(1));
criteres.addEqualTo("listeValueData.date", valueDate);
QueryByCriteria q = new QueryByCriteria(InfoData.class,
criteres);
collection = broker.getCollectionByQuery(q);
with subquery or with QueryCustomizer (can not change the attribute on
the fly ?).... and i have always got all the rows of the table VALUE_DATA
is there the generated sql :
[http-8080-Processor4] 2006/01/11 17:03:21,663 DEBUG JdbcAccessImpl
executeQuery: QueryByCriteria from class
ame.gcr.domaine.instrument.InfoData where [id = 1, listeValueData.date
= 2006-01-04 00:00:00.0]
[http-8080-Processor4] 2006/01/11 17:03:21,663 DEBUG
SqlQueryStatement$TableAlias TableAlias(): using hints ? false
[http-8080-Processor4] 2006/01/11 17:03:21,663 DEBUG
SqlQueryStatement$TableAlias TableAlias(): using hints ? false
[http-8080-Processor4] 2006/01/11 17:03:21,663 DEBUG
SqlGeneratorDefaultImpl Result of getTableAlias(): VALUE_DATA A1
[http-8080-Processor4] 2006/01/11 17:03:21,663 DEBUG
SqlGeneratorDefaultImpl SQL:SELECT A0.ID,A0.NAME FROM INFO_DATA
A0,VALUE_DATA A1 WHERE A0.ID=A1.ID AND ((A0.ID = ?) AND A1.DATE = ?)
[http-8080-Processor4] 2006/01/11 17:03:21,679 DEBUG JdbcAccessImpl
executeQuery: org.apache.commons.dbcp.DelegatingPreparedStatement@1b6fd5c
[http-8080-Processor4] 2006/01/11 17:03:21,679 DEBUG JdbcAccessImpl
executeQuery: QueryByCriteria from class
ame.gcr.domaine.instrument.ValueData where [id = 1]
[http-8080-Processor4] 2006/01/11 17:03:21,679 DEBUG
SqlQueryStatement$TableAlias TableAlias(): using hints ? false
[http-8080-Processor4] 2006/01/11 17:03:21,679 DEBUG
SqlGeneratorDefaultImpl SQL:SELECT A0.ID,A0.DATE,A0.VALUE FROM
VALUE_DATA A0 WHERE A0.ID = ?
[http-8080-Processor4] 2006/01/11 17:03:21,679 DEBUG JdbcAccessImpl
executeQuery: org.apache.commons.dbcp.DelegatingPreparedStatement@228ba7
Thanks for your advice
Regards
Renaud
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-user-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-user-help@db.apache.org
Re: Collection problem 1:n relationship
Posted by Armin Waibel <ar...@apache.org>.
Hi Renaud,
Renaud Lévy wrote:
> Hello,
>
> I've got a simple problem of collection's retrieve :
> There are 2 tables : InfoData and ValueData with foreign key and
> datetime field
> as it's describe in my repository
>
> <class-descriptor class="InfoData" table="INFO_DATA">
> <field-descriptor name="id" column="ID" jdbc-type="INTEGER"
> primarykey="true"/>
> <field-descriptor name="name" column="NAME" jdbc-type="VARCHAR"/>
> <collection-descriptor
> name="listeValueData"
> element-class-ref="ValueData"
> auto-retrieve="true" auto-update="false" auto-delete="false">
> <inverse-foreignkey field-ref="id"/>
> </collection-descriptor>
> </class-descriptor>
>
> <class-descriptor class="ValueData" table="VALUE_DATA">
> <field-descriptor name="id" column="ID" jdbc-type="INTEGER"
> primarykey="true"/>
> <field-descriptor name="date" column="DATE" jdbc-type="TIMESTAMP"
> primarykey="true"/>
> <field-descriptor name="value" column="VALUE" jdbc-type="REAL"/>
> </class-descriptor>
>
Class ValueData use a compound PK but in the collection-descriptor of
InfoData you only define one part of the compounded PK (ref to 'id').
Please try to add a element-class-ref for 'data' too or if possible
disable PK setting in ValueData.
HTH
regards,
Armin
> So i would like , only record in my collection for an id and a date given
> I try many of solutions to have a correct results like this one
>
> Criteria criteres = new Criteria();
> criteres.addEqualTo("id", new Integer(1));
> criteres.addEqualTo("listeValueData.date", valueDate);
> QueryByCriteria q = new QueryByCriteria(InfoData.class, criteres);
> collection = broker.getCollectionByQuery(q);
>
> with subquery or with QueryCustomizer (can not change the attribute on
> the fly ?).... and i have always got all the rows of the table VALUE_DATA
>
> is there the generated sql :
>
> [http-8080-Processor4] 2006/01/11 17:03:21,663 DEBUG JdbcAccessImpl
> executeQuery: QueryByCriteria from class
> ame.gcr.domaine.instrument.InfoData where [id = 1, listeValueData.date
> = 2006-01-04 00:00:00.0]
> [http-8080-Processor4] 2006/01/11 17:03:21,663 DEBUG
> SqlQueryStatement$TableAlias TableAlias(): using hints ? false
> [http-8080-Processor4] 2006/01/11 17:03:21,663 DEBUG
> SqlQueryStatement$TableAlias TableAlias(): using hints ? false
> [http-8080-Processor4] 2006/01/11 17:03:21,663 DEBUG
> SqlGeneratorDefaultImpl Result of getTableAlias(): VALUE_DATA A1
> [http-8080-Processor4] 2006/01/11 17:03:21,663 DEBUG
> SqlGeneratorDefaultImpl SQL:SELECT A0.ID,A0.NAME FROM INFO_DATA
> A0,VALUE_DATA A1 WHERE A0.ID=A1.ID AND ((A0.ID = ?) AND A1.DATE = ?)
> [http-8080-Processor4] 2006/01/11 17:03:21,679 DEBUG JdbcAccessImpl
> executeQuery: org.apache.commons.dbcp.DelegatingPreparedStatement@1b6fd5c
> [http-8080-Processor4] 2006/01/11 17:03:21,679 DEBUG JdbcAccessImpl
> executeQuery: QueryByCriteria from class
> ame.gcr.domaine.instrument.ValueData where [id = 1]
> [http-8080-Processor4] 2006/01/11 17:03:21,679 DEBUG
> SqlQueryStatement$TableAlias TableAlias(): using hints ? false
> [http-8080-Processor4] 2006/01/11 17:03:21,679 DEBUG
> SqlGeneratorDefaultImpl SQL:SELECT A0.ID,A0.DATE,A0.VALUE FROM
> VALUE_DATA A0 WHERE A0.ID = ?
> [http-8080-Processor4] 2006/01/11 17:03:21,679 DEBUG JdbcAccessImpl
> executeQuery: org.apache.commons.dbcp.DelegatingPreparedStatement@228ba7
>
> Thanks for your advice
>
> Regards
>
> Renaud
>
>
> ---------------------------------------------------------------------
> 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