Home » Modeling » EMF » [Teneo] Delete orphans in non-contaiment references
|
Re: [Teneo] Delete orphans in non-contaiment references [message #649276 is a reply to message #649204] |
Tue, 18 January 2011 14:36 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Fernando,
I would say that the cascade setting ALL will also result in delete-orphan (looking at the code). You can debug into the
AbstractMapper.addCascades method to see what happens.
There is also a cascade:DELETE_ORPHAN which can be used the same as PERSIST and the others.
Delete-orphan only works for many associations. There are configuration options to set a default cascade for containment
as non-containment:
http://wiki.eclipse.org/Teneo/Hibernate/Configuration_Option s
teneo.mapping.cascade_policy_on_containment
teneo.mapping.cascade_policy_on_non_containment
gr. Martin
PS, sorry I have not had time yet to look at the example you sent...
On 01/18/2011 09:21 AM, Fer wrote:
> Hello all,
>
> I am trying to delete orphans in non-containment references with Teneo 1.1.2 and Hibernate 3.6 but no work. The
> containment references are mapped as cascade="all, delete-orphan" by Teneo but the non-containment references are mapped
> as cascade="merge, refresh,.." (without delete-orphan) .
> I have tried using teneo.jpa annotations and teneo.hibernate annotations extensions (in my ecore) but only get a
> cascade="all" in hibernate mapping.
>
> Is there any way to set the cascade="all, delete-orphan" in non-containment references? Am I doing something wrong with
> annotations?
>
> Thanks in advance.
>
> Best Regards,
>
> Fernando
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
Re: [Teneo] Delete orphans in non-contaiment references [message #649450 is a reply to message #649276] |
Wed, 19 January 2011 09:34 |
Fer Missing name Messages: 24 Registered: September 2009 |
Junior Member |
|
|
Hi Martin,
Thanks for your response. I have trying to set the following:
props.setProperty(PersistenceOptions.CASCADE_POLICY_ON_CONTAINMENT, "ALL");
props.setProperty(PersistenceOptions.CASCADE_POLICY_ON_NON_CONTAINMENT, "PERSIST, REFRESH, MERGE, DELETE_ORPHAN");
The cascade="all, delete_orphan" is generated correctly in many associations but in many-to-one association the delete_orphan is omitted.
Here you can see part of the hibernate mapping generated:
<many-to-one name="interfaceEnd1" entity-name="InterfaceEndUsage" cascade="merge,persist,save-update,lock,refresh" lazy="proxy" insert="true" update="true" not-null="false">
<column not-null="false" unique="false" name="`interfaceendusage_interfaceend1_unique_identifier`"/>
</many-to-one>
<list name="usages" lazy="false" cascade="all,delete-orphan">
<key update="true">
<column name="`interfaceusage_usages_unique_identifier`" not-null="false" unique="false"/>
</key>
<list-index column="`interfaceusage_usages_idx`"/>
<one-to-many entity-name="InterfaceUsage"/>
</list>
The DELETE_ORPHAN in non-containment reference is omitted, I think that the problem is in AbstractAssociationMapper.convertCascade because the DELETE_ORPHAN option no exits!
protected List<HbCascadeType> convertCascade(List<CascadeType> cascades) {
final List<HbCascadeType> res = new ArrayList<HbCascadeType>();
for (CascadeType ct : cascades) {
if (ct == CascadeType.ALL) {
res.add(HbCascadeType.ALL);
} else if (ct == CascadeType.MERGE) {
res.add(HbCascadeType.MERGE);
} else if (ct == CascadeType.PERSIST) {
res.add(HbCascadeType.PERSIST);
res.add(HbCascadeType.SAVE_UPDATE);
res.add(HbCascadeType.LOCK);
} else if (ct == CascadeType.REFRESH) {
res.add(HbCascadeType.REFRESH);
} else if (ct == CascadeType.REMOVE) {
res.add(HbCascadeType.REMOVE);
} else if (ct == CascadeType.NONE) {
return new ArrayList<HbCascadeType>();
}
}
return res;
}
Furthermore, for onetoone/manytoone associations the delete-orphan option is no supported. Then , How I can do cascading deletes in many-to-one associations?
/**
* Creates cascades for onetoone/manytoone, they differ from many relations
* because no delete-orphan is supported.
*/
protected void addCascadesForSingle(Element associationElement,
List<HbCascadeType> cascades) {
addCascades(associationElement, cascades, false);
}
Best Regards,
Fernando
P.S: Do not worry, I look forward to your response.
|
|
|
Re: [Teneo] Delete orphans in non-contaiment references [message #649795 is a reply to message #649450] |
Thu, 20 January 2011 15:38 |
Martin Taal Messages: 5468 Registered: July 2009 |
Senior Member |
|
|
Hi Fernando,
Hibernate does not support delete-orphan for many-to-one, it is fairly uncommon I guess.
Sorry for the advice below, to get delete orphan on a non-containment association you need to set an eannotation in your
model, for example:
@Cascade(value={PERSIST, REMOVE, DELETE_ORPHAN})
this will set delete orphan for that association.
I will add the possibility to do this through an option. I also seen other examples where people modeled a containment
association as non-containment for their own reasons and this can be usefull. I will reply again to this post when this
is available.
gr. Martin
On 01/19/2011 10:34 AM, Fer wrote:
> Hi Martin,
>
> Thanks for your response. I have trying to set the following:
>
>
> props.setProperty(PersistenceOptions.CASCADE_POLICY_ON_CONTA INMENT, "ALL");
> props.setProperty(PersistenceOptions.CASCADE_POLICY_ON_NON_C ONTAINMENT, "PERSIST, REFRESH, MERGE, DELETE_ORPHAN");
>
>
> The cascade="all, delete_orphan" is generated correctly in many associations but in many-to-one association the
> delete_orphan is omitted.
>
> Here you can see part of the hibernate mapping generated:
>
> <many-to-one name="interfaceEnd1" entity-name="InterfaceEndUsage" cascade="merge,persist,save-update,lock,refresh"
> lazy="proxy" insert="true" update="true" not-null="false">
> <column not-null="false" unique="false" name="`interfaceendusage_interfaceend1_unique_identifier`"/ >
> </many-to-one>
> <list name="usages" lazy="false" cascade="all,delete-orphan">
> <key update="true">
> <column name="`interfaceusage_usages_unique_identifier`" not-null="false" unique="false"/>
> </key>
> <list-index column="`interfaceusage_usages_idx`"/>
> <one-to-many entity-name="InterfaceUsage"/>
> </list>
>
>
> The DELETE_ORPHAN in non-containment reference is omitted, I think that the problem is in
> AbstractAssociationMapper.convertCascade because the DELETE_ORPHAN option no exits!
>
> protected List<HbCascadeType> convertCascade(List<CascadeType> cascades) {
> final List<HbCascadeType> res = new ArrayList<HbCascadeType>();
> for (CascadeType ct : cascades) {
> if (ct == CascadeType.ALL) {
> res.add(HbCascadeType.ALL);
> } else if (ct == CascadeType.MERGE) {
> res.add(HbCascadeType.MERGE);
> } else if (ct == CascadeType.PERSIST) {
> res.add(HbCascadeType.PERSIST);
> res.add(HbCascadeType.SAVE_UPDATE);
> res.add(HbCascadeType.LOCK);
> } else if (ct == CascadeType.REFRESH) {
> res.add(HbCascadeType.REFRESH);
> } else if (ct == CascadeType.REMOVE) {
> res.add(HbCascadeType.REMOVE);
> } else if (ct == CascadeType.NONE) {
> return new ArrayList<HbCascadeType>();
> }
> }
> return res;
> }
>
>
> Furthermore, for onetoone/manytoone associations the delete-orphan option is no supported. Then , How I can do cascading
> deletes in many-to-one associations?
>
>
> /**
> * Creates cascades for onetoone/manytoone, they differ from many relations
> * because no delete-orphan is supported.
> */
> protected void addCascadesForSingle(Element associationElement,
> List<HbCascadeType> cascades) {
> addCascades(associationElement, cascades, false);
> }
>
>
> Best Regards,
>
> Fernando
>
> P.S: Do not worry, I look forward to your response. :)
>
--
With Regards, Martin Taal
Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@springsite.com - mtaal@elver.org
Web: www.springsite.com - www.elver.org
|
|
|
Re: [Teneo] Delete orphans in non-contaiment references [message #650718 is a reply to message #649795] |
Wed, 26 January 2011 09:05 |
Fer Missing name Messages: 24 Registered: September 2009 |
Junior Member |
|
|
Hi Martin,
Thanks for your response. I have tried the DELETE_ORPHAN option in several ways:
1. teneo.jpa -> @ManyToOne(cascade={PERSIST, REMOVE, DELETE_ORPHAN}).
Ecore:
Quote: | <eClassifiers xsi:type="ecore:EClass" name="InterfaceUsage">
<eStructuralFeatures xsi:type="ecore:EReference" name="interfaceEnd1" eType="#//InterfaceEndUsage">
<eAnnotations source="teneo.jpa">
<details key="value" value="@Cascade(value={PERSIST, REMOVE, DELETE_ORPHAN})"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="interfaceEnd2" eType="#//InterfaceEndUsage">
<eAnnotations source="teneo.jpa">
<details key="value" value="@Cascade(value={PERSIST, REMOVE, DELETE_ORPHAN})"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="usages" upperBound="-1"
eType="#//InterfaceUsage" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="type" eType="#//InterfaceDefinition">
<eAnnotations source="teneo.jpa">
<details key="value" value="@Cascade(value={PERSIST, REMOVE, DELETE_ORPHAN})"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
|
I get the following error message:
Quote: | org.hibernate.InvalidMappingException: Could not parse mapping document from string XML String
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processH bmXml(Configuration.java:3951)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processH bmXmlQueue(Configuration.java:3940)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processM etadata(Configuration.java:3928)
at org.hibernate.cfg.Configuration.secondPassCompile(Configurat ion.java:1368)
at org.hibernate.cfg.Configuration.buildMappings(Configuration. java:1345)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.buildMapp ings(HbSessionDataStore.java:134)
at org.eclipse.emf.teneo.hibernate.HbDataStore.initializeDataSt ore(HbDataStore.java:316)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initializ e(HbSessionDataStore.java:91)
at es.gmv.vsd.ssrdb.common.dao.factory.impl.H2DAOFactory.create Connection(H2DAOFactory.java:72)
at es.gmv.vsd.ssrdb.common.dao.factory.impl.DAOFactory.createCo nnection(DAOFactory.java:66)
at es.gmv.vsd.ssrdb.common.dao.impl.ds.DataSetVSEEDAO.removeAll (DataSetVSEEDAO.java:456)
at es.gmv.vsd.ssrdb.common.dao.impl.ds.DataSetVSEEDAO.get(DataS etVSEEDAO.java:167)
at es.gmv.vsd.ssrdb.common.dao.impl.cm.ConfigManagementDAO.read DataSetXMI(ConfigManagementDAO.java:1913)
at es.gmv.vsd.ssrdb.cm.impl.ConfigManagementImpl.readDataSetXMI (ConfigManagementImpl.java:761)
at es.gmv.vsd.ssrdb.auditing.impl.AuditingImpl.readDataSetXMI(A uditingImpl.java:806)
at es.gmv.vsd.ssrdb.mmi.impl.ManagerImpl.executeMethod(ManagerI mpl.java:672)
at es.gmv.vsd.ssrdb.mmi.impl.ManagerImpl.run(ManagerImpl.java:1 22)
Caused by: org.hibernate.MappingException: many-to-one attribute [interfaceEnd1] does not support orphan delete as it is not unique
at org.hibernate.cfg.HbmBinder.bindManyToOne(HbmBinder.java:163 9)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder. java:2164)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder. java:2134)
at org.hibernate.cfg.HbmBinder.bindJoinedSubclass(HbmBinder.jav a:949)
at org.hibernate.cfg.HbmBinder.handleJoinedSubclass(HbmBinder.j ava:2305)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:183)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processH bmXml(Configuration.java:3948)
... 16 more
|
2. teneo.jpa -> @Cascade(value={PERSIST, REMOVE, DELETE_ORPHAN})
Ecore:
Quote: | <eClassifiers xsi:type="ecore:EClass" name="InterfaceUsage">
<eStructuralFeatures xsi:type="ecore:EReference" name="interfaceEnd1" eType="#//InterfaceEndUsage">
<eAnnotations source="teneo.jpa">
<details key="value" value="@ManyToOne(cascade={PERSIST, REMOVE, DELETE_ORPHAN})"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="interfaceEnd2" eType="#//InterfaceEndUsage">
<eAnnotations source="teneo.jpa">
<details key="value" value="@ManyToOne(cascade={PERSIST, REMOVE, DELETE_ORPHAN})"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="usages" upperBound="-1"
eType="#//InterfaceUsage" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="type" eType="#//InterfaceDefinition">
<eAnnotations source="teneo.jpa">
<details key="value" value="@ManyToOne(cascade={PERSIST, REMOVE, DELETE_ORPHAN})"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
|
I get the following error message:
Quote: | org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption: Cannot convert 'DELETE_ORPHAN' to 'CascadeType' type
at org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:50)
at org.eclipse.emf.teneo.annotations.parser.ComplexNode.convert (ComplexNode.java:109)
at org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:119)
at org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:87)
at org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:76)
at org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:68)
at org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:142)
at org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:73)
at org.eclipse.emf.teneo.hibernate.HbDataStore.mapEPackages(HbD ataStore.java:1023)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.mapModel( HbSessionDataStore.java:181)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initializ e(HbSessionDataStore.java:87)
at es.gmv.vsd.ssrdb.common.dao.factory.impl.H2DAOFactory.create Connection(H2DAOFactory.java:72)
at es.gmv.vsd.ssrdb.common.dao.factory.impl.DAOFactory.createCo nnection(DAOFactory.java:66)
at es.gmv.vsd.ssrdb.common.dao.impl.ds.DataSetVSEEDAO.removeAll (DataSetVSEEDAO.java:456)
at es.gmv.vsd.ssrdb.common.dao.impl.ds.DataSetVSEEDAO.get(DataS etVSEEDAO.java:167)
at es.gmv.vsd.ssrdb.common.dao.impl.cm.ConfigManagementDAO.read DataSetXMI(ConfigManagementDAO.java:1913)
at es.gmv.vsd.ssrdb.cm.impl.ConfigManagementImpl.readDataSetXMI (ConfigManagementImpl.java:761)
at es.gmv.vsd.ssrdb.auditing.impl.AuditingImpl.readDataSetXMI(A uditingImpl.java:806)
at es.gmv.vsd.ssrdb.mmi.impl.ManagerImpl.executeMethod(ManagerI mpl.java:672)
at es.gmv.vsd.ssrdb.mmi.impl.ManagerImpl.run(ManagerImpl.java:1 22)
Caused by: java.lang.IllegalArgumentException: The value 'DELETE_ORPHAN' is not a valid enumerator of 'CascadeType'
at org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createCascadeTypeFromString(PannotationFactory Impl.java:610)
at org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createFromString(PannotationFactoryImpl.java:1 64)
at org.eclipse.emf.ecore.util.EcoreUtil.createFromString(EcoreU til.java:3259)
at org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:39)
... 19 more
|
3. teneo.hibernate -> @Cascade(value={PERSIST, REMOVE, DELETE_ORPHAN})
Ecore:
Quote: | <eClassifiers xsi:type="ecore:EClass" name="InterfaceUsage">
<eStructuralFeatures xsi:type="ecore:EReference" name="interfaceEnd1" eType="#//InterfaceEndUsage">
<eAnnotations source="teneo.hibernate">
<details key="value" value="@Cascade(value={PERSIST, REMOVE, DELETE_ORPHAN})"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="interfaceEnd2" eType="#//InterfaceEndUsage">
<eAnnotations source="teneo.hibernate">
<details key="value" value="@Cascade(value={PERSIST, REMOVE, DELETE_ORPHAN})"/>
</eAnnotations>
</eStructuralFeatures>
<eStructuralFeatures xsi:type="ecore:EReference" name="usages" upperBound="-1"
eType="#//InterfaceUsage" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="type" eType="#//InterfaceDefinition">
<eAnnotations source="teneo.hibernate">
<details key="value" value="@Cascade(value={PERSIST, REMOVE, DELETE_ORPHAN})"/>
</eAnnotations>
</eStructuralFeatures>
</eClassifiers>
|
get the following error message:
Quote: | org.hibernate.InvalidMappingException: Could not parse mapping document from string XML String
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processH bmXml(Configuration.java:3951)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processH bmXmlQueue(Configuration.java:3940)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processM etadata(Configuration.java:3928)
at org.hibernate.cfg.Configuration.secondPassCompile(Configurat ion.java:1368)
at org.hibernate.cfg.Configuration.buildMappings(Configuration. java:1345)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.buildMapp ings(HbSessionDataStore.java:134)
at org.eclipse.emf.teneo.hibernate.HbDataStore.initializeDataSt ore(HbDataStore.java:316)
at org.eclipse.emf.teneo.hibernate.HbSessionDataStore.initializ e(HbSessionDataStore.java:91)
at es.gmv.vsd.ssrdb.common.dao.factory.impl.H2DAOFactory.create Connection(H2DAOFactory.java:72)
at es.gmv.vsd.ssrdb.common.dao.factory.impl.DAOFactory.createCo nnection(DAOFactory.java:66)
at es.gmv.vsd.ssrdb.common.dao.impl.ds.DataSetVSEEDAO.removeAll (DataSetVSEEDAO.java:456)
at es.gmv.vsd.ssrdb.common.dao.impl.ds.DataSetVSEEDAO.get(DataS etVSEEDAO.java:167)
at es.gmv.vsd.ssrdb.common.dao.impl.cm.ConfigManagementDAO.read DataSetXMI(ConfigManagementDAO.java:1913)
at es.gmv.vsd.ssrdb.cm.impl.ConfigManagementImpl.readDataSetXMI (ConfigManagementImpl.java:761)
at es.gmv.vsd.ssrdb.auditing.impl.AuditingImpl.readDataSetXMI(A uditingImpl.java:806)
at es.gmv.vsd.ssrdb.mmi.impl.ManagerImpl.executeMethod(ManagerI mpl.java:672)
at es.gmv.vsd.ssrdb.mmi.impl.ManagerImpl.run(ManagerImpl.java:1 22)
Caused by: org.hibernate.MappingException: many-to-one attribute [interfaceEnd1] does not support orphan delete as it is not unique
at org.hibernate.cfg.HbmBinder.bindManyToOne(HbmBinder.java:163 9)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder. java:2164)
at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder. java:2134)
at org.hibernate.cfg.HbmBinder.bindJoinedSubclass(HbmBinder.jav a:949)
at org.hibernate.cfg.HbmBinder.handleJoinedSubclass(HbmBinder.j ava:2305)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:183)
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processH bmXml(Configuration.java:3948)
... 16 more
|
But neither works. Do you have any idea?
>I will add the possibility to do this through an option. I also seen other examples where people modeled a containment association as non->containment for their own reasons and this can be usefull. I will reply again to this post when this is available.
Perfect!
Best Regards,
Fernando
|
|
| |
Goto Forum:
Current Time: Fri Mar 29 13:51:31 GMT 2024
Powered by FUDForum. Page generated in 0.02298 seconds
|