I have next relations:
@Entity
@Table(name = "STOCK", uniqueConstraints = @UniqueConstraint(columnNames = { "CODE", "INTERVAL", "DATE" }) )
public class StockEntity {
.....
many other fields like collections
.....
@ElementCollection
@CollectionTable(name = "PARAMETERS", joinColumns = @JoinColumn(name="SETTING_ID"))
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
@MapKeyEnumerated(EnumType.STRING)
private Map<LocalSetting.SettingType, LocalSetting> parameters = new HashMap<>();
}
@Entity
@Table(name = "LOCAL_SETTING")
@Inheritance(strategy = InheritanceType.TABLE_PER_CLASS)
public class LocalSetting {
@Id
@Column(name = "SETTING_ID", unique = true, nullable = false)
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long settingId;
.....
}
when I use my DAO:
@Override
public void updateStocks(List<StockEntity> stocks) {
Session session = sessionFactory.getCurrentSession();
stocks.forEach(stock -> {
session.update(stock);
session.flush();
session.clear();
});
}
in log trace i notice that will be updated all fields in StockEntity, when I was changing only "parameters", it mean i also was updating lot of other parameters which i could simply skip
when I try to update only "parameters" using next code:
@Override
public void updateParameters(List<StockEntity> stocks) {
stocks.forEach(stock -> {
for (Map.Entry<LocalSetting.SettingType, LocalSetting> entry : stock.getParameters().entrySet()) {
sessionFactory.getCurrentSession().saveOrUpdate(entry.getValue());
}
});
}
but process will be same like i will update whole StockEntity ,maybe I can detach another fields until I will finish update "parameters"