我有两个实体。数据集市和实体数据。entity_data 扩展了 data_mart。我在 data_mart 和 entity_data 中都有 id 列。entity mart中的data_id是data_mart的foregin key(Pkey over there is id)。
@Entity
@Table(name = "data_mart")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(name = "type")
public class DataMaster {
/** The id. */
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(unique = true, nullable = false)
private Long id;
/** The type. */
private String type;
/** The created by. */
private String createdBy;
.....
}
@Entity
@Table(name = "entity_data")
@PrimaryKeyJoinColumn(name = "dataId")
@DiscriminatorValue("FILE")
@Where(clause = "active = '1'")
public class EntityData extends DataMaster {
/** The data id. */
@Column(insertable = false, updatable = false)
private Long dataId;
/** The delimiter. */
private String delimiter;
....
}
而子表的表结构如下
CREATE TABLE entity_data (
id bigint(20) NOT NULL AUTO_INCREMENT,
data_id bigint(20) NOT NULL,
delimiter varchar(20) DEFAULT NULL,
file_path `varchar(200) DEFAULT NULL,
...
)
当我尝试使用 HQL 查询更新表 entity_data 时,下面是由 Hibernate 形成的中间查询
create temporary table if not exists HT_entity_data (id bigint not null);
insert into HT_entity_data
select entitydata0_.data_id as data_id from entity_data
entitydata0_ inner join data_master entitydata0_1_ on
entitydata0_.data_id=entitydata0_1_.id where entitydata0_.file_path='abcdd'
update entity_data set file_path='new_path'
where (id) IN (select data_id from HT_entity_data)
上面的查询给出了错误的结果。在上述update语句的where子句中,id来了。它应该是 data_id。
我不知道这是怎么拍的??