[英]update of entity with hibernate entity manager
我有一個實施方案,其中我的實體Company
擴展RootEntity
與
strategy =InheritanceType.JOINED.(I am using hibernate-entitymanager)
我還有其他不擴展RootEntity
實體。 當我創建所有實體時,它確實會創建。但是當我嘗試更新RootEntity
的擴展實體時,它不會更新。 但是非擴展實體正在更新。 更新代碼在GenericDaoImpl
因此它是相同的更新方法。
可能是什么問題? 我的代碼是:
@Transactional(value="tx")
public E update(E entity) {
E merged = null;
RootEntity baseEntity = null;
if(entity instanceof RootEntity ){
baseEntity = (RootEntity)entity;
merged = entityManager.find(entityClass, baseEntity.getId());
}
merged = entityManager.merge(entity);
entityManager.flush();
return merged;
}
我要合並的對象:
public class Societa extends RootEntity implements Serializable{
private static final long serialVersionUID = 1L;
// ASSOCIAZIONE CAMPI DB VARIABILI NELLA CLASSE
@Column(name="nomeSocieta",nullable = false,columnDefinition="CHAR(80)")
private String nomeSocieta;
......
}
而我的RootEntity是:
@Entity
@Inheritance(strategy =InheritanceType.JOINED)
public class RootEntity {
private static final long serialVersionUID = 1L;
@Id
@Column(name="id",nullable = false)
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
...getters/setters..
}
Newaz,我需要查看您的RootEntity
和Company
實體。
另外,我雖然很難理解您提供的代碼-
entityManager.flush();
您不必執行此操作,如果我理解正確,則使用的是Spring,並且@Transactional
在調用方法完成后會自動關閉/刷新事務。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.