mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-19 21:00:53 +08:00
Add delete where subquery exists test
This commit is contained in:
parent
2c7ad605d4
commit
d2ec70e6e7
@ -34,8 +34,11 @@ import org.junit.rules.MethodRule;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import com.mysema.query.jpa.JPASubQuery;
|
||||
import com.mysema.query.jpa.JPQLSubQuery;
|
||||
import com.mysema.query.jpa.domain.Cat;
|
||||
import com.mysema.query.jpa.domain.QCat;
|
||||
import com.mysema.query.jpa.domain.QChild;
|
||||
import com.mysema.query.jpa.domain.QParent;
|
||||
import com.mysema.query.jpa.impl.JPADeleteClause;
|
||||
import com.mysema.query.jpa.impl.JPAQuery;
|
||||
import com.mysema.query.types.EntityPath;
|
||||
@ -169,4 +172,21 @@ public class JPABase extends AbstractStandardTest {
|
||||
child.in(parent.kittens)).exists())
|
||||
.execute();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Delete_Where_SubQuery2() {
|
||||
QChild child = QChild.child;
|
||||
QParent parent = QParent.parent;
|
||||
|
||||
JPASubQuery subQuery = new JPASubQuery()
|
||||
.from(parent)
|
||||
.where(parent.id.eq(2),
|
||||
child.parent.eq(parent));
|
||||
//child.in(parent.children));
|
||||
|
||||
delete(child)
|
||||
.where(child.id.eq(1), subQuery.exists())
|
||||
.execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
package com.mysema.query.jpa.domain;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
|
||||
@Entity(name="Child2")
|
||||
public class Child {
|
||||
|
||||
@Id
|
||||
int id;
|
||||
|
||||
@ManyToOne
|
||||
Parent parent;
|
||||
|
||||
}
|
||||
@ -35,6 +35,7 @@ public final class Domain {
|
||||
Calendar.class,
|
||||
Cat.class,
|
||||
Catalog.class,
|
||||
Child.class,
|
||||
Color.class,
|
||||
Company.class,
|
||||
Customer.class,
|
||||
@ -62,6 +63,7 @@ public final class Domain {
|
||||
Novel.class,
|
||||
Order.class,
|
||||
Parameter.class,
|
||||
Parent.class,
|
||||
Payment.class,
|
||||
PaymentStatus.class,
|
||||
Person.class,
|
||||
|
||||
@ -0,0 +1,18 @@
|
||||
package com.mysema.query.jpa.domain;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
|
||||
@Entity(name="Parent2")
|
||||
public class Parent {
|
||||
|
||||
@Id
|
||||
int id;
|
||||
|
||||
@OneToMany(mappedBy = "parent")
|
||||
Set<Child> children;
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user