@AdminTx
public void processSite(Site site) {
FluxBoutiqueMapping mapping = mapper.generateMappingFromUrl(site);
Boutique boutique;
for (FluxBoutiqueMapping.Boutique fluxBoutique : mapping.getListe().getBoutiques()) {
log.error("Dans la boucle");
boutique = daoAdmin.namedQuerySingle(Boutique.LOAD_BOUTIQUE_BY_IDWEBSC, fluxBoutique.getId());
log.error("boutique : "+boutique);
if (boutique==null) {
log.error("Dans le new");
boutique = new Boutique();
}
boutique.setSite(site);
boutique.setUrlLogo(fluxBoutique.getLogo());
boutique.setUrlBoutique(fluxBoutique.getUrl());
boutique.setSelected(false);
boutique.setIdWebSC(fluxBoutique.getId());
boutique.setDateModification(new Date());
boutiqueDao.persist(boutique);
boutique = null;
}
}
@Entity
@Table(name = "BOUTIQUE")
@SequenceGenerator(name = "SEQ_BOUTIQUE", sequenceName = "SEQ_BOUTIQUE")
@NamedQueries(value = {
@NamedQuery(name = Boutique.LOAD_BOUTIQUE_BY_IDWEBSC, query = "from Boutique b where b.idWebSC=?1"),
})
public class Boutique implements IPersistentObject, IPubliable<Manifestation> {
/**
*
*/
private static final long serialVersionUID = -3038903536445432584L;
public static final String LOAD_BOUTIQUE_BY_IDWEBSC = "load.boutique.by.idwebsc";
protected long idBoutique;
protected Site site;
protected Long idOrigine;
protected String urlLogo;
protected String urlBoutique;
protected boolean selected;
protected long idWebSC;
protected Date datePublication;
protected Date dateModification;
@Override
@Id
@GeneratedValue(generator="SEQ_BOUTIQUE")
@Column(name = "ID_BOUTIQUE", unique = true, nullable = false, precision = 8, scale = 0)
public Long getId() {
return this.idBoutique;
}
public void setId(Long idBoutique) {
this.idBoutique = idBoutique;
}
@Override
public void setIdOrigine(Long idOrigine) {
this.idOrigine = idOrigine;
}
@Override
@Column(name = "IDORIGINE", length = 7)
public Long getIdOrigine() {
return this.idOrigine;
}
@Override
@Temporal(TemporalType.DATE)
@Column(name = "DATE_PUBLICATION", length = 7)
public Date getDatePublication() {
return datePublication;
}
@Override
public void setDatePublication(Date datePublication) {
this.datePublication = datePublication;
}
@Override
@Temporal(TemporalType.DATE)
@Column(name = "DATE_MODIFICATION", length = 7)
public Date getDateModification() {
return dateModification;
}
public void setDateModification(Date dateModification) {
this.dateModification = dateModification;
}
@Override
public void update(Manifestation newer) {
// TODO Auto-generated method stub
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ID_SITE")
@ForeignKey(name = "FK_BOUTIQUE_SITE")
public Site getSite() {
return site;
}
public void setSite(Site site) {
this.site = site;
}
@Column(name = "URL_LOGO", length = 255)
public String getUrlLogo() {
return urlLogo;
}
public void setUrlLogo(String urlLogo) {
this.urlLogo = urlLogo;
}
@Column(name = "URL_BOUTIQUE", length = 255)
public String getUrlBoutique() {
return urlBoutique;
}
public void setUrlBoutique(String urlBoutique) {
this.urlBoutique = urlBoutique;
}
@Column(name = "SELECTED")
public boolean isSelected() {
return selected;
}
public void setSelected(boolean selected) {
this.selected = selected;
}
@Column(name = "ID_WEBSC", length = 7)
public long getIdWebSC() {
return idWebSC;
}
public void setIdWebSC(long idWebSC) {
this.idWebSC = idWebSC;
}
}
javax.persistence.PersistenceException: org.hibernate.PersistentObjectException: detached entity passed to persist: fr.u2m.viparis.business.Boutique
at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:219)
at fr.u2m.dao.jpa.GenericDaoJPAImpl.persist(GenericDaoJPAImpl.java:60)
at fr.u2m.viparis.service.impl.BoutiqueService.processSite(BoutiqueService.java:81)
at fr.u2m.viparis.service.impl.BoutiqueService.processAllFluxBoutique(BoutiqueService.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
at $Proxy136.processAllFluxBoutique(Unknown Source)
at fr.u2m.viparis.fluxboutique.action.FluxBoutiqueAction.loadFlux(FluxBoutiqueAction.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
at org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
at fr.u2m.struts.OpenViewRequestProcessor.processJpaActionPerform(OpenViewRequestProcessor.java:270)
at fr.u2m.struts.OpenViewRequestProcessor.processActionPerform(OpenViewRequestProcessor.java:115)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
at fr.u2m.struts.OpenViewRequestProcessor.process(OpenViewRequestProcessor.java:230)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at fr.u2m.viparis.cms.filter.MultiTabSessionFilter.doFilter(MultiTabSessionFilter.java:75)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at fr.u2m.viparis.cms.filter.MonitoringFilter.doFilter(MonitoringFilter.java:54)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at fr.u2m.viparis.cms.util.auditing.AuditingFilter.doFilter(AuditingFilter.java:44)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at fr.u2m.util.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:71)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:200)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: org.hibernate.PersistentObjectException: detached entity passed to persist: fr.u2m.viparis.business.Boutique
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:79)
at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
at org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:213)
... 65 more
我在Tomcat 7.0.32服务器上运行Java7.0.11。
你知道吗?
persist
用于全新的临时对象,如果id已经分配,它将失败。您可能应该调用saveorupdate
而不是persist
。
或者,您可以检查对象是否已经包含在实体管理器中,如果是,则执行
entityManager.merge(yourObject);
,否则
entityManager.persist(yourObject);
我有如下雇员类 当我调用来persisting时,我会得到以下错误
我在spring boot尝试用hibernate进行多对一的单向映射。我有以下几个学生班--很多 大学-一个班级 应用程序另存和运行为 但我的原因是:org.hibernate.PersistentObjectException:传递给Persisted的分离实体:jpa.many.to.oniredirectoral.model.university(位于org.hibernate.event
请告诉我如何解决这个问题。更多信息请评论
JPA和Hibernate的新手,所以请耐心等待,因为我试图绘制一整张图片。所以我有两个具有双向关系的Java对象。员工类是拥有类,部门类是关系的反面。一个部门可以有许多员工,一个员工只能有一个部门。我分配了employee_id作为员工实体的主键,department_id作为部门实体的主键。我还想在员工类中使用department_id作为外键。 员工类 部门类 我用来生成两个对象并将它们保存
我是Hibernate的新手,我需要帮助。 我有一个名为Kasa的表,它有3个属性-id、address和account\u id。在我的表中有12行。我想使用Hibernate对此进行映射,并使用Java添加新的映射,所以我这样做了: 我也有能手和二传手,但不需要复制。 现在我想在我的数据库中添加新行,如下所示: 我得到这样的错误:javax.persistence.PeristenceExce
我有两个模型,一个用于存储用户详细信息,使用该Id,我试图将用户位置保存在另一个表中,该表使用用户的相同Id作为主键。 为什么我会出现这个错误?坚持是什么意思?我正在使用MySQL数据库(&I)