阻止更新父母选择他的孩子

时间:2020-08-19 14:08:40

标签: java database hibernate jpa annotations

我的问题非常简单...更新我的父实体后,它会导致一个选择查询,该查询会在更新或插入子对象之前先选择所有子对象。我想摆脱那些笨拙的选择...

@Entity
@Table(name = "chunk", uniqueConstraints = {@UniqueConstraint(columnNames={"x", "y"})}, indexes = 
{@Index(columnList = "x,y")})
@Access(value = AccessType.FIELD)
public class Chunk extends HibernateComponent {

public int x;
public int y;
public Date createdOn;

@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
@OneToMany(fetch = FetchType.EAGER)
@Fetch(FetchMode.JOIN)
@BatchSize(size = 50)
public Set<Identity> inChunk = new LinkedHashSet<>();

@Transient
public Set<ChunkLoader> loadedBy = new LinkedHashSet<>();

public Chunk() {}
public Chunk(int x, int y, Date createdOn) {
    this.x = x;
    this.y = y;
    this.createdOn = createdOn;
}
}





@Entity
@Table(name = "identity")
@Access(AccessType.FIELD)
@SQLInsert(sql = "insert into identity(tag, typeID, id) values(?,?,?) ON DUPLICATE KEY UPDATE id = 
VALUES(id), tag = values(tag), typeID = values(typeID);")
@SelectBeforeUpdate(value = false)
public class Identity extends Component {

@Id
public long id;
public String tag;
public short typeID;

public Identity() {}
public Identity(long id, String tag, short typeID) { this.id = id;this.tag = tag;this.typeID = 
typeID; }
}

当前生成的简单父更新语句的休眠查询如下:

select childs
update childs
update parent

我的注释出了什么问题?为什么会发生这些选择,我该如何防止呢?

0 个答案:

没有答案