You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by "Das, Aditi" <Ad...@schwab.com> on 2008/04/14 23:33:06 UTC

JPQL delete fetches the record first before deleting. Why?

Hi,
 
I want to delete from table ORDER where order_id = 100, Also order table
should cascade delete it's child table.
 
But with the below statement, openJPA executes a select query for ORDER
and it's child table before executing the delete query. These extra sqls
are hit on performance. Am I missing out any configuration setting?
 
I am using openjpa-1.0.2 and mysql DB.
 
Query query = em.createNamedQuery("deleteCart");
query.setParameter("orderId", 100);
int ret = query.executeUpdate();
 
Below is the Order entity
-----------------------------------------------------------------
@Entity(name="ORDER")
@NamedQueries({
    @NamedQuery(name="deleteCart",
        query="DELETE from ORDER ord where ord.orderId = :orderId")
  
})
@Table(name="ORDERS", schema="ormtest")
public class Order {
 
 @Id
 @Column(name="ORDER_ID", updatable = false) // Well, no one should
update primary key
 
@TableGenerator(name="order_tab_seq",table="SEQUENCE_TABLE",pkColumnName
="ID",pkColumnValue="ORDER",valueColumnName="SEQUENCE_VALUE",allocationS
ize=1)
 @GeneratedValue(strategy =
GenerationType.TABLE,generator="order_tab_seq")
 private int orderId;
 
 @Column(name="CUST_ID",nullable=false)
 private int custId;
 
 @Column(name="TOTAL_PRICE",nullable=false)
 private double totalPrice;
 
 @Column(name="ORDER_DATE",nullable=false)
 private Date orderDate;
 
 @Column(name="IS_FULFILLED")
private String isFulFilled;
 
 @ManyToOne(optional=false,fetch=FetchType.LAZY)
 @JoinColumn(name="CUST_ID",referencedColumnName="CUST_ID")
 private Customer customer;
 
 @Column(name="CUST_BILLING_ID")
 private int custBillingId;
 
 @Version
 @Column(name="LAST_UPDATED_TIME",nullable=false)
 private Date lastUpdatedTime;
 
 // One order can have many Order detail
 
@OneToMany(mappedBy="order",targetEntity=OrderDetail.class,fetch=FetchTy
pe.EAGER,cascade={CascadeType.REMOVE,CascadeType.PERSIST})
 @OrderBy
 private List<OrderDetail> orderDetailList;
................
}
------------------------------------------------------------------------
--
Regards,
Aditi