openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Frederic Jeanneau (JIRA)" <>
Subject [jira] Created: (OPENJPA-270) Delete Query transformed into a Select Query
Date Thu, 28 Jun 2007 08:44:25 GMT
Delete Query transformed into a Select Query

                 Key: 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
            Reporter: Frederic Jeanneau

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 :

@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "PERS")
public class PersonneR implements comparable {
	@Column(name = "SSID", nullable = false, length = 40)
	private int SSid;
	@Column(name = "PERS_NOM", nullable = false, length = 40)
	private String nom;
	@Column(name = "PERS_PRENOM", nullable = false, length = 40)

Then my Employee class :

@Inheritance (strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "EMPL")
public class EmployeR implements Comparable {
	private PersonneR pers;
	@ManyToOne (optional = false,cascade = {CascadeType.PERSIST }) @JoinColumn(name = "NUM",
unique = false, nullable = false, updatable = false, referencedColumnName = "NUM", table =
	private ServiceR affectation;


The Service class is not important but i put it here :

@Inheritance (strategy = InheritanceType.TABLE_PER_CLASS)
@Table(name = "SERV")
public class ServiceR implements Comparable {
	@Column(name = "NUM", nullable = false, length = 5)
	private int numero;
	@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
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

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"...

So, if someone know how to delete by query, or why OpenJPA launch a select query, 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.

View raw message