Hello,
i have problem when deleting all records of entities that share the same table and have the same @MappedSuperclass. It seems that HQL query
DELETE <entity_name>
does not consider @DiscriminatorColumn property and deletes all records from underlying table (also sibling entities)
Here are entity definitions:
Code:
@MappedSuperclass
public abstract class AbstractTransaction implements Serializable
{
protected Long id;
...
@Entity(name="TRANSACTION")
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TRANSACTION_TYPE", discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue("Deposit")
public class Deposit extends AbstractTransaction
{
...
Entity
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name="TRANSACTION_TYPE", discriminatorType=DiscriminatorType.STRING)
@DiscriminatorValue("Transaction")
public class Transaction extends AbstractTransaction
{
Java code:Code:
String query = "DELETE banking.entity.Transaction";
int rowCount = session.createQuery(query).executeUpdate();
...
String query = "DELETE banking.entity.Deposit";
int rowCount = session.createQuery(query).executeUpdate();
SQL log:Code:
INFO: Deleting all banking.entity.Transaction
Hibernate: delete from Transaction
INFO: Deleting all banking.entity.Deposit
Hibernate: delete from TRANSACTION
Is there something I misunderstood?
Can anybody explain why the HQL query is translated that way?
Is it a bug?
Thanks for any reply.
Michal Galet