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 Reno <re...@laposte.net> on 2006/01/12 13:53:42 UTC

Collection problem 1:n relationship again

Thanks you for your response but if i disable the PK setting in 
ValueData, i have got still all the value from the table VALUE_DATA.

Ii would like to  fix the clause as i want to (for example DATE = 
"2006-01-12")
but ojb with the "auto-retrive=true" do that : SqlGeneratorDefaultImpl 
SQL:SELECT A0.ID,A0.DATE,A0.VALUE FROM VALUE_DATA A0 WHERE A0.ID = ?

i prefer to have this one : SqlGeneratorDefaultImpl  SQL:SELECT A0.ID,A0.DATE,A0.VALUE FROM VALUE_DATA A0 WHERE A0.ID = ? and A0.DATE = ?

Thx 

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 again

Posted by Armin Waibel <ar...@apache.org>.
Hi Reno,

Reno wrote:
> 
> Thanks you for your response but if i disable the PK setting in 
> ValueData, i have got still all the value from the table VALUE_DATA.
> 
> Ii would like to  fix the clause as i want to (for example DATE = 
> "2006-01-12")
> but ojb with the "auto-retrive=true" do that : SqlGeneratorDefaultImpl 
> SQL:SELECT A0.ID,A0.DATE,A0.VALUE FROM VALUE_DATA A0 WHERE A0.ID = ?
> 
> i prefer to have this one : SqlGeneratorDefaultImpl  SQL:SELECT 
> A0.ID,A0.DATE,A0.VALUE FROM VALUE_DATA A0 WHERE A0.ID = ? and A0.DATE = ?
> 

This sounds really strange. I setup a similar test (with OJB 1.0.4) 
using class Project and SubProject with a 1:n relation between Project 
and SubProject (I assume you copy the PK of InfoData to ValueData, 
because you don't use a autoincrement PK field in ValueData):

...
Project project = new Project(name, null, null);
Timestamp t1 = new Timestamp(System.currentTimeMillis());
Timestamp t2 = new Timestamp(t1.getTime() + 1);
broker.beginTransaction();
// first store the project to assign the PK
broker.store(project);
// now we can use the project id as part of the compounded SubProject_2 
PK (id, date)
SubProject_2 sub_1 = new SubProject_2(project.getId(), t1, name + 
"_dvd", project);
SubProject_2 sub_2 = new SubProject_2(project.getId(), t2, name + 
"_book", project);
project.addSubProject_2(sub_1);
project.addSubProject_2(sub_2);
broker.store(project);
broker.commitTransaction();

broker.beginTransaction();
broker.clearCache();
Criteria criteria = new Criteria();
criteria.addBetween("subProject_2s.date", new Timestamp(t1.getTime() - 
1), new Timestamp(t2.getTime() + 1));
Query q = QueryFactory.newQuery(Project.class, criteria, true);
Collection projects = broker.getCollectionByQuery(q);
...


SELECT A0.PRO_ID,A0.NAME FROM COL_2_PROJECT A0 INNER JOIN 
COL_2_SUB_PROJECT_2 A1 ON A0.PRO_ID=A1.SUB_ID WHERE A1.SUB_DATE BETWEEN 
'2006-01-16 12:17:25.281' AND '2006-01-16 12:17:25.282'

The join between Project and SubProject was correct resolved. Did you 
modify/extend any OJB classes?

regards,
Armin


> Thx
> 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