[英]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.