[英]update of entity with hibernate entity manager
I have one implementation where my entity Company
extends RootEntity
with 我有一个实施方案,其中我的实体
Company
扩展RootEntity
与
strategy =InheritanceType.JOINED.(I am using hibernate-entitymanager)
I have other entities which does not extends RootEntity
. 我还有其他不扩展
RootEntity
实体。 When I create all entites it does create.But when I try to update an extended entity of RootEntity
,it does not update. 当我创建所有实体时,它确实会创建。但是当我尝试更新
RootEntity
的扩展实体时,它不会更新。 But the non extending entity is updating. 但是非扩展实体正在更新。 The update code is in
GenericDaoImpl
so it is the same update method. 更新代码在
GenericDaoImpl
因此它是相同的更新方法。
what can be the problem? 可能是什么问题? my code is:
我的代码是:
@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;
}
My Object That I am trying to merge: 我要合并的对象:
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;
......
}
and my RootEntity is: 而我的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, I need to see your RootEntity
and Company
entity. Newaz,我需要查看您的
RootEntity
和Company
实体。
Also, I was having hard time understanding your provided code though - 另外,我虽然很难理解您提供的代码-
entityManager.flush();
you don't have to do this, if i understand correctly, you are using spring and @Transactional
automatically closes/flushes transaction when invoked method is finished. @Transactional
在调用方法完成后会自动关闭/刷新事务。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.