From dev-return-4687-apmail-openjpa-dev-archive=openjpa.apache.org@openjpa.apache.org Fri Jun 29 06:57:39 2007 Return-Path: Delivered-To: apmail-openjpa-dev-archive@www.apache.org Received: (qmail 33261 invoked from network); 29 Jun 2007 06:57:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 29 Jun 2007 06:57:32 -0000 Received: (qmail 58090 invoked by uid 500); 29 Jun 2007 06:57:30 -0000 Delivered-To: apmail-openjpa-dev-archive@openjpa.apache.org Received: (qmail 58017 invoked by uid 500); 29 Jun 2007 06:57:29 -0000 Mailing-List: contact dev-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@openjpa.apache.org Delivered-To: mailing list dev@openjpa.apache.org Received: (qmail 57877 invoked by uid 99); 29 Jun 2007 06:57:29 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Jun 2007 23:57:29 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO brutus.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Jun 2007 23:57:25 -0700 Received: from brutus (localhost [127.0.0.1]) by brutus.apache.org (Postfix) with ESMTP id F365E7141E7 for ; Thu, 28 Jun 2007 23:57:04 -0700 (PDT) Message-ID: <3778007.1183100224993.JavaMail.jira@brutus> Date: Thu, 28 Jun 2007 23:57:04 -0700 (PDT) From: "Frederic Jeanneau (JIRA)" To: dev@openjpa.apache.org Subject: [jira] Commented: (OPENJPA-270) Delete Query transformed into a Select Query In-Reply-To: <17891438.1183020265902.JavaMail.jira@brutus> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/OPENJPA-270?page=3Dcom.atlassia= n.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12509028 ]=20 Frederic Jeanneau commented on OPENJPA-270: ------------------------------------------- Thanks for your answer. In fact, I have a matching row in the table, but I don't see any delete sta= tement. I tried this morning, and it work. Requete : delete from EmployeR t0 where (t0.pers=3D?1) param 1 : 1 : prenom1 nom1 2218 empjpa TRACE [main] openjpa.jdbc.SQL - e= xecuting prepstmnt 15605470 SELECT t0.SSID, t0.PERS_NOM, t0.PERS_PRENOM, t1= .NUM, t1.SERV_NOM FROM EMPL t0 INNER JOIN SERV t1 ON t0.affectation_NUM =3D= t1.NUM WHERE (t0.SSID =3D ? AND t0.PERS_NOM =3D ? AND t0.PERS_PRENOM =3D ?= ) [params=3D(int) 1, (String) nom1, (String) prenom1] 2218 empjpa TRACE [main] openjpa.jdbc.SQL - [= 0 ms] spent 1 lignes effac=C3=A9es. 2250 empjpa TRACE [main] openjpa.jdbc.SQL - = executing prepstmnt 18135083 DELETE FROM EMPL WHERE SSID =3D ? AND PERS_NOM= =3D ? AND PERS_PRENOM =3D ? [params=3D(int) 1, (String) nom1, (String) pre= nom1] 2250 empjpa TRACE [main] openjpa.jdbc.SQL - = [0 ms] spent It seems that the row was the same but different, because I added manually = the row (problem of join persistance) Thanks for your help. > Delete Query transformed into a Select Query > -------------------------------------------- > > Key: OPENJPA-270 > URL: https://issues.apache.org/jira/browse/OPENJPA-270 > Project: OpenJPA > Issue Type: Bug > Components: jpa, query > Affects Versions: 0.9.7 > Environment: Java JRE 1.5 > OpenJPA 0.9.7 > IDE Eclipse > MySQL 4.1.9 DataBase (EasyPhp 1.8.0.1) > Reporter: Frederic Jeanneau > > Hello. > I'm french, so excuse my english. > I have a problem while trying to delete (and so update) an object. > The JQL syntax is correct (i think), but at the executeUpdate(), the quer= y is transformed into a select. > First, my object : > I have classical - test objects : employees, persons, service. > An employee is a person affected to a service > A service as a number and a name > A person has a number ID, a name and a surname. > First, the Person : > @Embeddable > @Inheritance(strategy =3D InheritanceType.TABLE_PER_CLASS) > @Table(name =3D "PERS") > public class PersonneR implements comparable { > =09@Id > =09@Column(name =3D "SSID", nullable =3D false, length =3D 40) > =09private int SSid; > =09@Basic > =09@Column(name =3D "PERS_NOM", nullable =3D false, length =3D 40) > =09private String nom; > =09@Basic > =09@Column(name =3D "PERS_PRENOM", nullable =3D false, length =3D 40) > ... > } > Then my Employee class : > @Entity > @Inheritance (strategy =3D InheritanceType.TABLE_PER_CLASS) > @Table(name =3D "EMPL") > public class EmployeR implements Comparable { > =09@EmbeddedId > =09private PersonneR pers; > =09@ManyToOne (optional =3D false,cascade =3D {CascadeType.PERSIST }) @Jo= inColumn(name =3D "NUM", unique =3D false, nullable =3D false, updatable = =3D false, referencedColumnName =3D "NUM", table =3D "SERV") > =09private ServiceR affectation; > ... > } > The Service class is not important but i put it here : > @Entity > @Inheritance (strategy =3D InheritanceType.TABLE_PER_CLASS) > @Table(name =3D "SERV") > public class ServiceR implements Comparable { > =09@Id > =09@Column(name =3D "NUM", nullable =3D false, length =3D 5) > =09private int numero; > =09@Basic > =09@Column(name =3D "SERV_NOM", nullable =3D false, length =3D 40) > =09private String nom; > ... > } > So, then I create an Entity manager, persist an employee and service. > I have 2 tables : > Table "empl" for the person/employee (SSID,PERS_NOM,PERS_PRENOM,affectati= on_NUM) > Primary key (SSID,PERS_NOM,PERS_PRENOM) (fields of the type Person) > Table "serv" for the service (NUM, SERV_NOM) > Primary Key : Num > But when I try to delete an employee (num 1, name "prenom1", surname "nom= 1") who had been persisted, > whith the following query : > // PersonneR pers is the pers fiel of the EmployeR object I want to delet= e. > Query qp =3D this.em.createQuery("DELETE FROM EmployeR t0 where (t0.pers= =3D?1)"); > qp.setParameter(1, pers); > int deleted =3D qp.executeUpdate(); > I have the following trace : > 2165 empjpa TRACE [main] openjpa.jdbc.SQL - = executing prepstmnt 3157607 SELECT t0.SSID, t0.PERS_NOM, t0.PERS_PRENOM, t= 1.NUM, t1.SERV_NOM FROM EMPL t0 INNER JOIN SERV t1 ON t0.affectation_NUM = =3D t1.NUM WHERE (t0.SSID =3D ? AND t0.PERS_NOM =3D ? AND t0.PERS_PRENOM = =3D ?) [params=3D(int) 1, (String) nom1, (String) prenom1] > 2165 empjpa TRACE [main] openjpa.jdbc.SQL - = [0 ms] spent > 0 lignes effac=C3=A9es. > And there is a "select" where I wanted a "delete". > The JPQL query is, in my opinion, correct, and the where clause is correc= tly understood by OpenJPA. > I also tried to do as in some examples "delete t0 from EmployeR to where = ...." but OpenJPA don't want "to" before "from"... > I also tried a native query, but OpenJPA don't want to call a native sql = query because "it is not supported"... > i also tried in the where clause : "(t0.pers.ssid=3D1) and (t0.pers.nom= =3Dnom1) and (t0.pers.prenom=3Dprenom1)", via setparameter(int pos,Object p= aram), but OpenJPA said "Argument Exception : null" > I also tried in the where clause : "('t0.pers.ssid'=3D1) and ('t0.pers.n= om'=3Dnom1) and ('t0.pers.prenom'=3Dprenom1)", via setparameter(int pos,Obj= ect param), but OpenJPA do a select. > I also tried in the where clause "(t0.ssid=3D1) and (t0.nom=3Dnom1) and (= t0.prenom=3Dprenom1)" , via setparameter(int pos,Object param), but OpenJPA= said that there is no ssid field in class EmployeR > I also tried "('t0.ssid'=3D1) and ('t0.nom'=3Dnom1) and ('t0.prenom'=3Dpr= enom1)" , via setparameter(int pos,Object param),but OpenJPA do a select > So, if someone know how to delete by query, or why OpenJPA launch a selec= t query instead of a delete, I'm waiting for their ideas, and i'm still try= ing to solve the problem. > thanks for your help --=20 This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.