- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用的是 spring 4.0.5 和 hibernate 4.3.5;我在使用 hibernate 时遇到错误,我无法弄清楚我错在哪里(因为我确定我错了)。我有一个与自身相关的表,它代表一个网络树,其中每个根节点可以有多个子节点,所以我创建了这个类:
@DynamicUpdate
@Cache(region = "it.eng.angelo.spring.dao.hibernate.models.WebTree", usage = CacheConcurrencyStrategy.READ_WRITE)
@Entity
@Table(name = "MEDIA_GALL_TREE", indexes = {@Index(name = "NOME_FOLDER_IDX", columnList = "NOME_FOLDER")})
public class WebTree extends AbstractModel
{
private static final long serialVersionUID = -4572195412018767502L;
private long id;
private String text;
private boolean opened;
private boolean disabled;
private boolean selected;
private Set<WebTree> children = new HashSet<WebTree>(0);
private Set<Media> media = new HashSet<Media>(0);
private WebTree father;
private WcmDomain dominio;
public WebTree()
{
super();
}
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "ID_FOLDER", unique = true, nullable = false)
public long getId()
{
return id;
}
public void setId(long id)
{
this.id = id;
}
@Column(name = "NOME_FOLDER", nullable = false, unique=false)
public String getText()
{
return text;
}
public void setText(String text)
{
this.text = text;
}
@Column(name = "OPENED_FOLDER")
public boolean isOpened()
{
return opened;
}
public void setOpened(boolean opened)
{
this.opened = opened;
}
@Column(name = "DISABLED_FOLDER")
public boolean isDisabled()
{
return disabled;
}
public void setDisabled(boolean disabled)
{
this.disabled = disabled;
}
@Column(name = "SELECTED_FOLDER")
public boolean isSelected()
{
return selected;
}
public void setSelected(boolean selected)
{
this.selected = selected;
}
@OneToMany(mappedBy = "father", orphanRemoval = true, targetEntity = WebTree.class)
public Set<WebTree> getChildren()
{
return children;
}
public void setChildren(Set<WebTree> children)
{
this.children = children;
}
@ManyToOne(targetEntity = WebTree.class)
@JoinColumn(name = "ID_PADRE", nullable = true)
public WebTree getFather()
{
return father;
}
public void setFather(WebTree father)
{
this.father = father;
}
@OneToOne
@JoinColumn(name="ID_DOMINIO", nullable=false)
public WcmDomain getDominio()
{
return dominio;
}
public void setDominio(WcmDomain dominio)
{
this.dominio = dominio;
}
@OneToMany( mappedBy = "folder", orphanRemoval = true, targetEntity = Media.class, cascade = { CascadeType.ALL })
public Set<Media> getMedia()
{
return media;
}
public void setMedia(Set<Media> media)
{
this.media = media;
}
}
@Test
public void testLoadModifyTree()
{
try
{
DetachedCriteria dc = DetachedCriteria.forClass(MediaGalleryTree.class);
dc.setFetchMode("father", FetchMode.JOIN);
dc.add(Property.forName("id").eq(4l));
List<MediaGalleryTree> result = hibSvc.search(dc, IConstants.NO_PAGINATION, IConstants.NO_PAGINATION);
for (MediaGalleryTree mediaGalleryTree : result)
{
logger.info(mediaGalleryTree.getId());
}
}
catch (Exception e)
{
logger.error(e.getMessage(), e);
}
}
18:48:43,123 ERROR [WcmHibernateDao] Errore nella ricerca con detached criteria DetachableCriteria(CriteriaImpl(it.eng.comi.spring.dao.hibernate.models.MediaGalleryTree:this[][id=4])); More than one row with the given identifier was found: 2, for class: it.eng.comi.spring.dao.hibernate.models.MediaGalleryTree
org.hibernate.HibernateException: More than one row with the given identifier was found: 2, for class: it.eng.comi.spring.dao.hibernate.models.MediaGalleryTree
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:100)
at org.hibernate.loader.entity.EntityLoader.loadByUniqueKey(EntityLoader.java:161)
at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:2385)
at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:767)
at org.hibernate.type.EntityType.resolve(EntityType.java:505)
at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:170)
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:144)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1114)
at org.hibernate.loader.Loader.processResultSet(Loader.java:972)
at org.hibernate.loader.Loader.doQuery(Loader.java:920)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
at org.hibernate.loader.Loader.doList(Loader.java:2553)
at org.hibernate.loader.Loader.doList(Loader.java:2539)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2369)
at org.hibernate.loader.Loader.list(Loader.java:2364)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:126)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1682)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:380)
at it.eng.comi.spring.dao.WcmHibernateDao.searchEntity(WcmHibernateDao.java:140)
at it.eng.comi.spring.service.impl.WcmRdbmsExtSvcImpl.search(WcmRdbmsExtSvcImpl.java:237)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy45.search(Unknown Source)
at it.eng.comi.test.ComiTests.testLoadModifyTree(ComiTests.java:578)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
18:48:43,135 ERROR [WcmRdbmsExtSvcImpl] Errore nella ricerca con deatchedCriteria DetachableCriteria(CriteriaImpl(it.eng.comi.spring.dao.hibernate.models.MediaGalleryTree:this[][id=4])); Errore nella ricerca con detached criteria DetachableCriteria(CriteriaImpl(it.eng.comi.spring.dao.hibernate.models.MediaGalleryTree:this[][id=4])); More than one row with the given identifier was found: 2, for class: it.eng.comi.spring.dao.hibernate.models.MediaGalleryTree
it.eng.comi.exception.CoMiDbException: Errore nella ricerca con detached criteria DetachableCriteria(CriteriaImpl(it.eng.comi.spring.dao.hibernate.models.MediaGalleryTree:this[][id=4])); More than one row with the given identifier was found: 2, for class: it.eng.comi.spring.dao.hibernate.models.MediaGalleryTree
at it.eng.comi.spring.dao.WcmHibernateDao.searchEntity(WcmHibernateDao.java:146)
at it.eng.comi.spring.service.impl.WcmRdbmsExtSvcImpl.search(WcmRdbmsExtSvcImpl.java:237)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:98)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:262)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:95)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
at com.sun.proxy.$Proxy45.search(Unknown Source)
at it.eng.comi.test.ComiTests.testLoadModifyTree(ComiTests.java:578)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:233)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:87)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:176)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.HibernateException: More than one row with the given identifier was found: 2, for class: it.eng.comi.spring.dao.hibernate.models.MediaGalleryTree
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:100)
at org.hibernate.loader.entity.EntityLoader.loadByUniqueKey(EntityLoader.java:161)
at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:2385)
at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:767)
at org.hibernate.type.EntityType.resolve(EntityType.java:505)
at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:170)
at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:144)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1114)
at org.hibernate.loader.Loader.processResultSet(Loader.java:972)
at org.hibernate.loader.Loader.doQuery(Loader.java:920)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:354)
at org.hibernate.loader.Loader.doList(Loader.java:2553)
at org.hibernate.loader.Loader.doList(Loader.java:2539)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2369)
at org.hibernate.loader.Loader.list(Loader.java:2364)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:126)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1682)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:380)
at it.eng.comi.spring.dao.WcmHibernateDao.searchEntity(WcmHibernateDao.java:140)
... 43 more
Hibernate:
select
this_.ID_FOLDER as ID_FOLDE1_7_2_,
this_.UT_INS as UT_INS2_7_2_,
this_.DT_INS as DT_INS3_7_2_,
this_.DT_UPD as DT_UPD4_7_2_,
this_.UT_UPD as UT_UPD5_7_2_,
this_.DISABLED_FOLDER as DISABLED6_7_2_,
this_.ID_DOMINIO as ID_DOMI10_7_2_,
this_.ID_PADRE as ID_PADR11_7_2_,
this_.OPENED_FOLDER as OPENED_F7_7_2_,
this_.SELECTED_FOLDER as SELECTED8_7_2_,
this_.NOME_FOLDER as NOME_FOL9_7_2_,
wcmdomain2_.ID_DOMINIO as ID_DOMIN1_8_0_,
wcmdomain2_.UT_INS as UT_INS2_8_0_,
wcmdomain2_.DT_INS as DT_INS3_8_0_,
wcmdomain2_.DT_UPD as DT_UPD4_8_0_,
wcmdomain2_.UT_UPD as UT_UPD5_8_0_,
wcmdomain2_.WCM_NOME_DOMINIO as WCM_NOME6_8_0_,
mediagalle3_.ID_FOLDER as ID_FOLDE1_7_1_,
mediagalle3_.UT_INS as UT_INS2_7_1_,
mediagalle3_.DT_INS as DT_INS3_7_1_,
mediagalle3_.DT_UPD as DT_UPD4_7_1_,
mediagalle3_.UT_UPD as UT_UPD5_7_1_,
mediagalle3_.DISABLED_FOLDER as DISABLED6_7_1_,
mediagalle3_.ID_DOMINIO as ID_DOMI10_7_1_,
mediagalle3_.ID_PADRE as ID_PADR11_7_1_,
mediagalle3_.OPENED_FOLDER as OPENED_F7_7_1_,
mediagalle3_.SELECTED_FOLDER as SELECTED8_7_1_,
mediagalle3_.NOME_FOLDER as NOME_FOL9_7_1_
from
MEDIA_GALL_TREE this_
inner join
WCM_DOMAIN wcmdomain2_
on this_.ID_DOMINIO=wcmdomain2_.ID_DOMINIO
left outer join
MEDIA_GALL_TREE mediagalle3_
on this_.ID_PADRE=mediagalle3_.ID_FOLDER
where
this_.ID_FOLDER=?
Hibernate:
select
mediagalle0_.ID_FOLDER as ID_FOLDE1_7_2_,
mediagalle0_.UT_INS as UT_INS2_7_2_,
mediagalle0_.DT_INS as DT_INS3_7_2_,
mediagalle0_.DT_UPD as DT_UPD4_7_2_,
mediagalle0_.UT_UPD as UT_UPD5_7_2_,
mediagalle0_.DISABLED_FOLDER as DISABLED6_7_2_,
mediagalle0_.ID_DOMINIO as ID_DOMI10_7_2_,
mediagalle0_.ID_PADRE as ID_PADR11_7_2_,
mediagalle0_.OPENED_FOLDER as OPENED_F7_7_2_,
mediagalle0_.SELECTED_FOLDER as SELECTED8_7_2_,
mediagalle0_.NOME_FOLDER as NOME_FOL9_7_2_,
wcmdomain1_.ID_DOMINIO as ID_DOMIN1_8_0_,
wcmdomain1_.UT_INS as UT_INS2_8_0_,
wcmdomain1_.DT_INS as DT_INS3_8_0_,
wcmdomain1_.DT_UPD as DT_UPD4_8_0_,
wcmdomain1_.UT_UPD as UT_UPD5_8_0_,
wcmdomain1_.WCM_NOME_DOMINIO as WCM_NOME6_8_0_,
mediagalle2_.ID_FOLDER as ID_FOLDE1_7_1_,
mediagalle2_.UT_INS as UT_INS2_7_1_,
mediagalle2_.DT_INS as DT_INS3_7_1_,
mediagalle2_.DT_UPD as DT_UPD4_7_1_,
mediagalle2_.UT_UPD as UT_UPD5_7_1_,
mediagalle2_.DISABLED_FOLDER as DISABLED6_7_1_,
mediagalle2_.ID_DOMINIO as ID_DOMI10_7_1_,
mediagalle2_.ID_PADRE as ID_PADR11_7_1_,
mediagalle2_.OPENED_FOLDER as OPENED_F7_7_1_,
mediagalle2_.SELECTED_FOLDER as SELECTED8_7_1_,
mediagalle2_.NOME_FOLDER as NOME_FOL9_7_1_
from
MEDIA_GALL_TREE mediagalle0_
inner join
WCM_DOMAIN wcmdomain1_
on mediagalle0_.ID_DOMINIO=wcmdomain1_.ID_DOMINIO
left outer join
MEDIA_GALL_TREE mediagalle2_
on mediagalle0_.ID_PADRE=mediagalle2_.ID_FOLDER
where
mediagalle0_.ID_DOMINIO=?
id_folder; ut_ins; dt_ins; dt_upd; ut_upd; disabled_folder; opened_folder; selected_folder; nome_folder; id_dominio; id_padre
"1";"system";"2014-06-12 18:23:16.649";"2014-06-12 18:23:16.649";"system";FALSE;FALSE;FALSE;"Root 1";1;
"2";"system";"2014-06-12 18:23:16.662";"2014-06-12 18:23:16.662";"system";FALSE;FALSE;FALSE;"Root 2";2;
"4";"wpsAdmin";"2014-06-13 16:18:01.428";"2014-06-13 18:12:14.228";"wpsAdmin";FALSE;FALSE;FALSE;"Testina";2;2
"7";"wpsAdmin";"2014-06-13 17:33:05.575";"2014-06-13 17:33:10.275";"wpsAdmin";FALSE;FALSE;FALSE;"Angelo";2;2
@OneToMany( mappedBy = "father", targetEntity = WebTree.class, fetch=FetchType.EAGER)
public Set<WebTree> getChildren()
{
return children;
}
最佳答案
我被 org.hibernate.HibernateException: More than one row with the given identifier was found:
咬了问题,在 StackOverflow 上没有找到任何帮助。解决这个问题花了一段时间,所以我在这里记录了解决方案。我正在使用 JPA/Hibernate 和 Spring Data。
首先,这不是由数据库中的重复行引起的,因为显然不可能有重复的主键。相反,这是由 Hibernate 查找对象并急切地用 LEFT OUTER JOIN 填充一对一关系引起的。 Hibernate 假设单行会返回,但有两行会返回,因为有两个对象与一对一关系相关联。
这是我的对象的简化版本:
@Entity
@Table(name = "plate")
public class Plate {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name="test_seq", sequenceName="test_seq")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "test_seq")
@Column(name = "id")
private Long id;
@Version
@Column(name = "object_version")
private long objectVersion;
@Column(name = "name")
private String name;
@OneToOne(mappedBy = "plate")
private Sheet sheet;
public Sheet getSheet() {
return sheet;
}
public void setSheet(Sheet sheet) {
if (this.sheet != null) {
this.sheet.setPlate(null);
}
this.sheet = sheet;
sheet.setPlate(this);
}
}
@Entity
@Table(name = "sheet")
public class Sheet {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name="test_seq", sequenceName="test_seq")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "test_seq")
@Column(name = "id")
private Long id;
@Version
@Column(name = "object_version")
private long objectVersion;
@Column(name = "sheet_name")
private String sheetName;
@OneToOne
@JoinColumn(name = "plate_id")
private Plate plate;
public Plate getPlate() {
return plate;
}
// Do not use. Use Plate.setSheet() instead
void setPlate(Plate plate) {
this.plate = plate;
}
}
select
plate1_.id as id1_19_12_,
plate1_.object_version as object_v2_19_12_,
plate1_.name as name3_19_12_,
sheet2_.id as id1_39_12_,
sheet2_.object_version as object_v2_39_12_,
sheet2_.sheet_name as sheet_nam2_39_12_,
sheet2_.plate_id as plate_id4_39_12_,
from
plate plate1_
left outer join sheet sheet2_ on plate1_.id = sheet2_.plate_id
where
plate1_.id=?
org.hibernate.HibernateException: More than one row with the given identifier was found: 10045, for class: com.example.Plate
@OneToOne(mappedBy = "plate", cascade = CascadeType.ALL, orphanRemoval = true)
private Sheet sheet;
关于 hibernate :发现具有给定标识符的多于一行错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24210478/
我想要以下代码的 Python 单行解决方案,但是怎么做呢? total = 0 for ob in self.oblist: total += sum(v.amount for v in o
今天和大家一起学习一种可视化技术:构建树状热力图treemap。树形图易于可视化,且易于被人理解。树状图通过展示不同大小的矩形,以传达不同大小的数据量,一般认为,较大的矩形意味着占总体的一大部分,而较
就目前而言,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the he
我有一个声明 $set eq "Y" ? $set = "N" : $set = "Y"; 但不管它总是设置为 "N" # Toggle setting if ($set eq "Y") { $
当我尝试在我的服务器上上传一个 php 文件时,我收到一条消息:"Parse error: ..." 我知道这是什么意思,但问题是别的。 如果我在本地服务器上编辑文件(我的计算机上安装了 XAMPP)
我是 python oneliner 循环的新手。 我希望用户将数据输入到二维列表中,同时提醒他他们将输入的数据索引。我的代码是: flag=0 x=[[int(input("enter the "+
尝试在变量之前和之后打印字符串。C 是否有能力使用一条语句来显示此输出? 这有效: float value = 5; printf("\nThe value of %f", value); print
我正在验证我创建的 MySQL 数据库的结果,为此,我需要一些屏幕截图。 例如,以下查询: select distinct run_ID from ngsRunStats_FK.failedRuns
有人可以解释一下这个 JS LINE 吗?数据是一个对象。 var list = data == null ? [] : (data.wine instanceof Array ? data.wine
如何在一行中添加三个下拉菜单。我想把我的日、月和年放在一行中,但不能这样做。任何帮助将不胜感激。我附上我的 jsfiddle . .... 最佳
我正在尝试使用 html 将 iframe 的高度设置为 100%(我已成功完成),但我还在顶部添加了一行额外的文本,所以它太高了 ~16px(这需要一个滚动条)。有没有办法更改 iframe 以显示
这是一个示例,我从文件中读取行作为字符串,以使整个文件作为字符串数组: String[] ArrayOfStrings = (new Scanner( new File("log.txt") ).us
我有一个包含大量定义的配置文件,用于在编译期间包含模块。此外,这意味着我必须经常检查代码内部的定义。每张支票需要 3 行,是否可以在一行中执行此操作。 #if FUNC_ENABLED functio
我正在尝试制作一个水平列表,其中每个 列表中的 s 的高度为 385px,宽度为 400px。 我尝试使用 inline-block 使列表水平排列,但这似乎不起作用。也就是说,我的意思是列表仍然是垂
这很烦人,我有一个带有 css 文件的 wordpress 主题,所有内容都在一长行中。我想知道为什么有人会那样做。现在我已经升级了,我需要将旧文件与新文件进行比较,以便我可以接受更改。 Meld、d
我有一个对象数组,其中每个对象都有一个 search_order 属性。我要检查数组并将所有对象的属性增加 1这是简单的方法: res = [] for r in array: r.searc
我在某些服务器上遇到许多具有相同内容和相同名称的文件。我需要隔离这些文件进行分析,所以我不能只删除重复项。操作系统为Linux(centos和ubuntu)。 我枚举文件名和位置并将它们放入文本文件中
你能在不抛出错误的情况下解决这个问题吗?答案是单线。这是来自一个死的职位发布,在回复中要求回答。我认为这是剔除受访者的聪明方法,但我似乎无法在不出错的情况下回答它。 显而易见的解决方案: f.moo(
这个问题在这里已经有了答案: Is it ok if I omit curly braces in Java? [closed] (16 个答案) 关闭 9 年前。 我在 java 中使用没有大括号
我在这里试图用 python 制作一个简单的计算器,我想知道是否可以在命令运行时将前 3 行合并为一行。我的意思是;我不必按 Enter 键来键入下一个数字/运算符,而是按空格键(在输入部分)。 wh
我是一名优秀的程序员,十分优秀!