You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Michael Dick (JIRA)" <ji...@apache.org> on 2007/06/29 17:01:08 UTC

[jira] Closed: (OPENJPA-270) Delete Query transformed into a Select Query

     [ https://issues.apache.org/jira/browse/OPENJPA-270?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Dick closed OPENJPA-270.
--------------------------------


> 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 query 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 = InheritanceType.TABLE_PER_CLASS)
> @Table(name = "PERS")
> public class PersonneR implements comparable {
> 	@Id
> 	@Column(name = "SSID", nullable = false, length = 40)
> 	private int SSid;
> 	@Basic
> 	@Column(name = "PERS_NOM", nullable = false, length = 40)
> 	private String nom;
> 	@Basic
> 	@Column(name = "PERS_PRENOM", nullable = false, length = 40)
> ...
> }
> Then my Employee class :
> @Entity
> @Inheritance (strategy = InheritanceType.TABLE_PER_CLASS)
> @Table(name = "EMPL")
> public class EmployeR implements Comparable {
> 	@EmbeddedId
> 	private PersonneR pers;
> 	@ManyToOne (optional = false,cascade = {CascadeType.PERSIST }) @JoinColumn(name = "NUM", unique = false, nullable = false, updatable = false, referencedColumnName = "NUM", table = "SERV")
> 	private ServiceR affectation;
> ...
> }
> The Service class is not important but i put it here :
> @Entity
> @Inheritance (strategy = InheritanceType.TABLE_PER_CLASS)
> @Table(name = "SERV")
> public class ServiceR implements Comparable {
> 	@Id
> 	@Column(name = "NUM", nullable = false, length = 5)
> 	private int numero;
> 	@Basic
> 	@Column(name = "SERV_NOM", nullable = false, length = 40)
> 	private 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,affectation_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 "nom1") who had been persisted,
> whith the following query :
> // PersonneR pers is the pers fiel of the EmployeR object I want to delete.
> Query qp = this.em.createQuery("DELETE FROM EmployeR t0 where (t0.pers=?1)");
> qp.setParameter(1, pers);
> int deleted = qp.executeUpdate();
> I have the following trace :
> 2165  empjpa  TRACE  [main] openjpa.jdbc.SQL - <t 32519825, conn 6237616> executing prepstmnt 3157607 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 = t1.NUM WHERE (t0.SSID = ? AND t0.PERS_NOM = ? AND t0.PERS_PRENOM = ?) [params=(int) 1, (String) nom1, (String) prenom1]
> 2165  empjpa  TRACE  [main] openjpa.jdbc.SQL - <t 32519825, conn 6237616> [0 ms] spent
> 0 lignes effacées.
> And there is a "select" where I wanted a "delete".
> The JPQL query is, in my opinion, correct, and the where clause is correctly 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=1) and (t0.pers.nom=nom1) and (t0.pers.prenom=prenom1)", via setparameter(int pos,Object param), but OpenJPA said "Argument Exception : null"
> I also tried in the where clause  : "('t0.pers.ssid'=1) and ('t0.pers.nom'=nom1) and ('t0.pers.prenom'=prenom1)", via setparameter(int pos,Object param), but OpenJPA do a select.
> I also tried in the where clause "(t0.ssid=1) and (t0.nom=nom1) and (t0.prenom=prenom1)" , via setparameter(int pos,Object param), but OpenJPA said that there is no ssid field in class EmployeR
> I also tried "('t0.ssid'=1) and ('t0.nom'=nom1) and ('t0.prenom'=prenom1)" , 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 select query instead of a delete, I'm waiting for their ideas, and i'm still trying to solve the problem.
> thanks for your help

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.