I am trying to do a bulk delete.
Query queryDeleteEntries = entityManager.createQuery("DELETE from
Entry r where (r.person.emailAddress like :name) and (r.otherData is null)");
int deletedEntriesCount = queryDeleteEntries.setParameter("name",
"tester." + emailAddressSuffix).executeUpdate();
I am getting an error:
Caused by: java.sql.SQLException: ORA-00933: SQL command not properly ended
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112) ~[DatabaseError.class:Oracle JDBC Driver version - "10.2.0.2.0"]
Without "and r.otherData is null" it works, so I don't see what the problem is with that?
otherData is a list and it is defined in the Entry class that way:
@OneToMany(fetch = FetchType.EAGER)
@JoinColumn(name = "ENTRY_ID", referencedColumnName = "ID")
private List<OtherData> otherData;
OtherData (name changed) class:
@Entity
@Table(name = "OTHERDATA")
@SequenceGenerator(name = "SEQ", allocationSize = 1, sequenceName = "SEQ_OTHERDATA_ID")
public class OtherData {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ")
private Long id;
...
@Column(name = "ENTRY_ID")
private Long entryId;
Can I not use "is null" on lists?
EDIT
I tried it with "size(r.otherData) = 0" and with "r.otherData IS EMPTY", but both led to the same exception.
What DOES work is this:
Query queryDeleteEntries = entityManager.createQuery("DELETE from Entry r where id in "
+ "(select id from Entry r2 where r2.person.emailAddress like :name"
+ " and not exists (select 1 from OtherData a where a.entryId = r2.id))");
int deletedEntriesCount = queryDeleteEntries.setParameter("name", "tester."+emailAddressSuffix).executeUpdate();
But I think it shouldn't be that complicated! Isn't there an easier way to do that?
Thanks in advance for any hints!