Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Problem with deletion on secondary table with composite key
PostPosted: Tue Oct 31, 2017 2:00 pm 
Beginner
Beginner

Joined: Wed Sep 03, 2003 9:31 am
Posts: 26
Using Hibernate 5.2.11-Final on SQLServer 2014 and jTDS driver.

I have an entity mapped like this:

Code:
@Entity
@Table(name="table1")
@SecondaryTable(name="table2", pkJoinColumns={
    @PrimaryKeyJoinColumn(name="pk1", referencedColumnName="pk1"),
    @PrimaryKeyJoinColumn(name="pk2", referencedColumnName="pk2")
})
public class MyPojo {
   properties
}


I'm trying to delete this entity using the following JPA criteria:

Code:
CriteriaDelete<MyPojo> deleteCriteria = builder.createCriteriaDelete(MyPojo.class);
Root<MyPojo> fromMyPojo = deleteCriteria.from(MyPojo.class);
session.createQuery(deleteCriteria
                    .where(builder.equal(fromMyPojo.get("compositeId"), compositeIdInstance)))
                    .executeUpdate();


Hibernate generates series of statements:
    creates a temporary table
    populates it with the composite keys of the rows that will be deleted
    executes the delete statement using the composite keys from the temporary table
    drops the temporary table

I'm receiving the following error because of the delete statement:

Code:
Caused by: java.sql.SQLException: An expression of non-boolean type specified in a context where a condition is expected, near ','.


The delete statement is:
Code:
delete from table2
where (pk1, pk2) in (select pk1, pk2 from #table1)


Apparently the expression where (pk1, pk2) in (select pk1, pk2 from #table1) is wrong.

I don't know what to do except throw a native sql query and delete both main and secondary tables.

What am I doing wrong?


Top
 Profile  
 
 Post subject: Re: Problem with deletion on secondary table with composite key
PostPosted: Tue Oct 31, 2017 3:11 pm 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1531
Location: Romania
Looks like a bug. Please provide a replicating test case and open a Jira issue.

Meanwhile, you can try with these extra bulk-id strategies.

_________________
If you liked my answer, you are going to love my High-Performance Java Persistence book and my blog as well.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.