{code:java} @Entity @Access(AccessType.FIELD) public class D2 { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Column(name = "id", nullable = false) private int id;
@ManyToOne @JoinColumn(name = "customerId", nullable = false) private Customer customer; }
@Entity public abstract class AbstractD2Source { ... @OneToOne(optional = true) @JoinColumn(name = "dId", nullable = true) private D2 d; ... }
CriteriaDelete<AbstractD2Source> query = cb.createCriteriaDelete(AbstractD2Source.class); Root<AbstractD2Source> dSource = query.from(AbstractD2Source.class); query.where(cb.and( cb.equal(dSource.get(AbstractD2Source_.d).get(D2_.customer), customer), datafeedSource.get(AbstractD2Source_.id).in(dSourceIds) )); return em.createQuery(query).executeUpdate(); {code}
The forementioned produces an error: Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 'customerId' in 'where clause'
{code:java} 11.06. 14:37:14,087 INFO [stdout] (default task-1) Hibernate: insert into HT_dfSource select abstractda0_.id as id from dfSource abstractda0_ where customerId=1 and (abstractda0_.id in (1047)) 11.06. 14:37:14,096 WARN [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-1) SQL Error: 1054, SQLState: 42S22 11.06. 14:37:14,096 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-1) Unknown column 'customerId' in 'where clause' {code}
Workaround that works (without CriteriaDelete):
{code:java} CriteriaQuery<Integer> query01 = cb.createQuery(Integer.class); Root<AbstractD2Source> dSource01 = query01.from(AbstractD2Source.class); query01.select(dSource01.get(AbstractD2Source_.id)); query01.where(cb.and( cb.equal(dSource01.get(AbstractD2Source_.datafeed).get(D2_.customer), customer), dSource01.get(AbstractD2Source_.id).in(datafeedSourceIds) )); List<Integer> checkedIds = getResultListFromQuery(query01);
CriteriaDelete<AbstractD2Source> query = cb.createCriteriaDelete(AbstractD2Source.class); Root<AbstractD2Source> dSource = query.from(AbstractD2Source.class); query.where(dSource.get(AbstractD2Source_.id).in(checkedIds)); return em.createQuery(query).executeUpdate(); {code} |
|