Welcome Guest  |  Register  |  Login
Login Name Password
  Search  
  Index  | Recent Threads  | Unanswered Threads  | Who's Online  | Help


Quick Go »

No member browsing this thread
Thread Status: Active
Total posts in this thread: 5
[ Jump to Last Post ]
Post new Thread
Author
Previous Thread This topic has been viewed 1271 times and has 4 replies Next Thread
Female stephbibie
Newbie




Joined: May 3, 2006
Post Count: 9
Status: Offline
Reply to this Post  Reply with Quote 
JDODataStoreException when querring a collection in many to many relation

Hello,

I have 2 classes Critere and SousRubrique. Each class have a reference to the other. And I want to get all the Critere objects which have a specified SousRubrique.

Here is my pojos :

package modele.pojos;

import java.util.Set;

public class Critere {

private int id;
private String nom;
private Set<SousRubrique> sousRubriques;

.....

//all getters and setters

}

package modele.pojos;

import java.util.Set;

public class SousRubrique {

private int id;
private String nom;
private Rubrique rubrique;
private Set<Critere> criteres;

.....

//all getters and setters

}

and my metadata file :

<class name="SousRubrique" identity-type="application" table="sous_rubriques">
<field name="id" primary-key="true">
<column name="ID_SOUS_RUBRIQUE"/>
</field>
<field name="nom" >
<column precision="200"/>
</field>
<field name="rubrique">
<column name="ID_RUBRIQUE"/>
</field>
<field name="criteres" table="asso_sous_rubriques_criteres" default-fetch-group="true">
<collection element-type="Critere"/>
<join>
<column name="ID_SOUS_RUBRIQUE"/>
</join>
<element>
<column name="ID_CRITERE"/>
</element>
<extension vendor-name="jpox" key="cache-lazy-loading" value="false"/>
</field>
</class>

<class name="Critere" identity-type="application" table="criteres">
<field name="id" primary-key="true">
<column name="id_critere"/>
</field>
<field name="nom">
<column precision="100"/>
</field>
<field name="sousRubriques" persistence-modifier="persistent" mapped-by="criteres">
<collection element-type="SousRubrique"/>
</field>
</class>


So when I try to get the Critere objects by this way :

public List<Critere> getCriteresBySousRubrique(SousRubrique sr){
PersistenceManager pm = null;
Transaction tx = null;
Collection objects = null;
List<Critere> list = new ArrayList<Critere>();

try{
pm = PersistanceManageur.currentPM(false);
tx = pm.currentTransaction();
tx.begin();
Query q = pm.newQuery(Critere.class, "sousRubriques.contains(sr)");
objects = (Collection) q.execute();
Iterator iter = objects.iterator();
if (! iter.hasNext()){
System.out.println("Aucune classe trouvée");
}
else {
while (iter.hasNext()) {
list.add((Critere) iter.next());
}
}
tx.commit();

}
catch (Exception e){
e.printStackTrace();
}
finally{
if(tx.isActive())
tx.rollback();
PersistanceManageur.closePM();
}

return list;
}


I have this error :
javax.jdo.JDODataStoreException: Error executing JDOQL query "SELECT 'modele.pojos.Critere' AS JPOXMETADATA,THIS.ID_CRITERE,THIS.NOM,THIS.NON_AFFICHE FROM CRITERES THIS WHERE EXISTS (SELECT 1 FROM ASSO_SOUS_RUBRIQUES_CRITERES THIS_SOUSRUBRIQUES_SR,SOUS_RUBRIQUES UNBOUND_SR WHERE THIS_SOUSRUBRIQUES_SR.ID_CRITERE = THIS.ID_CRITERE AND THIS_SOUSRUBRIQUES_SR.ID_CRITERE = THIS.ID_CRITERE AND UNBOUND_SR.ID_SOUS_RUBRIQUE = THIS_SOUSRUBRIQUES_SR.ID_SOUS_RUBRIQUE)" : Erreur de syntaxe près de 'EXISTS (SELECT 1 FROM ASSO_SOUS_RUBRIQUES_CRITERES THIS_SOUSRUBR' à la ligne 1

I also tried like this :

Query q = pm.newQuery(Critere.class, "sousRubriques.contains(sr)");
q.declareParameters("SousRubrique sr");
objects = (Collection) q.execute(sr);

But I get the same error
----------------------------------------
[Edit 1 times, last edit by stephbibie at May 22, 2006 4:04:25 PM]
[May 22, 2006 2:58:05 PM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male erik
Expert
Member's Avatar

Belgium
Joined: Mar 12, 2004
Post Count: 2991
Status: Offline
Reply to this Post  Reply with Quote 
Re: JDODataStoreException when querring a collection in many to many relation

This query should work, but it seems your database does not support it. which db are you using? we can try to find a workaround
----------------------------------------
Erik Bengtson


[May 22, 2006 5:10:27 PM] Show Printable Version of Post    View Member Profile    Send Private Message    Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Female stephbibie
Newbie




Joined: May 3, 2006
Post Count: 9
Status: Offline
Reply to this Post  Reply with Quote 
Re: JDODataStoreException when querring a collection in many to many relation

I'm using MySQL 4.0.15 database
[May 23, 2006 7:11:57 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Male andy
Expert
Member's Avatar

UK
Joined: Mar 13, 2004
Post Count: 5686
Status: Offline
Reply to this Post  Reply with Quote 
Re: JDODataStoreException when querring a collection in many to many relation

I'm using MySQL 4.0.15 database

Use of EXISTS is stated in the JPOX docs http://www.jpox.org/docs/1_1/rdbms.html as only being supported by MySQL from 4.1
----------------------------------------
-Andy smile

[May 23, 2006 8:03:05 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
Female stephbibie
Newbie




Joined: May 3, 2006
Post Count: 9
Status: Offline
Reply to this Post  Reply with Quote 
Re: JDODataStoreException when querring a collection in many to many relation

You're right, I updated my MySQL version and now it works. Thanks a lot !
[May 23, 2006 9:02:56 AM] Show Printable Version of Post    View Member Profile    Send Private Message [Link] Report threatening or abusive post: please login first  Go to top 
[ Jump to Last Post ]
Show Printable Version of Thread  Post new Thread