Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [Teneo] @OneToMany cascade="ALL" not as expected
[Teneo] @OneToMany cascade="ALL" not as expected [message #424550] Wed, 29 October 2008 20:41 Go to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

I followed the example in claims.xsd for preventing a cascade delete.
This is for my Permission elements when a parent Role element is
deleted. Here is my xsd.

<xsd:complexType name="Role">
<xsd:sequence minOccurs="0" maxOccurs="1">
<xsd:element minOccurs="0" maxOccurs="unbounded"
name="permission" type="secmsec:Permission" ecore:opposite="role">
<xsd:annotation>
<xsd:appinfo
source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
cascade="ALL")</xsd:appinfo>
</xsd:annotation>
</xsd:element>
<xsd:element minOccurs="0" maxOccurs="unbounded"
type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
ecore:reference="secmsec:User">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa"> @ManyToMany(indexed=false)
@JoinTable(name="UserRole")</xsd:appinfo>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="id" type="xsd:int">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="name" type="xsd:string">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">@Column(unique=true)</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>

<xsd:complexType name="Permission">
<xsd:attribute name="id" type="xsd:int">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">@Id
@GeneratedValue(strategy=IDENTITY)</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="name" type="xsd:string"></xsd:attribute>
</xsd:complexType>
<xsd:element name="permission" type="secmsec:Permission"></xsd:element>

I also tried using a reference

<xsd:element minOccurs="0" maxOccurs="unbounded" name="permission"
ecore:reference="secmsec:Permission" ecore:opposite="role">
<xsd:annotation>
<xsd:appinfo
source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
cascade="ALL")</xsd:appinfo>
</xsd:annotation>
</xsd:element>

but I always end up with

<bag name="permission" inverse="true" lazy="true"
cascade="all,delete-orphan">
<key update="true" foreign-key="role_permission">
<column name="`permission_role_id`" not-null="false" unique="false"/>
</key>
<one-to-many entity-name="Permission"/>
</bag>

When what I think is required is cascade="all"

What am I missing?

Thx.

David
Re: [Teneo] @OneToMany cascade="ALL" not as expected [message #424551 is a reply to message #424550] Wed, 29 October 2008 22:03 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
Yes the JPA standard does not have a separate annotation for delete-orphan, therefore ALL translates
to all, delete-orphan. To get the behavior you want you need the list all other values:
MERGE,PERSIST,REFRESH,REMOVE
instead of using ALL

gr. Martin

David Wynter wrote:
> Hi,
>
> I followed the example in claims.xsd for preventing a cascade delete.
> This is for my Permission elements when a parent Role element is
> deleted. Here is my xsd.
>
> <xsd:complexType name="Role">
> <xsd:sequence minOccurs="0" maxOccurs="1">
> <xsd:element minOccurs="0" maxOccurs="unbounded"
> name="permission" type="secmsec:Permission" ecore:opposite="role">
> <xsd:annotation>
> <xsd:appinfo
> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
> cascade="ALL")</xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
> <xsd:element minOccurs="0" maxOccurs="unbounded"
> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
> ecore:reference="secmsec:User">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa"> @ManyToMany(indexed=false)
> @JoinTable(name="UserRole")</xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
> </xsd:sequence>
> <xsd:attribute name="id" type="xsd:int">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> <xsd:attribute name="name" type="xsd:string">
> <xsd:annotation>
> <xsd:appinfo
> source="teneo.jpa">@Column(unique=true)</xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> </xsd:complexType>
>
> <xsd:complexType name="Permission">
> <xsd:attribute name="id" type="xsd:int">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">@Id
> @GeneratedValue(strategy=IDENTITY)</xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> <xsd:attribute name="name" type="xsd:string"></xsd:attribute>
> </xsd:complexType>
> <xsd:element name="permission" type="secmsec:Permission"></xsd:element>
>
> I also tried using a reference
>
> <xsd:element minOccurs="0" maxOccurs="unbounded" name="permission"
> ecore:reference="secmsec:Permission" ecore:opposite="role">
> <xsd:annotation>
> <xsd:appinfo
> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
> cascade="ALL")</xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
>
> but I always end up with
>
> <bag name="permission" inverse="true" lazy="true"
> cascade="all,delete-orphan">
> <key update="true" foreign-key="role_permission">
> <column name="`permission_role_id`" not-null="false"
> unique="false"/>
> </key>
> <one-to-many entity-name="Permission"/>
> </bag>
>
> When what I think is required is cascade="all"
>
> What am I missing?
>
> Thx.
>
> David


--

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] @OneToMany cascade="ALL" not as expected [message #424552 is a reply to message #424550] Wed, 29 October 2008 22:09 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi Martin,

I tried changing the permission element inside Role annotation to use
cascade="PERSIST" which translates to cascade="persist,save-update,lock"
in the hibernate.hbm.xml. But then I also end up with a table called
role_permission with one foreign key from role.id to its role column?
This is a one to many why is there an extra table created?

I was also looking for the documentation on the valid cascade values for
the Teneo annotations. Do you have a reference to that?

Thx.

David

David Wynter wrote:
> Hi,
>
> I followed the example in claims.xsd for preventing a cascade delete.
> This is for my Permission elements when a parent Role element is
> deleted. Here is my xsd.
>
> <xsd:complexType name="Role">
> <xsd:sequence minOccurs="0" maxOccurs="1">
> <xsd:element minOccurs="0" maxOccurs="unbounded"
> name="permission" type="secmsec:Permission" ecore:opposite="role">
> <xsd:annotation>
> <xsd:appinfo
> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
> cascade="ALL")</xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
> <xsd:element minOccurs="0" maxOccurs="unbounded"
> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
> ecore:reference="secmsec:User">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa"> @ManyToMany(indexed=false)
> @JoinTable(name="UserRole")</xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
> </xsd:sequence>
> <xsd:attribute name="id" type="xsd:int">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> <xsd:attribute name="name" type="xsd:string">
> <xsd:annotation>
> <xsd:appinfo
> source="teneo.jpa">@Column(unique=true)</xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> </xsd:complexType>
>
> <xsd:complexType name="Permission">
> <xsd:attribute name="id" type="xsd:int">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa">@Id
> @GeneratedValue(strategy=IDENTITY)</xsd:appinfo>
> </xsd:annotation>
> </xsd:attribute>
> <xsd:attribute name="name" type="xsd:string"></xsd:attribute>
> </xsd:complexType>
> <xsd:element name="permission" type="secmsec:Permission"></xsd:element>
>
> I also tried using a reference
>
> <xsd:element minOccurs="0" maxOccurs="unbounded" name="permission"
> ecore:reference="secmsec:Permission" ecore:opposite="role">
> <xsd:annotation>
> <xsd:appinfo
> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
> cascade="ALL")</xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
>
> but I always end up with
>
> <bag name="permission" inverse="true" lazy="true"
> cascade="all,delete-orphan">
> <key update="true" foreign-key="role_permission">
> <column name="`permission_role_id`" not-null="false"
> unique="false"/>
> </key>
> <one-to-many entity-name="Permission"/>
> </bag>
>
> When what I think is required is cascade="all"
>
> What am I missing?
>
> Thx.
>
> David
Re: [Teneo] @OneToMany cascade="ALL" not as expected [message #424554 is a reply to message #424551] Wed, 29 October 2008 23:15 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi Martin,

I tried that

Exception in thread "main"
org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
Cannot convert 'PERSIST,MERGE,REFRESH,REMOVE' to 'CascadeType' type
at
org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:51)
at
org.eclipse.emf.teneo.annotations.parser.ComplexNode.convert (ComplexNode.java:92)
at
org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:115)
at
org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:83)
at
org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:72)
at
org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:64)
at
org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:106)
at
org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:57)
at
org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.createORM apperFile(GenerateHBM.java:108)
at
org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.main(Gene rateHBM.java:79)
Caused by: java.lang.IllegalArgumentException: The value
'PERSIST,MERGE,REFRESH,REMOVE' is not a valid enumerator of 'CascadeType'
at
org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createCascadeTypeFromString(PannotationFactory Impl.java:546)
at
org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createFromString(PannotationFactoryImpl.java:1 54)
at
org.eclipse.emf.ecore.util.EcoreUtil.createFromString(EcoreU til.java:3181)
at
org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:40)
... 9 more

Using

<xsd:element maxOccurs="unbounded" minOccurs="0" name="permission"
type="xsd:anyURI" ecore:reference="secmsec:Permission"
ecore:opposite="role">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa">@OneToMany(mappedBy="Permission",
cascade="PERSIST,MERGE,REFRESH,REMOVE", indexed=false)</xsd:appinfo>
</xsd:annotation>
</xsd:element>

Also used type = "IDREF" not sure of the difference in practice, seen
both used in this context.

David


Martin Taal wrote:
> Hi David,
> Yes the JPA standard does not have a separate annotation for
> delete-orphan, therefore ALL translates to all, delete-orphan. To get
> the behavior you want you need the list all other values:
> MERGE,PERSIST,REFRESH,REMOVE
> instead of using ALL
>
> gr. Martin
>
> David Wynter wrote:
>> Hi,
>>
>> I followed the example in claims.xsd for preventing a cascade delete.
>> This is for my Permission elements when a parent Role element is
>> deleted. Here is my xsd.
>>
>> <xsd:complexType name="Role">
>> <xsd:sequence minOccurs="0" maxOccurs="1">
>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>> name="permission" type="secmsec:Permission" ecore:opposite="role">
>> <xsd:annotation>
>> <xsd:appinfo
>> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
>> cascade="ALL")</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>> ecore:reference="secmsec:User">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa"> @ManyToMany(indexed=false)
>> @JoinTable(name="UserRole")</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>> </xsd:sequence>
>> <xsd:attribute name="id" type="xsd:int">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:attribute>
>> <xsd:attribute name="name" type="xsd:string">
>> <xsd:annotation>
>> <xsd:appinfo
>> source="teneo.jpa">@Column(unique=true)</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:attribute>
>> </xsd:complexType>
>>
>> <xsd:complexType name="Permission">
>> <xsd:attribute name="id" type="xsd:int">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">@Id
>> @GeneratedValue(strategy=IDENTITY)</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:attribute>
>> <xsd:attribute name="name" type="xsd:string"></xsd:attribute>
>> </xsd:complexType>
>> <xsd:element name="permission" type="secmsec:Permission"></xsd:element>
>>
>> I also tried using a reference
>>
>> <xsd:element minOccurs="0" maxOccurs="unbounded" name="permission"
>> ecore:reference="secmsec:Permission" ecore:opposite="role">
>> <xsd:annotation>
>> <xsd:appinfo
>> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
>> cascade="ALL")</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>>
>> but I always end up with
>>
>> <bag name="permission" inverse="true" lazy="true"
>> cascade="all,delete-orphan">
>> <key update="true" foreign-key="role_permission">
>> <column name="`permission_role_id`" not-null="false"
>> unique="false"/>
>> </key>
>> <one-to-many entity-name="Permission"/>
>> </bag>
>>
>> When what I think is required is cascade="all"
>>
>> What am I missing?
>>
>> Thx.
>>
>> David
>
>
Re: [Teneo] @OneToMany cascade="ALL" not as expected [message #424556 is a reply to message #424552] Wed, 29 October 2008 23:25 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
Did you set the option: JOIN_TABLE_FOR_NON_CONTAINED_ASSOCIATIONS? It is default true so if it is
not set to false then always a join table is created for one-to-many. If you set it to false then
the join table should not be generated.

Teneo supports the standard JPA cascade values and in addition the hibernate cascade annotation, for
example:
@Cascade({DELETE_ORPHAN, SAVE_UPDATE, REPLICATE, DELETE,PERSIST})

http://www.hibernate.org/hib_docs/annotations/reference/en/h tml_single/#entity-hibspec-cascade
http://www.elver.org/hibernate/ejb3_features.html

gr. Martin

David Wynter wrote:
> Hi Martin,
>
> I tried changing the permission element inside Role annotation to use
> cascade="PERSIST" which translates to cascade="persist,save-update,lock"
> in the hibernate.hbm.xml. But then I also end up with a table called
> role_permission with one foreign key from role.id to its role column?
> This is a one to many why is there an extra table created?
>
> I was also looking for the documentation on the valid cascade values for
> the Teneo annotations. Do you have a reference to that?
>
> Thx.
>
> David
>
> David Wynter wrote:
>> Hi,
>>
>> I followed the example in claims.xsd for preventing a cascade delete.
>> This is for my Permission elements when a parent Role element is
>> deleted. Here is my xsd.
>>
>> <xsd:complexType name="Role">
>> <xsd:sequence minOccurs="0" maxOccurs="1">
>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>> name="permission" type="secmsec:Permission" ecore:opposite="role">
>> <xsd:annotation>
>> <xsd:appinfo
>> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
>> cascade="ALL")</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>> ecore:reference="secmsec:User">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa"> @ManyToMany(indexed=false)
>> @JoinTable(name="UserRole")</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>> </xsd:sequence>
>> <xsd:attribute name="id" type="xsd:int">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:attribute>
>> <xsd:attribute name="name" type="xsd:string">
>> <xsd:annotation>
>> <xsd:appinfo
>> source="teneo.jpa">@Column(unique=true)</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:attribute>
>> </xsd:complexType>
>>
>> <xsd:complexType name="Permission">
>> <xsd:attribute name="id" type="xsd:int">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa">@Id
>> @GeneratedValue(strategy=IDENTITY)</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:attribute>
>> <xsd:attribute name="name" type="xsd:string"></xsd:attribute>
>> </xsd:complexType>
>> <xsd:element name="permission" type="secmsec:Permission"></xsd:element>
>>
>> I also tried using a reference
>>
>> <xsd:element minOccurs="0" maxOccurs="unbounded" name="permission"
>> ecore:reference="secmsec:Permission" ecore:opposite="role">
>> <xsd:annotation>
>> <xsd:appinfo
>> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
>> cascade="ALL")</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>>
>> but I always end up with
>>
>> <bag name="permission" inverse="true" lazy="true"
>> cascade="all,delete-orphan">
>> <key update="true" foreign-key="role_permission">
>> <column name="`permission_role_id`" not-null="false"
>> unique="false"/>
>> </key>
>> <one-to-many entity-name="Permission"/>
>> </bag>
>>
>> When what I think is required is cascade="all"
>>
>> What am I missing?
>>
>> Thx.
>>
>> David


--

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] @OneToMany cascade="ALL" not as expected [message #424557 is a reply to message #424554] Wed, 29 October 2008 23:28 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
In JPA/annotations you have to use an array notation for multiple values, so the correct format is this:
@OneToMany(mappedBy="Permission", cascade={PERSIST,MERGE,REFRESH,REMOVE}, indexed=false)

In addition a cascade is not a string but an enum (therefore there are no double quotes around the
values).

gr. Martin

David Wynter wrote:
> Hi Martin,
>
> I tried that
>
> Exception in thread "main"
> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
> Cannot convert 'PERSIST,MERGE,REFRESH,REMOVE' to 'CascadeType' type
> at
> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:51)
>
> at
> org.eclipse.emf.teneo.annotations.parser.ComplexNode.convert (ComplexNode.java:92)
>
> at
> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:115)
>
> at
> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:83)
>
> at
> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:72)
>
> at
> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:64)
>
> at
> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:106)
>
> at
> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:57)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.createORM apperFile(GenerateHBM.java:108)
>
> at
> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.main(Gene rateHBM.java:79)
>
> Caused by: java.lang.IllegalArgumentException: The value
> 'PERSIST,MERGE,REFRESH,REMOVE' is not a valid enumerator of 'CascadeType'
> at
> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createCascadeTypeFromString(PannotationFactory Impl.java:546)
>
> at
> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createFromString(PannotationFactoryImpl.java:1 54)
>
> at
> org.eclipse.emf.ecore.util.EcoreUtil.createFromString(EcoreU til.java:3181)
> at
> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:40)
>
> ... 9 more
>
> Using
>
> <xsd:element maxOccurs="unbounded" minOccurs="0" name="permission"
> type="xsd:anyURI" ecore:reference="secmsec:Permission"
> ecore:opposite="role">
> <xsd:annotation>
> <xsd:appinfo
> source="teneo.jpa">@OneToMany(mappedBy="Permission",
> cascade="PERSIST,MERGE,REFRESH,REMOVE", indexed=false)</xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
>
> Also used type = "IDREF" not sure of the difference in practice, seen
> both used in this context.
>
> David
>
>
> Martin Taal wrote:
>> Hi David,
>> Yes the JPA standard does not have a separate annotation for
>> delete-orphan, therefore ALL translates to all, delete-orphan. To get
>> the behavior you want you need the list all other values:
>> MERGE,PERSIST,REFRESH,REMOVE
>> instead of using ALL
>>
>> gr. Martin
>>
>> David Wynter wrote:
>>> Hi,
>>>
>>> I followed the example in claims.xsd for preventing a cascade delete.
>>> This is for my Permission elements when a parent Role element is
>>> deleted. Here is my xsd.
>>>
>>> <xsd:complexType name="Role">
>>> <xsd:sequence minOccurs="0" maxOccurs="1">
>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>> name="permission" type="secmsec:Permission" ecore:opposite="role">
>>> <xsd:annotation>
>>> <xsd:appinfo
>>> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
>>> cascade="ALL")</xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:element>
>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>> ecore:reference="secmsec:User">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa"> @ManyToMany(indexed=false)
>>> @JoinTable(name="UserRole")</xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:element>
>>> </xsd:sequence>
>>> <xsd:attribute name="id" type="xsd:int">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:attribute>
>>> <xsd:attribute name="name" type="xsd:string">
>>> <xsd:annotation>
>>> <xsd:appinfo
>>> source="teneo.jpa">@Column(unique=true)</xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:attribute>
>>> </xsd:complexType>
>>>
>>> <xsd:complexType name="Permission">
>>> <xsd:attribute name="id" type="xsd:int">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa">@Id
>>> @GeneratedValue(strategy=IDENTITY)</xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:attribute>
>>> <xsd:attribute name="name" type="xsd:string"></xsd:attribute>
>>> </xsd:complexType>
>>> <xsd:element name="permission" type="secmsec:Permission"></xsd:element>
>>>
>>> I also tried using a reference
>>>
>>> <xsd:element minOccurs="0" maxOccurs="unbounded" name="permission"
>>> ecore:reference="secmsec:Permission" ecore:opposite="role">
>>> <xsd:annotation>
>>> <xsd:appinfo
>>> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
>>> cascade="ALL")</xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:element>
>>>
>>> but I always end up with
>>>
>>> <bag name="permission" inverse="true" lazy="true"
>>> cascade="all,delete-orphan">
>>> <key update="true" foreign-key="role_permission">
>>> <column name="`permission_role_id`" not-null="false"
>>> unique="false"/>
>>> </key>
>>> <one-to-many entity-name="Permission"/>
>>> </bag>
>>>
>>> When what I think is required is cascade="all"
>>>
>>> What am I missing?
>>>
>>> Thx.
>>>
>>> David
>>
>>


--

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] @OneToMany cascade="ALL" not as expected [message #424559 is a reply to message #424557] Wed, 29 October 2008 23:44 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi Martin,

Do I have to use this annotation at all. This option setting suggests
that if I correct these tables that are effectively controlled
vocabularies to all be non containment then this option:

PersistenceOptions.CASCADE_POLICY_ON_NON_CONTAINMENT (default: not
set): this option allows you to set the default cascade policy for non
containment relations. It can be set to a comma delimited set of cascade
values, for example MERGE, PERSIST, REFRESH. If this option is not set
then then the system will use the following set: MERGE, PERSIST, REFRESH.

Suggests the std behaviour should set the correct cascade behaviour.

Thx.

David

Martin Taal wrote:
> Hi David,
> In JPA/annotations you have to use an array notation for multiple
> values, so the correct format is this:
> @OneToMany(mappedBy="Permission",
> cascade={PERSIST,MERGE,REFRESH,REMOVE}, indexed=false)
>
> In addition a cascade is not a string but an enum (therefore there are
> no double quotes around the values).
>
> gr. Martin
>
> David Wynter wrote:
>> Hi Martin,
>>
>> I tried that
>>
>> Exception in thread "main"
>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>> Cannot convert 'PERSIST,MERGE,REFRESH,REMOVE' to 'CascadeType' type
>> at
>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:51)
>>
>> at
>> org.eclipse.emf.teneo.annotations.parser.ComplexNode.convert (ComplexNode.java:92)
>>
>> at
>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:115)
>>
>> at
>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:83)
>>
>> at
>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:72)
>>
>> at
>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:64)
>>
>> at
>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:106)
>>
>> at
>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:57)
>>
>> at
>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.createORM apperFile(GenerateHBM.java:108)
>>
>> at
>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.main(Gene rateHBM.java:79)
>>
>> Caused by: java.lang.IllegalArgumentException: The value
>> 'PERSIST,MERGE,REFRESH,REMOVE' is not a valid enumerator of 'CascadeType'
>> at
>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createCascadeTypeFromString(PannotationFactory Impl.java:546)
>>
>> at
>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createFromString(PannotationFactoryImpl.java:1 54)
>>
>> at
>> org.eclipse.emf.ecore.util.EcoreUtil.createFromString(EcoreU til.java:3181)
>>
>> at
>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:40)
>>
>> ... 9 more
>>
>> Using
>>
>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>> name="permission" type="xsd:anyURI"
>> ecore:reference="secmsec:Permission" ecore:opposite="role">
>> <xsd:annotation>
>> <xsd:appinfo
>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>> cascade="PERSIST,MERGE,REFRESH,REMOVE", indexed=false)</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>>
>> Also used type = "IDREF" not sure of the difference in practice, seen
>> both used in this context.
>>
>> David
>>
>>
>> Martin Taal wrote:
>>> Hi David,
>>> Yes the JPA standard does not have a separate annotation for
>>> delete-orphan, therefore ALL translates to all, delete-orphan. To get
>>> the behavior you want you need the list all other values:
>>> MERGE,PERSIST,REFRESH,REMOVE
>>> instead of using ALL
>>>
>>> gr. Martin
>>>
>>> David Wynter wrote:
>>>> Hi,
>>>>
>>>> I followed the example in claims.xsd for preventing a cascade
>>>> delete. This is for my Permission elements when a parent Role
>>>> element is deleted. Here is my xsd.
>>>>
>>>> <xsd:complexType name="Role">
>>>> <xsd:sequence minOccurs="0" maxOccurs="1">
>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>> name="permission" type="secmsec:Permission" ecore:opposite="role">
>>>> <xsd:annotation>
>>>> <xsd:appinfo
>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
>>>> cascade="ALL")</xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:element>
>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>>> ecore:reference="secmsec:User">
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @ManyToMany(indexed=false) @JoinTable(name="UserRole")</xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:element>
>>>> </xsd:sequence>
>>>> <xsd:attribute name="id" type="xsd:int">
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:attribute>
>>>> <xsd:attribute name="name" type="xsd:string">
>>>> <xsd:annotation>
>>>> <xsd:appinfo
>>>> source="teneo.jpa">@Column(unique=true)</xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:attribute>
>>>> </xsd:complexType>
>>>>
>>>> <xsd:complexType name="Permission">
>>>> <xsd:attribute name="id" type="xsd:int">
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">@Id
>>>> @GeneratedValue(strategy=IDENTITY)</xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:attribute>
>>>> <xsd:attribute name="name" type="xsd:string"></xsd:attribute>
>>>> </xsd:complexType>
>>>> <xsd:element name="permission"
>>>> type="secmsec:Permission"></xsd:element>
>>>>
>>>> I also tried using a reference
>>>>
>>>> <xsd:element minOccurs="0" maxOccurs="unbounded" name="permission"
>>>> ecore:reference="secmsec:Permission" ecore:opposite="role">
>>>> <xsd:annotation>
>>>> <xsd:appinfo
>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
>>>> cascade="ALL")</xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:element>
>>>>
>>>> but I always end up with
>>>>
>>>> <bag name="permission" inverse="true" lazy="true"
>>>> cascade="all,delete-orphan">
>>>> <key update="true" foreign-key="role_permission">
>>>> <column name="`permission_role_id`" not-null="false"
>>>> unique="false"/>
>>>> </key>
>>>> <one-to-many entity-name="Permission"/>
>>>> </bag>
>>>>
>>>> When what I think is required is cascade="all"
>>>>
>>>> What am I missing?
>>>>
>>>> Thx.
>>>>
>>>> David
>>>
>>>
>
>
Re: [Teneo] @OneToMany cascade="ALL" not as expected [message #424566 is a reply to message #424559] Thu, 30 October 2008 08:11 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
My confusion, I thought that you were talking about containment relations.

An assocation defined like below should not result in delete-orphan or remove:
<xsd:element minOccurs="0" maxOccurs="unbounded" type="xsd:anyURI"
ecore:opposite="userRole" name="roleUser" ecore:reference="secmsec:User">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa"> @ManyToMany(indexed=false)
@JoinTable(name="UserRole")</xsd:appinfo>
</xsd:annotation>
</xsd:element>

it should have the cascades (as a default): MERGE, PERSIST, REFRESH resulting in the following
cascades in hbm: MERGE, SAVE-UPDATE, PERSIST, LOCK, REFRESH

if you define it as containment, like below, then it has ALL as a default which results in all,
delete-orphan. Which you can override using annotations in specific cases or globally by setting
CASCADE_POLICY_ON_CONTAINMENT.

<xsd:element minOccurs="0" maxOccurs="unbounded" type="secmsec:User"
ecore:opposite="userRole" name="roleUser">
<xsd:annotation>
<xsd:appinfo source="teneo.jpa"> @ManyToMany(indexed=false)
@JoinTable(name="UserRole")</xsd:appinfo>
</xsd:annotation>
</xsd:element>

gr. Martin

David Wynter wrote:
> Hi Martin,
>
> Do I have to use this annotation at all. This option setting suggests
> that if I correct these tables that are effectively controlled
> vocabularies to all be non containment then this option:
>
> PersistenceOptions.CASCADE_POLICY_ON_NON_CONTAINMENT (default: not
> set): this option allows you to set the default cascade policy for non
> containment relations. It can be set to a comma delimited set of cascade
> values, for example MERGE, PERSIST, REFRESH. If this option is not set
> then then the system will use the following set: MERGE, PERSIST, REFRESH.
>
> Suggests the std behaviour should set the correct cascade behaviour.
>
> Thx.
>
> David
>
> Martin Taal wrote:
>> Hi David,
>> In JPA/annotations you have to use an array notation for multiple
>> values, so the correct format is this:
>> @OneToMany(mappedBy="Permission",
>> cascade={PERSIST,MERGE,REFRESH,REMOVE}, indexed=false)
>>
>> In addition a cascade is not a string but an enum (therefore there are
>> no double quotes around the values).
>>
>> gr. Martin
>>
>> David Wynter wrote:
>>> Hi Martin,
>>>
>>> I tried that
>>>
>>> Exception in thread "main"
>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>> Cannot convert 'PERSIST,MERGE,REFRESH,REMOVE' to 'CascadeType' type
>>> at
>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:51)
>>>
>>> at
>>> org.eclipse.emf.teneo.annotations.parser.ComplexNode.convert (ComplexNode.java:92)
>>>
>>> at
>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:115)
>>>
>>> at
>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:83)
>>>
>>> at
>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:72)
>>>
>>> at
>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:64)
>>>
>>> at
>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:106)
>>>
>>> at
>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:57)
>>>
>>> at
>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.createORM apperFile(GenerateHBM.java:108)
>>>
>>> at
>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.main(Gene rateHBM.java:79)
>>>
>>> Caused by: java.lang.IllegalArgumentException: The value
>>> 'PERSIST,MERGE,REFRESH,REMOVE' is not a valid enumerator of
>>> 'CascadeType'
>>> at
>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createCascadeTypeFromString(PannotationFactory Impl.java:546)
>>>
>>> at
>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createFromString(PannotationFactoryImpl.java:1 54)
>>>
>>> at
>>> org.eclipse.emf.ecore.util.EcoreUtil.createFromString(EcoreU til.java:3181)
>>>
>>> at
>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:40)
>>>
>>> ... 9 more
>>>
>>> Using
>>>
>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>> name="permission" type="xsd:anyURI"
>>> ecore:reference="secmsec:Permission" ecore:opposite="role">
>>> <xsd:annotation>
>>> <xsd:appinfo
>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>> cascade="PERSIST,MERGE,REFRESH,REMOVE", indexed=false)</xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:element>
>>>
>>> Also used type = "IDREF" not sure of the difference in practice, seen
>>> both used in this context.
>>>
>>> David
>>>
>>>
>>> Martin Taal wrote:
>>>> Hi David,
>>>> Yes the JPA standard does not have a separate annotation for
>>>> delete-orphan, therefore ALL translates to all, delete-orphan. To
>>>> get the behavior you want you need the list all other values:
>>>> MERGE,PERSIST,REFRESH,REMOVE
>>>> instead of using ALL
>>>>
>>>> gr. Martin
>>>>
>>>> David Wynter wrote:
>>>>> Hi,
>>>>>
>>>>> I followed the example in claims.xsd for preventing a cascade
>>>>> delete. This is for my Permission elements when a parent Role
>>>>> element is deleted. Here is my xsd.
>>>>>
>>>>> <xsd:complexType name="Role">
>>>>> <xsd:sequence minOccurs="0" maxOccurs="1">
>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>> name="permission" type="secmsec:Permission" ecore:opposite="role">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo
>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
>>>>> cascade="ALL")</xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:element>
>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>>>> ecore:reference="secmsec:User">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @ManyToMany(indexed=false) @JoinTable(name="UserRole")</xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:element>
>>>>> </xsd:sequence>
>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:attribute>
>>>>> <xsd:attribute name="name" type="xsd:string">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo
>>>>> source="teneo.jpa">@Column(unique=true)</xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:attribute>
>>>>> </xsd:complexType>
>>>>>
>>>>> <xsd:complexType name="Permission">
>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">@Id
>>>>> @GeneratedValue(strategy=IDENTITY)</xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:attribute>
>>>>> <xsd:attribute name="name" type="xsd:string"></xsd:attribute>
>>>>> </xsd:complexType>
>>>>> <xsd:element name="permission"
>>>>> type="secmsec:Permission"></xsd:element>
>>>>>
>>>>> I also tried using a reference
>>>>>
>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded" name="permission"
>>>>> ecore:reference="secmsec:Permission" ecore:opposite="role">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo
>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
>>>>> cascade="ALL")</xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:element>
>>>>>
>>>>> but I always end up with
>>>>>
>>>>> <bag name="permission" inverse="true" lazy="true"
>>>>> cascade="all,delete-orphan">
>>>>> <key update="true" foreign-key="role_permission">
>>>>> <column name="`permission_role_id`"
>>>>> not-null="false" unique="false"/>
>>>>> </key>
>>>>> <one-to-many entity-name="Permission"/>
>>>>> </bag>
>>>>>
>>>>> When what I think is required is cascade="all"
>>>>>
>>>>> What am I missing?
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>
>>>>
>>
>>


--

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] @OneToMany cascade="ALL" not as expected [message #424568 is a reply to message #424566] Thu, 30 October 2008 09:00 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi Martin,

Thanks that clarifies it perfectly. I had tried both types of
relationship, containment and non. I assume you meant to use @OneToMany
in you examples below? According to the Hibernate manual the ManyToMany
do not make sense for non cascade to delete orphan.

David

Martin Taal wrote:
> Hi David,
> My confusion, I thought that you were talking about containment relations.
>
> An assocation defined like below should not result in delete-orphan or
> remove:
> <xsd:element minOccurs="0" maxOccurs="unbounded"
> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
> ecore:reference="secmsec:User">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa"> @ManyToMany(indexed=false)
> @JoinTable(name="UserRole")</xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
>
> it should have the cascades (as a default): MERGE, PERSIST, REFRESH
> resulting in the following cascades in hbm: MERGE, SAVE-UPDATE, PERSIST,
> LOCK, REFRESH
>
> if you define it as containment, like below, then it has ALL as a
> default which results in all, delete-orphan. Which you can override
> using annotations in specific cases or globally by setting
> CASCADE_POLICY_ON_CONTAINMENT.
>
> <xsd:element minOccurs="0" maxOccurs="unbounded"
> type="secmsec:User" ecore:opposite="userRole" name="roleUser">
> <xsd:annotation>
> <xsd:appinfo source="teneo.jpa"> @ManyToMany(indexed=false)
> @JoinTable(name="UserRole")</xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
>
> gr. Martin
>
> David Wynter wrote:
>> Hi Martin,
>>
>> Do I have to use this annotation at all. This option setting suggests
>> that if I correct these tables that are effectively controlled
>> vocabularies to all be non containment then this option:
>>
>> PersistenceOptions.CASCADE_POLICY_ON_NON_CONTAINMENT (default: not
>> set): this option allows you to set the default cascade policy for non
>> containment relations. It can be set to a comma delimited set of
>> cascade values, for example MERGE, PERSIST, REFRESH. If this option is
>> not set then then the system will use the following set: MERGE,
>> PERSIST, REFRESH.
>>
>> Suggests the std behaviour should set the correct cascade behaviour.
>>
>> Thx.
>>
>> David
>>
>> Martin Taal wrote:
>>> Hi David,
>>> In JPA/annotations you have to use an array notation for multiple
>>> values, so the correct format is this:
>>> @OneToMany(mappedBy="Permission",
>>> cascade={PERSIST,MERGE,REFRESH,REMOVE}, indexed=false)
>>>
>>> In addition a cascade is not a string but an enum (therefore there
>>> are no double quotes around the values).
>>>
>>> gr. Martin
>>>
>>> David Wynter wrote:
>>>> Hi Martin,
>>>>
>>>> I tried that
>>>>
>>>> Exception in thread "main"
>>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>>> Cannot convert 'PERSIST,MERGE,REFRESH,REMOVE' to 'CascadeType' type
>>>> at
>>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:51)
>>>>
>>>> at
>>>> org.eclipse.emf.teneo.annotations.parser.ComplexNode.convert (ComplexNode.java:92)
>>>>
>>>> at
>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:115)
>>>>
>>>> at
>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:83)
>>>>
>>>> at
>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:72)
>>>>
>>>> at
>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:64)
>>>>
>>>> at
>>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:106)
>>>>
>>>> at
>>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:57)
>>>>
>>>> at
>>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.createORM apperFile(GenerateHBM.java:108)
>>>>
>>>> at
>>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.main(Gene rateHBM.java:79)
>>>>
>>>> Caused by: java.lang.IllegalArgumentException: The value
>>>> 'PERSIST,MERGE,REFRESH,REMOVE' is not a valid enumerator of
>>>> 'CascadeType'
>>>> at
>>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createCascadeTypeFromString(PannotationFactory Impl.java:546)
>>>>
>>>> at
>>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createFromString(PannotationFactoryImpl.java:1 54)
>>>>
>>>> at
>>>> org.eclipse.emf.ecore.util.EcoreUtil.createFromString(EcoreU til.java:3181)
>>>>
>>>> at
>>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:40)
>>>>
>>>> ... 9 more
>>>>
>>>> Using
>>>>
>>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>>> name="permission" type="xsd:anyURI"
>>>> ecore:reference="secmsec:Permission" ecore:opposite="role">
>>>> <xsd:annotation>
>>>> <xsd:appinfo
>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>> cascade="PERSIST,MERGE,REFRESH,REMOVE", indexed=false)</xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:element>
>>>>
>>>> Also used type = "IDREF" not sure of the difference in practice,
>>>> seen both used in this context.
>>>>
>>>> David
>>>>
>>>>
>>>> Martin Taal wrote:
>>>>> Hi David,
>>>>> Yes the JPA standard does not have a separate annotation for
>>>>> delete-orphan, therefore ALL translates to all, delete-orphan. To
>>>>> get the behavior you want you need the list all other values:
>>>>> MERGE,PERSIST,REFRESH,REMOVE
>>>>> instead of using ALL
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> David Wynter wrote:
>>>>>> Hi,
>>>>>>
>>>>>> I followed the example in claims.xsd for preventing a cascade
>>>>>> delete. This is for my Permission elements when a parent Role
>>>>>> element is deleted. Here is my xsd.
>>>>>>
>>>>>> <xsd:complexType name="Role">
>>>>>> <xsd:sequence minOccurs="0" maxOccurs="1">
>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>> name="permission" type="secmsec:Permission" ecore:opposite="role">
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo
>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
>>>>>> cascade="ALL")</xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:element>
>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>>>>> ecore:reference="secmsec:User">
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>> @ManyToMany(indexed=false) @JoinTable(name="UserRole")</xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:element>
>>>>>> </xsd:sequence>
>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:attribute>
>>>>>> <xsd:attribute name="name" type="xsd:string">
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo
>>>>>> source="teneo.jpa">@Column(unique=true)</xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:attribute>
>>>>>> </xsd:complexType>
>>>>>>
>>>>>> <xsd:complexType name="Permission">
>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo source="teneo.jpa">@Id
>>>>>> @GeneratedValue(strategy=IDENTITY)</xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:attribute>
>>>>>> <xsd:attribute name="name" type="xsd:string"></xsd:attribute>
>>>>>> </xsd:complexType>
>>>>>> <xsd:element name="permission"
>>>>>> type="secmsec:Permission"></xsd:element>
>>>>>>
>>>>>> I also tried using a reference
>>>>>>
>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded" name="permission"
>>>>>> ecore:reference="secmsec:Permission" ecore:opposite="role">
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo
>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false
>>>>>> cascade="ALL")</xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:element>
>>>>>>
>>>>>> but I always end up with
>>>>>>
>>>>>> <bag name="permission" inverse="true" lazy="true"
>>>>>> cascade="all,delete-orphan">
>>>>>> <key update="true" foreign-key="role_permission">
>>>>>> <column name="`permission_role_id`"
>>>>>> not-null="false" unique="false"/>
>>>>>> </key>
>>>>>> <one-to-many entity-name="Permission"/>
>>>>>> </bag>
>>>>>>
>>>>>> When what I think is required is cascade="all"
>>>>>>
>>>>>> What am I missing?
>>>>>>
>>>>>> Thx.
>>>>>>
>>>>>> David
>>>>>
>>>>>
>>>
>>>
>
>
Re: [Teneo] @OneToMany cascade="ALL" not as expected [message #424569 is a reply to message #424568] Thu, 30 October 2008 09:35 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
Yes this was copy-paste posting :-), delete-orphan and manytomany are not logical together.

gr. Mmartin

David Wynter wrote:
> Hi Martin,
>
> Thanks that clarifies it perfectly. I had tried both types of
> relationship, containment and non. I assume you meant to use @OneToMany
> in you examples below? According to the Hibernate manual the ManyToMany
> do not make sense for non cascade to delete orphan.
>
> David
>
> Martin Taal wrote:
>> Hi David,
>> My confusion, I thought that you were talking about containment
>> relations.
>>
>> An assocation defined like below should not result in delete-orphan or
>> remove:
>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>> ecore:reference="secmsec:User">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa"> @ManyToMany(indexed=false)
>> @JoinTable(name="UserRole")</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>>
>> it should have the cascades (as a default): MERGE, PERSIST, REFRESH
>> resulting in the following cascades in hbm: MERGE, SAVE-UPDATE,
>> PERSIST, LOCK, REFRESH
>>
>> if you define it as containment, like below, then it has ALL as a
>> default which results in all, delete-orphan. Which you can override
>> using annotations in specific cases or globally by setting
>> CASCADE_POLICY_ON_CONTAINMENT.
>>
>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>> type="secmsec:User" ecore:opposite="userRole" name="roleUser">
>> <xsd:annotation>
>> <xsd:appinfo source="teneo.jpa"> @ManyToMany(indexed=false)
>> @JoinTable(name="UserRole")</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>>
>> gr. Martin
>>
>> David Wynter wrote:
>>> Hi Martin,
>>>
>>> Do I have to use this annotation at all. This option setting suggests
>>> that if I correct these tables that are effectively controlled
>>> vocabularies to all be non containment then this option:
>>>
>>> PersistenceOptions.CASCADE_POLICY_ON_NON_CONTAINMENT (default: not
>>> set): this option allows you to set the default cascade policy for
>>> non containment relations. It can be set to a comma delimited set of
>>> cascade values, for example MERGE, PERSIST, REFRESH. If this option
>>> is not set then then the system will use the following set: MERGE,
>>> PERSIST, REFRESH.
>>>
>>> Suggests the std behaviour should set the correct cascade behaviour.
>>>
>>> Thx.
>>>
>>> David
>>>
>>> Martin Taal wrote:
>>>> Hi David,
>>>> In JPA/annotations you have to use an array notation for multiple
>>>> values, so the correct format is this:
>>>> @OneToMany(mappedBy="Permission",
>>>> cascade={PERSIST,MERGE,REFRESH,REMOVE}, indexed=false)
>>>>
>>>> In addition a cascade is not a string but an enum (therefore there
>>>> are no double quotes around the values).
>>>>
>>>> gr. Martin
>>>>
>>>> David Wynter wrote:
>>>>> Hi Martin,
>>>>>
>>>>> I tried that
>>>>>
>>>>> Exception in thread "main"
>>>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>>>> Cannot convert 'PERSIST,MERGE,REFRESH,REMOVE' to 'CascadeType' type
>>>>> at
>>>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:51)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.teneo.annotations.parser.ComplexNode.convert (ComplexNode.java:92)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:115)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:83)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:72)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:64)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:106)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:57)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.createORM apperFile(GenerateHBM.java:108)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.main(Gene rateHBM.java:79)
>>>>>
>>>>> Caused by: java.lang.IllegalArgumentException: The value
>>>>> 'PERSIST,MERGE,REFRESH,REMOVE' is not a valid enumerator of
>>>>> 'CascadeType'
>>>>> at
>>>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createCascadeTypeFromString(PannotationFactory Impl.java:546)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createFromString(PannotationFactoryImpl.java:1 54)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.ecore.util.EcoreUtil.createFromString(EcoreU til.java:3181)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:40)
>>>>>
>>>>> ... 9 more
>>>>>
>>>>> Using
>>>>>
>>>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>>>> name="permission" type="xsd:anyURI"
>>>>> ecore:reference="secmsec:Permission" ecore:opposite="role">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo
>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>> cascade="PERSIST,MERGE,REFRESH,REMOVE", indexed=false)</xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:element>
>>>>>
>>>>> Also used type = "IDREF" not sure of the difference in practice,
>>>>> seen both used in this context.
>>>>>
>>>>> David
>>>>>
>>>>>
>>>>> Martin Taal wrote:
>>>>>> Hi David,
>>>>>> Yes the JPA standard does not have a separate annotation for
>>>>>> delete-orphan, therefore ALL translates to all, delete-orphan. To
>>>>>> get the behavior you want you need the list all other values:
>>>>>> MERGE,PERSIST,REFRESH,REMOVE
>>>>>> instead of using ALL
>>>>>>
>>>>>> gr. Martin
>>>>>>
>>>>>> David Wynter wrote:
>>>>>>> Hi,
>>>>>>>
>>>>>>> I followed the example in claims.xsd for preventing a cascade
>>>>>>> delete. This is for my Permission elements when a parent Role
>>>>>>> element is deleted. Here is my xsd.
>>>>>>>
>>>>>>> <xsd:complexType name="Role">
>>>>>>> <xsd:sequence minOccurs="0" maxOccurs="1">
>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>> name="permission" type="secmsec:Permission" ecore:opposite="role">
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo
>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>> indexed=false cascade="ALL")</xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>> </xsd:element>
>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>>>>>> ecore:reference="secmsec:User">
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>> @ManyToMany(indexed=false) @JoinTable(name="UserRole")</xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>> </xsd:element>
>>>>>>> </xsd:sequence>
>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>> </xsd:attribute>
>>>>>>> <xsd:attribute name="name" type="xsd:string">
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo
>>>>>>> source="teneo.jpa">@Column(unique=true)</xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>> </xsd:attribute>
>>>>>>> </xsd:complexType>
>>>>>>>
>>>>>>> <xsd:complexType name="Permission">
>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo source="teneo.jpa">@Id
>>>>>>> @GeneratedValue(strategy=IDENTITY)</xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>> </xsd:attribute>
>>>>>>> <xsd:attribute name="name" type="xsd:string"></xsd:attribute>
>>>>>>> </xsd:complexType>
>>>>>>> <xsd:element name="permission"
>>>>>>> type="secmsec:Permission"></xsd:element>
>>>>>>>
>>>>>>> I also tried using a reference
>>>>>>>
>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>> name="permission" ecore:reference="secmsec:Permission"
>>>>>>> ecore:opposite="role">
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo
>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>> indexed=false cascade="ALL")</xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>> </xsd:element>
>>>>>>>
>>>>>>> but I always end up with
>>>>>>>
>>>>>>> <bag name="permission" inverse="true" lazy="true"
>>>>>>> cascade="all,delete-orphan">
>>>>>>> <key update="true" foreign-key="role_permission">
>>>>>>> <column name="`permission_role_id`"
>>>>>>> not-null="false" unique="false"/>
>>>>>>> </key>
>>>>>>> <one-to-many entity-name="Permission"/>
>>>>>>> </bag>
>>>>>>>
>>>>>>> When what I think is required is cascade="all"
>>>>>>>
>>>>>>> What am I missing?
>>>>>>>
>>>>>>> Thx.
>>>>>>>
>>>>>>> David
>>>>>>
>>>>>>
>>>>
>>>>
>>
>>


--

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] @OneToMany cascade="ALL" not as expected [message #424618 is a reply to message #424569] Fri, 31 October 2008 12:05 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi Martin,

I tried the

<xsd:complexType name="Role">
<xsd:sequence minOccurs="0" maxOccurs="1">
<xsd:element minOccurs="0" maxOccurs="unbounded"
name="permission" ecore:reference="secmsec:Permission"
ecore:opposite="role">
<xsd:annotation>
<xsd:appinfo
source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false,
cascade=MERGE,PERSIST,REFRESH)</xsd:appinfo>
</xsd:annotation>
</xsd:element>
.....

But get this

Exception in thread "main"
org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption: No =
character after identifier, see _ for error position
@OneToMany(mappedBy="Permission", indexed=false,
cascade=MERGE,PERSIST,_REFRESH)

I was trying to experiment to find out which if any of the cascade enum
types influence the hibernate definition. After reading this

http://parasjain01.wordpress.com/2008/01/14/orghibernatetran sientobjectexception-object-references-an-unsaved-transient- instance-save-the-transient-instance-before-flushing/

I realised I need to had update=”false” insert=”false” set for all the
tables that contain non transient objects. In another model I have over
100 tables that contain controlled vocabularies, which none of the
tables that have them as a reference by foreign key should ever delete
or attempt to persist.

Thx.

David



Martin Taal wrote:
> Hi David,
> Yes this was copy-paste posting :-), delete-orphan and manytomany are
> not logical together.
>
> gr. Mmartin
>
> David Wynter wrote:
>> Hi Martin,
>>
>> Thanks that clarifies it perfectly. I had tried both types of
>> relationship, containment and non. I assume you meant to use
>> @OneToMany in you examples below? According to the Hibernate manual
>> the ManyToMany do not make sense for non cascade to delete orphan.
>>
>> David
>>
>> Martin Taal wrote:
>>> Hi David,
>>> My confusion, I thought that you were talking about containment
>>> relations.
>>>
>>> An assocation defined like below should not result in delete-orphan
>>> or remove:
>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>> ecore:reference="secmsec:User">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa"> @ManyToMany(indexed=false)
>>> @JoinTable(name="UserRole")</xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:element>
>>>
>>> it should have the cascades (as a default): MERGE, PERSIST, REFRESH
>>> resulting in the following cascades in hbm: MERGE, SAVE-UPDATE,
>>> PERSIST, LOCK, REFRESH
>>>
>>> if you define it as containment, like below, then it has ALL as a
>>> default which results in all, delete-orphan. Which you can override
>>> using annotations in specific cases or globally by setting
>>> CASCADE_POLICY_ON_CONTAINMENT.
>>>
>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>> type="secmsec:User" ecore:opposite="userRole" name="roleUser">
>>> <xsd:annotation>
>>> <xsd:appinfo source="teneo.jpa"> @ManyToMany(indexed=false)
>>> @JoinTable(name="UserRole")</xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:element>
>>>
>>> gr. Martin
>>>
>>> David Wynter wrote:
>>>> Hi Martin,
>>>>
>>>> Do I have to use this annotation at all. This option setting
>>>> suggests that if I correct these tables that are effectively
>>>> controlled vocabularies to all be non containment then this option:
>>>>
>>>> PersistenceOptions.CASCADE_POLICY_ON_NON_CONTAINMENT (default: not
>>>> set): this option allows you to set the default cascade policy for
>>>> non containment relations. It can be set to a comma delimited set of
>>>> cascade values, for example MERGE, PERSIST, REFRESH. If this option
>>>> is not set then then the system will use the following set: MERGE,
>>>> PERSIST, REFRESH.
>>>>
>>>> Suggests the std behaviour should set the correct cascade behaviour.
>>>>
>>>> Thx.
>>>>
>>>> David
>>>>
>>>> Martin Taal wrote:
>>>>> Hi David,
>>>>> In JPA/annotations you have to use an array notation for multiple
>>>>> values, so the correct format is this:
>>>>> @OneToMany(mappedBy="Permission",
>>>>> cascade={PERSIST,MERGE,REFRESH,REMOVE}, indexed=false)
>>>>>
>>>>> In addition a cascade is not a string but an enum (therefore there
>>>>> are no double quotes around the values).
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> David Wynter wrote:
>>>>>> Hi Martin,
>>>>>>
>>>>>> I tried that
>>>>>>
>>>>>> Exception in thread "main"
>>>>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>>>>> Cannot convert 'PERSIST,MERGE,REFRESH,REMOVE' to 'CascadeType' type
>>>>>> at
>>>>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:51)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.teneo.annotations.parser.ComplexNode.convert (ComplexNode.java:92)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:115)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:83)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:72)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:64)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:106)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:57)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.createORM apperFile(GenerateHBM.java:108)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.main(Gene rateHBM.java:79)
>>>>>>
>>>>>> Caused by: java.lang.IllegalArgumentException: The value
>>>>>> 'PERSIST,MERGE,REFRESH,REMOVE' is not a valid enumerator of
>>>>>> 'CascadeType'
>>>>>> at
>>>>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createCascadeTypeFromString(PannotationFactory Impl.java:546)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createFromString(PannotationFactoryImpl.java:1 54)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.ecore.util.EcoreUtil.createFromString(EcoreU til.java:3181)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:40)
>>>>>>
>>>>>> ... 9 more
>>>>>>
>>>>>> Using
>>>>>>
>>>>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>>>>> name="permission" type="xsd:anyURI"
>>>>>> ecore:reference="secmsec:Permission" ecore:opposite="role">
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo
>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>> cascade="PERSIST,MERGE,REFRESH,REMOVE", indexed=false)</xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:element>
>>>>>>
>>>>>> Also used type = "IDREF" not sure of the difference in practice,
>>>>>> seen both used in this context.
>>>>>>
>>>>>> David
>>>>>>
>>>>>>
>>>>>> Martin Taal wrote:
>>>>>>> Hi David,
>>>>>>> Yes the JPA standard does not have a separate annotation for
>>>>>>> delete-orphan, therefore ALL translates to all, delete-orphan. To
>>>>>>> get the behavior you want you need the list all other values:
>>>>>>> MERGE,PERSIST,REFRESH,REMOVE
>>>>>>> instead of using ALL
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> David Wynter wrote:
>>>>>>>> Hi,
>>>>>>>>
>>>>>>>> I followed the example in claims.xsd for preventing a cascade
>>>>>>>> delete. This is for my Permission elements when a parent Role
>>>>>>>> element is deleted. Here is my xsd.
>>>>>>>>
>>>>>>>> <xsd:complexType name="Role">
>>>>>>>> <xsd:sequence minOccurs="0" maxOccurs="1">
>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>> name="permission" type="secmsec:Permission" ecore:opposite="role">
>>>>>>>> <xsd:annotation>
>>>>>>>> <xsd:appinfo
>>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>>> indexed=false cascade="ALL")</xsd:appinfo>
>>>>>>>> </xsd:annotation>
>>>>>>>> </xsd:element>
>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>>>>>>> ecore:reference="secmsec:User">
>>>>>>>> <xsd:annotation>
>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>> @ManyToMany(indexed=false)
>>>>>>>> @JoinTable(name="UserRole")</xsd:appinfo>
>>>>>>>> </xsd:annotation>
>>>>>>>> </xsd:element>
>>>>>>>> </xsd:sequence>
>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>> <xsd:annotation>
>>>>>>>> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
>>>>>>>> </xsd:annotation>
>>>>>>>> </xsd:attribute>
>>>>>>>> <xsd:attribute name="name" type="xsd:string">
>>>>>>>> <xsd:annotation>
>>>>>>>> <xsd:appinfo
>>>>>>>> source="teneo.jpa">@Column(unique=true)</xsd:appinfo>
>>>>>>>> </xsd:annotation>
>>>>>>>> </xsd:attribute>
>>>>>>>> </xsd:complexType>
>>>>>>>>
>>>>>>>> <xsd:complexType name="Permission">
>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>> <xsd:annotation>
>>>>>>>> <xsd:appinfo source="teneo.jpa">@Id
>>>>>>>> @GeneratedValue(strategy=IDENTITY)</xsd:appinfo>
>>>>>>>> </xsd:annotation>
>>>>>>>> </xsd:attribute>
>>>>>>>> <xsd:attribute name="name" type="xsd:string"></xsd:attribute>
>>>>>>>> </xsd:complexType>
>>>>>>>> <xsd:element name="permission"
>>>>>>>> type="secmsec:Permission"></xsd:element>
>>>>>>>>
>>>>>>>> I also tried using a reference
>>>>>>>>
>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>> name="permission" ecore:reference="secmsec:Permission"
>>>>>>>> ecore:opposite="role">
>>>>>>>> <xsd:annotation>
>>>>>>>> <xsd:appinfo
>>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>>> indexed=false cascade="ALL")</xsd:appinfo>
>>>>>>>> </xsd:annotation>
>>>>>>>> </xsd:element>
>>>>>>>>
>>>>>>>> but I always end up with
>>>>>>>>
>>>>>>>> <bag name="permission" inverse="true" lazy="true"
>>>>>>>> cascade="all,delete-orphan">
>>>>>>>> <key update="true" foreign-key="role_permission">
>>>>>>>> <column name="`permission_role_id`"
>>>>>>>> not-null="false" unique="false"/>
>>>>>>>> </key>
>>>>>>>> <one-to-many entity-name="Permission"/>
>>>>>>>> </bag>
>>>>>>>>
>>>>>>>> When what I think is required is cascade="all"
>>>>>>>>
>>>>>>>> What am I missing?
>>>>>>>>
>>>>>>>> Thx.
>>>>>>>>
>>>>>>>> David
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>
>>>
>
>
Re: [Teneo] @OneToMany cascade="ALL" not as expected [message #424621 is a reply to message #424618] Fri, 31 October 2008 12:22 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
With multiple enum values you need curly brackets around them (an array of values).
@OneToMany(mappedBy="Permission", indexed=false, cascade={MERGE,PERSIST,REFRESH})

gr. Martin

David Wynter wrote:
> Hi Martin,
>
> I tried the
>
> <xsd:complexType name="Role">
> <xsd:sequence minOccurs="0" maxOccurs="1">
> <xsd:element minOccurs="0" maxOccurs="unbounded"
> name="permission" ecore:reference="secmsec:Permission"
> ecore:opposite="role">
> <xsd:annotation>
> <xsd:appinfo
> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false,
> cascade=MERGE,PERSIST,REFRESH)</xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
> .....
>
> But get this
>
> Exception in thread "main"
> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption: No =
> character after identifier, see _ for error position
> @OneToMany(mappedBy="Permission", indexed=false,
> cascade=MERGE,PERSIST,_REFRESH)
>
> I was trying to experiment to find out which if any of the cascade enum
> types influence the hibernate definition. After reading this
>
> http://parasjain01.wordpress.com/2008/01/14/orghibernatetran sientobjectexception-object-references-an-unsaved-transient- instance-save-the-transient-instance-before-flushing/
>
>
> I realised I need to had update=”false” insert=”false” set for all the
> tables that contain non transient objects. In another model I have over
> 100 tables that contain controlled vocabularies, which none of the
> tables that have them as a reference by foreign key should ever delete
> or attempt to persist.
>
> Thx.
>
> David
>
>
>
> Martin Taal wrote:
>> Hi David,
>> Yes this was copy-paste posting :-), delete-orphan and manytomany are
>> not logical together.
>>
>> gr. Mmartin
>>
>> David Wynter wrote:
>>> Hi Martin,
>>>
>>> Thanks that clarifies it perfectly. I had tried both types of
>>> relationship, containment and non. I assume you meant to use
>>> @OneToMany in you examples below? According to the Hibernate manual
>>> the ManyToMany do not make sense for non cascade to delete orphan.
>>>
>>> David
>>>
>>> Martin Taal wrote:
>>>> Hi David,
>>>> My confusion, I thought that you were talking about containment
>>>> relations.
>>>>
>>>> An assocation defined like below should not result in delete-orphan
>>>> or remove:
>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>>> ecore:reference="secmsec:User">
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @ManyToMany(indexed=false) @JoinTable(name="UserRole")</xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:element>
>>>>
>>>> it should have the cascades (as a default): MERGE, PERSIST, REFRESH
>>>> resulting in the following cascades in hbm: MERGE, SAVE-UPDATE,
>>>> PERSIST, LOCK, REFRESH
>>>>
>>>> if you define it as containment, like below, then it has ALL as a
>>>> default which results in all, delete-orphan. Which you can override
>>>> using annotations in specific cases or globally by setting
>>>> CASCADE_POLICY_ON_CONTAINMENT.
>>>>
>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>> type="secmsec:User" ecore:opposite="userRole" name="roleUser">
>>>> <xsd:annotation>
>>>> <xsd:appinfo source="teneo.jpa">
>>>> @ManyToMany(indexed=false) @JoinTable(name="UserRole")</xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:element>
>>>>
>>>> gr. Martin
>>>>
>>>> David Wynter wrote:
>>>>> Hi Martin,
>>>>>
>>>>> Do I have to use this annotation at all. This option setting
>>>>> suggests that if I correct these tables that are effectively
>>>>> controlled vocabularies to all be non containment then this option:
>>>>>
>>>>> PersistenceOptions.CASCADE_POLICY_ON_NON_CONTAINMENT (default: not
>>>>> set): this option allows you to set the default cascade policy for
>>>>> non containment relations. It can be set to a comma delimited set
>>>>> of cascade values, for example MERGE, PERSIST, REFRESH. If this
>>>>> option is not set then then the system will use the following set:
>>>>> MERGE, PERSIST, REFRESH.
>>>>>
>>>>> Suggests the std behaviour should set the correct cascade behaviour.
>>>>>
>>>>> Thx.
>>>>>
>>>>> David
>>>>>
>>>>> Martin Taal wrote:
>>>>>> Hi David,
>>>>>> In JPA/annotations you have to use an array notation for multiple
>>>>>> values, so the correct format is this:
>>>>>> @OneToMany(mappedBy="Permission",
>>>>>> cascade={PERSIST,MERGE,REFRESH,REMOVE}, indexed=false)
>>>>>>
>>>>>> In addition a cascade is not a string but an enum (therefore there
>>>>>> are no double quotes around the values).
>>>>>>
>>>>>> gr. Martin
>>>>>>
>>>>>> David Wynter wrote:
>>>>>>> Hi Martin,
>>>>>>>
>>>>>>> I tried that
>>>>>>>
>>>>>>> Exception in thread "main"
>>>>>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>>>>>> Cannot convert 'PERSIST,MERGE,REFRESH,REMOVE' to 'CascadeType' type
>>>>>>> at
>>>>>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:51)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.teneo.annotations.parser.ComplexNode.convert (ComplexNode.java:92)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:115)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:83)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:72)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:64)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:106)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:57)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.createORM apperFile(GenerateHBM.java:108)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.main(Gene rateHBM.java:79)
>>>>>>>
>>>>>>> Caused by: java.lang.IllegalArgumentException: The value
>>>>>>> 'PERSIST,MERGE,REFRESH,REMOVE' is not a valid enumerator of
>>>>>>> 'CascadeType'
>>>>>>> at
>>>>>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createCascadeTypeFromString(PannotationFactory Impl.java:546)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createFromString(PannotationFactoryImpl.java:1 54)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.ecore.util.EcoreUtil.createFromString(EcoreU til.java:3181)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:40)
>>>>>>>
>>>>>>> ... 9 more
>>>>>>>
>>>>>>> Using
>>>>>>>
>>>>>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>>>>>> name="permission" type="xsd:anyURI"
>>>>>>> ecore:reference="secmsec:Permission" ecore:opposite="role">
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo
>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>> cascade="PERSIST,MERGE,REFRESH,REMOVE", indexed=false)</xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>> </xsd:element>
>>>>>>>
>>>>>>> Also used type = "IDREF" not sure of the difference in practice,
>>>>>>> seen both used in this context.
>>>>>>>
>>>>>>> David
>>>>>>>
>>>>>>>
>>>>>>> Martin Taal wrote:
>>>>>>>> Hi David,
>>>>>>>> Yes the JPA standard does not have a separate annotation for
>>>>>>>> delete-orphan, therefore ALL translates to all, delete-orphan.
>>>>>>>> To get the behavior you want you need the list all other values:
>>>>>>>> MERGE,PERSIST,REFRESH,REMOVE
>>>>>>>> instead of using ALL
>>>>>>>>
>>>>>>>> gr. Martin
>>>>>>>>
>>>>>>>> David Wynter wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> I followed the example in claims.xsd for preventing a cascade
>>>>>>>>> delete. This is for my Permission elements when a parent Role
>>>>>>>>> element is deleted. Here is my xsd.
>>>>>>>>>
>>>>>>>>> <xsd:complexType name="Role">
>>>>>>>>> <xsd:sequence minOccurs="0" maxOccurs="1">
>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>> name="permission" type="secmsec:Permission"
>>>>>>>>> ecore:opposite="role">
>>>>>>>>> <xsd:annotation>
>>>>>>>>> <xsd:appinfo
>>>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>>>> indexed=false cascade="ALL")</xsd:appinfo>
>>>>>>>>> </xsd:annotation>
>>>>>>>>> </xsd:element>
>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>>>>>>>> ecore:reference="secmsec:User">
>>>>>>>>> <xsd:annotation>
>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>> @ManyToMany(indexed=false)
>>>>>>>>> @JoinTable(name="UserRole")</xsd:appinfo>
>>>>>>>>> </xsd:annotation>
>>>>>>>>> </xsd:element>
>>>>>>>>> </xsd:sequence>
>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>> <xsd:annotation>
>>>>>>>>> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
>>>>>>>>> </xsd:annotation>
>>>>>>>>> </xsd:attribute>
>>>>>>>>> <xsd:attribute name="name" type="xsd:string">
>>>>>>>>> <xsd:annotation>
>>>>>>>>> <xsd:appinfo
>>>>>>>>> source="teneo.jpa">@Column(unique=true)</xsd:appinfo>
>>>>>>>>> </xsd:annotation>
>>>>>>>>> </xsd:attribute>
>>>>>>>>> </xsd:complexType>
>>>>>>>>>
>>>>>>>>> <xsd:complexType name="Permission">
>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>> <xsd:annotation>
>>>>>>>>> <xsd:appinfo source="teneo.jpa">@Id
>>>>>>>>> @GeneratedValue(strategy=IDENTITY)</xsd:appinfo>
>>>>>>>>> </xsd:annotation>
>>>>>>>>> </xsd:attribute>
>>>>>>>>> <xsd:attribute name="name" type="xsd:string"></xsd:attribute>
>>>>>>>>> </xsd:complexType>
>>>>>>>>> <xsd:element name="permission"
>>>>>>>>> type="secmsec:Permission"></xsd:element>
>>>>>>>>>
>>>>>>>>> I also tried using a reference
>>>>>>>>>
>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>> name="permission" ecore:reference="secmsec:Permission"
>>>>>>>>> ecore:opposite="role">
>>>>>>>>> <xsd:annotation>
>>>>>>>>> <xsd:appinfo
>>>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>>>> indexed=false cascade="ALL")</xsd:appinfo>
>>>>>>>>> </xsd:annotation>
>>>>>>>>> </xsd:element>
>>>>>>>>>
>>>>>>>>> but I always end up with
>>>>>>>>>
>>>>>>>>> <bag name="permission" inverse="true" lazy="true"
>>>>>>>>> cascade="all,delete-orphan">
>>>>>>>>> <key update="true" foreign-key="role_permission">
>>>>>>>>> <column name="`permission_role_id`"
>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>> </key>
>>>>>>>>> <one-to-many entity-name="Permission"/>
>>>>>>>>> </bag>
>>>>>>>>>
>>>>>>>>> When what I think is required is cascade="all"
>>>>>>>>>
>>>>>>>>> What am I missing?
>>>>>>>>>
>>>>>>>>> Thx.
>>>>>>>>>
>>>>>>>>> David
>>>>>>>>
>>>>>>>>
>>>>>>
>>>>>>
>>>>
>>>>
>>
>>


--

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] @OneToMany cascade="ALL" not as expected [message #424629 is a reply to message #424621] Fri, 31 October 2008 15:37 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Thanks, that was a dooh moment.

I still have problems though on my OneToOne relationships. I am using this

<xsd:element minOccurs="0" maxOccurs="1" name="rulesType"
ecore:reference="gensec:RulesType" ecore:opposite="jurisdiction">
<xsd:annotation>
<xsd:appinfo
source="teneo.jpa">@OneToOne(mappedBy="RulesType", indexed=false,
cascade={MERGE,PERSIST,REFRESH})</xsd:appinfo>
</xsd:annotation>
</xsd:element>


Which replaced the original

<xsd:element minOccurs="0" maxOccurs="1" ref="gensec:rulesType" />

Which generates code that allows aJurisdictionInstance.getRuleType()
that returned a RuleType object. But withthe @OneToOne annotation it
returns an EObject which requires a cast.

When I try to run it I get this exception

org.eclipse.emf.teneo.hibernate.HbMapperException: No efeature indexed
for eclass OneToOne

I googled it and found a issue with using a proxy, but found nothing
that explained what causes this.

What I want to achieve is have a set of tables that are 1 to 1 or many
to 1 that are only ever update, deleted or whatever in isolation, not by
a class that has a reference to them. This should prevent the
TransientObjectException too. Am I on the right path?

Thx.

David

Martin Taal wrote:
> Hi David,
> With multiple enum values you need curly brackets around them (an array
> of values).
> @OneToMany(mappedBy="Permission", indexed=false,
> cascade={MERGE,PERSIST,REFRESH})
>
> gr. Martin
>
> David Wynter wrote:
>> Hi Martin,
>>
>> I tried the
>>
>> <xsd:complexType name="Role">
>> <xsd:sequence minOccurs="0" maxOccurs="1">
>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>> name="permission" ecore:reference="secmsec:Permission"
>> ecore:opposite="role">
>> <xsd:annotation>
>> <xsd:appinfo
>> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false,
>> cascade=MERGE,PERSIST,REFRESH)</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>> .....
>>
>> But get this
>>
>> Exception in thread "main"
>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption: No
>> = character after identifier, see _ for error position
>> @OneToMany(mappedBy="Permission", indexed=false,
>> cascade=MERGE,PERSIST,_REFRESH)
>>
>> I was trying to experiment to find out which if any of the cascade
>> enum types influence the hibernate definition. After reading this
>>
>> http://parasjain01.wordpress.com/2008/01/14/orghibernatetran sientobjectexception-object-references-an-unsaved-transient- instance-save-the-transient-instance-before-flushing/
>>
>>
>> I realised I need to had update=”false” insert=”false” set for all the
>> tables that contain non transient objects. In another model I have
>> over 100 tables that contain controlled vocabularies, which none of
>> the tables that have them as a reference by foreign key should ever
>> delete or attempt to persist.
>>
>> Thx.
>>
>> David
>>
>>
>>
>> Martin Taal wrote:
>>> Hi David,
>>> Yes this was copy-paste posting :-), delete-orphan and manytomany are
>>> not logical together.
>>>
>>> gr. Mmartin
>>>
>>> David Wynter wrote:
>>>> Hi Martin,
>>>>
>>>> Thanks that clarifies it perfectly. I had tried both types of
>>>> relationship, containment and non. I assume you meant to use
>>>> @OneToMany in you examples below? According to the Hibernate manual
>>>> the ManyToMany do not make sense for non cascade to delete orphan.
>>>>
>>>> David
>>>>
>>>> Martin Taal wrote:
>>>>> Hi David,
>>>>> My confusion, I thought that you were talking about containment
>>>>> relations.
>>>>>
>>>>> An assocation defined like below should not result in delete-orphan
>>>>> or remove:
>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>>>> ecore:reference="secmsec:User">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @ManyToMany(indexed=false) @JoinTable(name="UserRole")</xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:element>
>>>>>
>>>>> it should have the cascades (as a default): MERGE, PERSIST, REFRESH
>>>>> resulting in the following cascades in hbm: MERGE, SAVE-UPDATE,
>>>>> PERSIST, LOCK, REFRESH
>>>>>
>>>>> if you define it as containment, like below, then it has ALL as a
>>>>> default which results in all, delete-orphan. Which you can override
>>>>> using annotations in specific cases or globally by setting
>>>>> CASCADE_POLICY_ON_CONTAINMENT.
>>>>>
>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>> type="secmsec:User" ecore:opposite="userRole" name="roleUser">
>>>>> <xsd:annotation>
>>>>> <xsd:appinfo source="teneo.jpa">
>>>>> @ManyToMany(indexed=false) @JoinTable(name="UserRole")</xsd:appinfo>
>>>>> </xsd:annotation>
>>>>> </xsd:element>
>>>>>
>>>>> gr. Martin
>>>>>
>>>>> David Wynter wrote:
>>>>>> Hi Martin,
>>>>>>
>>>>>> Do I have to use this annotation at all. This option setting
>>>>>> suggests that if I correct these tables that are effectively
>>>>>> controlled vocabularies to all be non containment then this option:
>>>>>>
>>>>>> PersistenceOptions.CASCADE_POLICY_ON_NON_CONTAINMENT (default:
>>>>>> not set): this option allows you to set the default cascade policy
>>>>>> for non containment relations. It can be set to a comma delimited
>>>>>> set of cascade values, for example MERGE, PERSIST, REFRESH. If
>>>>>> this option is not set then then the system will use the following
>>>>>> set: MERGE, PERSIST, REFRESH.
>>>>>>
>>>>>> Suggests the std behaviour should set the correct cascade behaviour.
>>>>>>
>>>>>> Thx.
>>>>>>
>>>>>> David
>>>>>>
>>>>>> Martin Taal wrote:
>>>>>>> Hi David,
>>>>>>> In JPA/annotations you have to use an array notation for multiple
>>>>>>> values, so the correct format is this:
>>>>>>> @OneToMany(mappedBy="Permission",
>>>>>>> cascade={PERSIST,MERGE,REFRESH,REMOVE}, indexed=false)
>>>>>>>
>>>>>>> In addition a cascade is not a string but an enum (therefore
>>>>>>> there are no double quotes around the values).
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> David Wynter wrote:
>>>>>>>> Hi Martin,
>>>>>>>>
>>>>>>>> I tried that
>>>>>>>>
>>>>>>>> Exception in thread "main"
>>>>>>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>>>>>>> Cannot convert 'PERSIST,MERGE,REFRESH,REMOVE' to 'CascadeType' type
>>>>>>>> at
>>>>>>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:51)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.teneo.annotations.parser.ComplexNode.convert (ComplexNode.java:92)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:115)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:83)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:72)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:64)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:106)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:57)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.createORM apperFile(GenerateHBM.java:108)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.main(Gene rateHBM.java:79)
>>>>>>>>
>>>>>>>> Caused by: java.lang.IllegalArgumentException: The value
>>>>>>>> 'PERSIST,MERGE,REFRESH,REMOVE' is not a valid enumerator of
>>>>>>>> 'CascadeType'
>>>>>>>> at
>>>>>>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createCascadeTypeFromString(PannotationFactory Impl.java:546)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createFromString(PannotationFactoryImpl.java:1 54)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.ecore.util.EcoreUtil.createFromString(EcoreU til.java:3181)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:40)
>>>>>>>>
>>>>>>>> ... 9 more
>>>>>>>>
>>>>>>>> Using
>>>>>>>>
>>>>>>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>>>>>>> name="permission" type="xsd:anyURI"
>>>>>>>> ecore:reference="secmsec:Permission" ecore:opposite="role">
>>>>>>>> <xsd:annotation>
>>>>>>>> <xsd:appinfo
>>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>>> cascade="PERSIST,MERGE,REFRESH,REMOVE",
>>>>>>>> indexed=false)</xsd:appinfo>
>>>>>>>> </xsd:annotation>
>>>>>>>> </xsd:element>
>>>>>>>>
>>>>>>>> Also used type = "IDREF" not sure of the difference in practice,
>>>>>>>> seen both used in this context.
>>>>>>>>
>>>>>>>> David
>>>>>>>>
>>>>>>>>
>>>>>>>> Martin Taal wrote:
>>>>>>>>> Hi David,
>>>>>>>>> Yes the JPA standard does not have a separate annotation for
>>>>>>>>> delete-orphan, therefore ALL translates to all, delete-orphan.
>>>>>>>>> To get the behavior you want you need the list all other values:
>>>>>>>>> MERGE,PERSIST,REFRESH,REMOVE
>>>>>>>>> instead of using ALL
>>>>>>>>>
>>>>>>>>> gr. Martin
>>>>>>>>>
>>>>>>>>> David Wynter wrote:
>>>>>>>>>> Hi,
>>>>>>>>>>
>>>>>>>>>> I followed the example in claims.xsd for preventing a cascade
>>>>>>>>>> delete. This is for my Permission elements when a parent Role
>>>>>>>>>> element is deleted. Here is my xsd.
>>>>>>>>>>
>>>>>>>>>> <xsd:complexType name="Role">
>>>>>>>>>> <xsd:sequence minOccurs="0" maxOccurs="1">
>>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>>> name="permission" type="secmsec:Permission"
>>>>>>>>>> ecore:opposite="role">
>>>>>>>>>> <xsd:annotation>
>>>>>>>>>> <xsd:appinfo
>>>>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>>>>> indexed=false cascade="ALL")</xsd:appinfo>
>>>>>>>>>> </xsd:annotation>
>>>>>>>>>> </xsd:element>
>>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>>>>>>>>> ecore:reference="secmsec:User">
>>>>>>>>>> <xsd:annotation>
>>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>>> @ManyToMany(indexed=false)
>>>>>>>>>> @JoinTable(name="UserRole")</xsd:appinfo>
>>>>>>>>>> </xsd:annotation>
>>>>>>>>>> </xsd:element>
>>>>>>>>>> </xsd:sequence>
>>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>>> <xsd:annotation>
>>>>>>>>>> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
>>>>>>>>>> </xsd:annotation>
>>>>>>>>>> </xsd:attribute>
>>>>>>>>>> <xsd:attribute name="name" type="xsd:string">
>>>>>>>>>> <xsd:annotation>
>>>>>>>>>> <xsd:appinfo
>>>>>>>>>> source="teneo.jpa">@Column(unique=true)</xsd:appinfo>
>>>>>>>>>> </xsd:annotation>
>>>>>>>>>> </xsd:attribute>
>>>>>>>>>> </xsd:complexType>
>>>>>>>>>>
>>>>>>>>>> <xsd:complexType name="Permission">
>>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>>> <xsd:annotation>
>>>>>>>>>> <xsd:appinfo source="teneo.jpa">@Id
>>>>>>>>>> @GeneratedValue(strategy=IDENTITY)</xsd:appinfo>
>>>>>>>>>> </xsd:annotation>
>>>>>>>>>> </xsd:attribute>
>>>>>>>>>> <xsd:attribute name="name" type="xsd:string"></xsd:attribute>
>>>>>>>>>> </xsd:complexType>
>>>>>>>>>> <xsd:element name="permission"
>>>>>>>>>> type="secmsec:Permission"></xsd:element>
>>>>>>>>>>
>>>>>>>>>> I also tried using a reference
>>>>>>>>>>
>>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>>> name="permission" ecore:reference="secmsec:Permission"
>>>>>>>>>> ecore:opposite="role">
>>>>>>>>>> <xsd:annotation>
>>>>>>>>>> <xsd:appinfo
>>>>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>>>>> indexed=false cascade="ALL")</xsd:appinfo>
>>>>>>>>>> </xsd:annotation>
>>>>>>>>>> </xsd:element>
>>>>>>>>>>
>>>>>>>>>> but I always end up with
>>>>>>>>>>
>>>>>>>>>> <bag name="permission" inverse="true" lazy="true"
>>>>>>>>>> cascade="all,delete-orphan">
>>>>>>>>>> <key update="true" foreign-key="role_permission">
>>>>>>>>>> <column name="`permission_role_id`"
>>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>>> </key>
>>>>>>>>>> <one-to-many entity-name="Permission"/>
>>>>>>>>>> </bag>
>>>>>>>>>>
>>>>>>>>>> When what I think is required is cascade="all"
>>>>>>>>>>
>>>>>>>>>> What am I missing?
>>>>>>>>>>
>>>>>>>>>> Thx.
>>>>>>>>>>
>>>>>>>>>> David
>>>>>>>>>
>>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>
>>>
>
>
Re: [Teneo] @OneToMany cascade="ALL" not as expected [message #424664 is a reply to message #424629] Fri, 31 October 2008 17:56 Go to previous messageGo to next message
David Wynter is currently offline David WynterFriend
Messages: 4624
Registered: July 2009
Senior Member
Hi,

Since the alternative seemed to be that I could alter the
hibernate.hbm.xml to have update=”false” insert=”false” were required
and use the original
<xsd:element minOccurs="0" maxOccurs="1" ref="gensec:rulesType" />
which had worked except it gave me the update=”true” insert=”true”

then use the
props.setProperty(PersistenceOptions.USE_MAPPING_FILE, "true");

I thought I might be able to move forward, but instead I get this.

Exception in thread "main" org.hibernate.DuplicateMappingException:
Duplicate class/entity mapping Accretion
at org.hibernate.cfg.Mappings.addClass(Mappings.java:141)

It seems to clash with the code that was previously generated?

I have run out of ideas now on how to get the behaviour I need.

Thx.

David



David Wynter wrote:
> Hi,
>
> Thanks, that was a dooh moment.
>
> I still have problems though on my OneToOne relationships. I am using this
>
> <xsd:element minOccurs="0" maxOccurs="1" name="rulesType"
> ecore:reference="gensec:RulesType" ecore:opposite="jurisdiction">
> <xsd:annotation>
> <xsd:appinfo
> source="teneo.jpa">@OneToOne(mappedBy="RulesType", indexed=false,
> cascade={MERGE,PERSIST,REFRESH})</xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
>
>
> Which replaced the original
>
> <xsd:element minOccurs="0" maxOccurs="1" ref="gensec:rulesType" />
>
> Which generates code that allows aJurisdictionInstance.getRuleType()
> that returned a RuleType object. But withthe @OneToOne annotation it
> returns an EObject which requires a cast.
>
> When I try to run it I get this exception
>
> org.eclipse.emf.teneo.hibernate.HbMapperException: No efeature indexed
> for eclass OneToOne
>
> I googled it and found a issue with using a proxy, but found nothing
> that explained what causes this.
>
> What I want to achieve is have a set of tables that are 1 to 1 or many
> to 1 that are only ever update, deleted or whatever in isolation, not by
> a class that has a reference to them. This should prevent the
> TransientObjectException too. Am I on the right path?
>
> Thx.
>
> David
>
> Martin Taal wrote:
>> Hi David,
>> With multiple enum values you need curly brackets around them (an
>> array of values).
>> @OneToMany(mappedBy="Permission", indexed=false,
>> cascade={MERGE,PERSIST,REFRESH})
>>
>> gr. Martin
>>
>> David Wynter wrote:
>>> Hi Martin,
>>>
>>> I tried the
>>>
>>> <xsd:complexType name="Role">
>>> <xsd:sequence minOccurs="0" maxOccurs="1">
>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>> name="permission" ecore:reference="secmsec:Permission"
>>> ecore:opposite="role">
>>> <xsd:annotation>
>>> <xsd:appinfo
>>> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false,
>>> cascade=MERGE,PERSIST,REFRESH)</xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:element>
>>> .....
>>>
>>> But get this
>>>
>>> Exception in thread "main"
>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>> No = character after identifier, see _ for error position
>>> @OneToMany(mappedBy="Permission", indexed=false,
>>> cascade=MERGE,PERSIST,_REFRESH)
>>>
>>> I was trying to experiment to find out which if any of the cascade
>>> enum types influence the hibernate definition. After reading this
>>>
>>> http://parasjain01.wordpress.com/2008/01/14/orghibernatetran sientobjectexception-object-references-an-unsaved-transient- instance-save-the-transient-instance-before-flushing/
>>>
>>>
>>> I realised I need to had update=”false” insert=”false” set for all
>>> the tables that contain non transient objects. In another model I
>>> have over 100 tables that contain controlled vocabularies, which none
>>> of the tables that have them as a reference by foreign key should
>>> ever delete or attempt to persist.
>>>
>>> Thx.
>>>
>>> David
>>>
>>>
>>>
>>> Martin Taal wrote:
>>>> Hi David,
>>>> Yes this was copy-paste posting :-), delete-orphan and manytomany
>>>> are not logical together.
>>>>
>>>> gr. Mmartin
>>>>
>>>> David Wynter wrote:
>>>>> Hi Martin,
>>>>>
>>>>> Thanks that clarifies it perfectly. I had tried both types of
>>>>> relationship, containment and non. I assume you meant to use
>>>>> @OneToMany in you examples below? According to the Hibernate manual
>>>>> the ManyToMany do not make sense for non cascade to delete orphan.
>>>>>
>>>>> David
>>>>>
>>>>> Martin Taal wrote:
>>>>>> Hi David,
>>>>>> My confusion, I thought that you were talking about containment
>>>>>> relations.
>>>>>>
>>>>>> An assocation defined like below should not result in
>>>>>> delete-orphan or remove:
>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>>>>> ecore:reference="secmsec:User">
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>> @ManyToMany(indexed=false) @JoinTable(name="UserRole")</xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:element>
>>>>>>
>>>>>> it should have the cascades (as a default): MERGE, PERSIST,
>>>>>> REFRESH resulting in the following cascades in hbm: MERGE,
>>>>>> SAVE-UPDATE, PERSIST, LOCK, REFRESH
>>>>>>
>>>>>> if you define it as containment, like below, then it has ALL as a
>>>>>> default which results in all, delete-orphan. Which you can
>>>>>> override using annotations in specific cases or globally by
>>>>>> setting CASCADE_POLICY_ON_CONTAINMENT.
>>>>>>
>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>> type="secmsec:User" ecore:opposite="userRole" name="roleUser">
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>> @ManyToMany(indexed=false) @JoinTable(name="UserRole")</xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:element>
>>>>>>
>>>>>> gr. Martin
>>>>>>
>>>>>> David Wynter wrote:
>>>>>>> Hi Martin,
>>>>>>>
>>>>>>> Do I have to use this annotation at all. This option setting
>>>>>>> suggests that if I correct these tables that are effectively
>>>>>>> controlled vocabularies to all be non containment then this option:
>>>>>>>
>>>>>>> PersistenceOptions.CASCADE_POLICY_ON_NON_CONTAINMENT (default:
>>>>>>> not set): this option allows you to set the default cascade
>>>>>>> policy for non containment relations. It can be set to a comma
>>>>>>> delimited set of cascade values, for example MERGE, PERSIST,
>>>>>>> REFRESH. If this option is not set then then the system will use
>>>>>>> the following set: MERGE, PERSIST, REFRESH.
>>>>>>>
>>>>>>> Suggests the std behaviour should set the correct cascade behaviour.
>>>>>>>
>>>>>>> Thx.
>>>>>>>
>>>>>>> David
>>>>>>>
>>>>>>> Martin Taal wrote:
>>>>>>>> Hi David,
>>>>>>>> In JPA/annotations you have to use an array notation for
>>>>>>>> multiple values, so the correct format is this:
>>>>>>>> @OneToMany(mappedBy="Permission",
>>>>>>>> cascade={PERSIST,MERGE,REFRESH,REMOVE}, indexed=false)
>>>>>>>>
>>>>>>>> In addition a cascade is not a string but an enum (therefore
>>>>>>>> there are no double quotes around the values).
>>>>>>>>
>>>>>>>> gr. Martin
>>>>>>>>
>>>>>>>> David Wynter wrote:
>>>>>>>>> Hi Martin,
>>>>>>>>>
>>>>>>>>> I tried that
>>>>>>>>>
>>>>>>>>> Exception in thread "main"
>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>>>>>>>> Cannot convert 'PERSIST,MERGE,REFRESH,REMOVE' to 'CascadeType'
>>>>>>>>> type
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:51)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.ComplexNode.convert (ComplexNode.java:92)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:115)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:83)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:72)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:64)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:106)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:57)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.createORM apperFile(GenerateHBM.java:108)

>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.main(Gene rateHBM.java:79)
>>>>>>>>>
>>>>>>>>> Caused by: java.lang.IllegalArgumentException: The value
>>>>>>>>> 'PERSIST,MERGE,REFRESH,REMOVE' is not a valid enumerator of
>>>>>>>>> 'CascadeType'
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createCascadeTypeFromString(PannotationFactory Impl.java:546)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createFromString(PannotationFactoryImpl.java:1 54)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.ecore.util.EcoreUtil.createFromString(EcoreU til.java:3181)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:40)
>>>>>>>>>
>>>>>>>>> ... 9 more
>>>>>>>>>
>>>>>>>>> Using
>>>>>>>>>
>>>>>>>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>>>>>>>> name="permission" type="xsd:anyURI"
>>>>>>>>> ecore:reference="secmsec:Permission" ecore:opposite="role">
>>>>>>>>> <xsd:annotation>
>>>>>>>>> <xsd:appinfo
>>>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>>>> cascade="PERSIST,MERGE,REFRESH,REMOVE",
>>>>>>>>> indexed=false)</xsd:appinfo>
>>>>>>>>> </xsd:annotation>
>>>>>>>>> </xsd:element>
>>>>>>>>>
>>>>>>>>> Also used type = "IDREF" not sure of the difference in
>>>>>>>>> practice, seen both used in this context.
>>>>>>>>>
>>>>>>>>> David
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Martin Taal wrote:
>>>>>>>>>> Hi David,
>>>>>>>>>> Yes the JPA standard does not have a separate annotation for
>>>>>>>>>> delete-orphan, therefore ALL translates to all, delete-orphan.
>>>>>>>>>> To get the behavior you want you need the list all other values:
>>>>>>>>>> MERGE,PERSIST,REFRESH,REMOVE
>>>>>>>>>> instead of using ALL
>>>>>>>>>>
>>>>>>>>>> gr. Martin
>>>>>>>>>>
>>>>>>>>>> David Wynter wrote:
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> I followed the example in claims.xsd for preventing a cascade
>>>>>>>>>>> delete. This is for my Permission elements when a parent Role
>>>>>>>>>>> element is deleted. Here is my xsd.
>>>>>>>>>>>
>>>>>>>>>>> <xsd:complexType name="Role">
>>>>>>>>>>> <xsd:sequence minOccurs="0" maxOccurs="1">
>>>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>>>> name="permission" type="secmsec:Permission"
>>>>>>>>>>> ecore:opposite="role">
>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>> <xsd:appinfo
>>>>>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>>>>>> indexed=false cascade="ALL")</xsd:appinfo>
>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>> </xsd:element>
>>>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>>>>>>>>>> ecore:reference="secmsec:User">
>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>>>> @ManyToMany(indexed=false)
>>>>>>>>>>> @JoinTable(name="UserRole")</xsd:appinfo>
>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>> </xsd:element>
>>>>>>>>>>> </xsd:sequence>
>>>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>> </xsd:attribute>
>>>>>>>>>>> <xsd:attribute name="name" type="xsd:string">
>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>> <xsd:appinfo
>>>>>>>>>>> source="teneo.jpa">@Column(unique=true)</xsd:appinfo>
>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>> </xsd:attribute>
>>>>>>>>>>> </xsd:complexType>
>>>>>>>>>>>
>>>>>>>>>>> <xsd:complexType name="Permission">
>>>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>> <xsd:appinfo source="teneo.jpa">@Id
>>>>>>>>>>> @GeneratedValue(strategy=IDENTITY)</xsd:appinfo>
>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>> </xsd:attribute>
>>>>>>>>>>> <xsd:attribute name="name"
>>>>>>>>>>> type="xsd:string"></xsd:attribute>
>>>>>>>>>>> </xsd:complexType>
>>>>>>>>>>> <xsd:element name="permission"
>>>>>>>>>>> type="secmsec:Permission"></xsd:element>
>>>>>>>>>>>
>>>>>>>>>>> I also tried using a reference
>>>>>>>>>>>
>>>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>>>> name="permission" ecore:reference="secmsec:Permission"
>>>>>>>>>>> ecore:opposite="role">
>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>> <xsd:appinfo
>>>>>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>>>>>> indexed=false cascade="ALL")</xsd:appinfo>
>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>> </xsd:element>
>>>>>>>>>>>
>>>>>>>>>>> but I always end up with
>>>>>>>>>>>
>>>>>>>>>>> <bag name="permission" inverse="true" lazy="true"
>>>>>>>>>>> cascade="all,delete-orphan">
>>>>>>>>>>> <key update="true" foreign-key="role_permission">
>>>>>>>>>>> <column name="`permission_role_id`"
>>>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>>>> </key>
>>>>>>>>>>> <one-to-many entity-name="Permission"/>
>>>>>>>>>>> </bag>
>>>>>>>>>>>
>>>>>>>>>>> When what I think is required is cascade="all"
>>>>>>>>>>>
>>>>>>>>>>> What am I missing?
>>>>>>>>>>>
>>>>>>>>>>> Thx.
>>>>>>>>>>>
>>>>>>>>>>> David
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>
>>>>>>
>>>>
>>>>
>>
>>
Re: [Teneo] @OneToMany cascade="ALL" not as expected [message #424665 is a reply to message #424629] Fri, 31 October 2008 19:06 Go to previous messageGo to next message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
To prevent updates from manytoone (A manytoone B) then you should not set a cascade option on the
manytoone or onetoone. However this assumes the entity to which you refer is already persisted. So
you should take care that your program persists B before A. Many times software is structured like
this by itself. For example, if I have a customer order which refers to a business partner (a
manytoone assocation) then 99 out of 100 cases the business partner already exists and is updated
separately.
If you want B to be persisted together with A then you should set cascade option like you do below.

But maybe I did not understand your point. You say that manytoone should be persisted in isolation
and not because of an update of a class that has a reference to them. However, by nature a manytoone
points out (from the many to the one). If the manytoone is unidirectionial then the many is never
updated because of an update of the one. If it is bidirectional then you need to set an annotation
on the one side (in the onetomany on that side) to prevent cascading. However many times it can make
sense to support cascade behavior through a onetomany.

I hope this clear, I am trying to give an answer on what I perceive to be your question (but I am
not sure) :-).

A OneToOne does not support or need indexed, so removing that part of the annotation should solve
the exception you are getting.

The onetoone annotation can not be the cause of the generated code using an EObject. I am not sure
why this happens. If you still see this behavior then you can send a separate post to the newsgroup
so that Ed can react on that one.

gr. Martin

David Wynter wrote:
> Hi,
>
> Thanks, that was a dooh moment.
>
> I still have problems though on my OneToOne relationships. I am using this
>
> <xsd:element minOccurs="0" maxOccurs="1" name="rulesType"
> ecore:reference="gensec:RulesType" ecore:opposite="jurisdiction">
> <xsd:annotation>
> <xsd:appinfo
> source="teneo.jpa">@OneToOne(mappedBy="RulesType", indexed=false,
> cascade={MERGE,PERSIST,REFRESH})</xsd:appinfo>
> </xsd:annotation>
> </xsd:element>
>
>
> Which replaced the original
>
> <xsd:element minOccurs="0" maxOccurs="1" ref="gensec:rulesType" />
>
> Which generates code that allows aJurisdictionInstance.getRuleType()
> that returned a RuleType object. But withthe @OneToOne annotation it
> returns an EObject which requires a cast.
>
> When I try to run it I get this exception
>
> org.eclipse.emf.teneo.hibernate.HbMapperException: No efeature indexed
> for eclass OneToOne
>
> I googled it and found a issue with using a proxy, but found nothing
> that explained what causes this.
>
> What I want to achieve is have a set of tables that are 1 to 1 or many
> to 1 that are only ever update, deleted or whatever in isolation, not by
> a class that has a reference to them. This should prevent the
> TransientObjectException too. Am I on the right path?
>
> Thx.
>
> David
>
> Martin Taal wrote:
>> Hi David,
>> With multiple enum values you need curly brackets around them (an
>> array of values).
>> @OneToMany(mappedBy="Permission", indexed=false,
>> cascade={MERGE,PERSIST,REFRESH})
>>
>> gr. Martin
>>
>> David Wynter wrote:
>>> Hi Martin,
>>>
>>> I tried the
>>>
>>> <xsd:complexType name="Role">
>>> <xsd:sequence minOccurs="0" maxOccurs="1">
>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>> name="permission" ecore:reference="secmsec:Permission"
>>> ecore:opposite="role">
>>> <xsd:annotation>
>>> <xsd:appinfo
>>> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false,
>>> cascade=MERGE,PERSIST,REFRESH)</xsd:appinfo>
>>> </xsd:annotation>
>>> </xsd:element>
>>> .....
>>>
>>> But get this
>>>
>>> Exception in thread "main"
>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>> No = character after identifier, see _ for error position
>>> @OneToMany(mappedBy="Permission", indexed=false,
>>> cascade=MERGE,PERSIST,_REFRESH)
>>>
>>> I was trying to experiment to find out which if any of the cascade
>>> enum types influence the hibernate definition. After reading this
>>>
>>> http://parasjain01.wordpress.com/2008/01/14/orghibernatetran sientobjectexception-object-references-an-unsaved-transient- instance-save-the-transient-instance-before-flushing/
>>>
>>>
>>> I realised I need to had update=”false” insert=”false” set for all
>>> the tables that contain non transient objects. In another model I
>>> have over 100 tables that contain controlled vocabularies, which none
>>> of the tables that have them as a reference by foreign key should
>>> ever delete or attempt to persist.
>>>
>>> Thx.
>>>
>>> David
>>>
>>>
>>>
>>> Martin Taal wrote:
>>>> Hi David,
>>>> Yes this was copy-paste posting :-), delete-orphan and manytomany
>>>> are not logical together.
>>>>
>>>> gr. Mmartin
>>>>
>>>> David Wynter wrote:
>>>>> Hi Martin,
>>>>>
>>>>> Thanks that clarifies it perfectly. I had tried both types of
>>>>> relationship, containment and non. I assume you meant to use
>>>>> @OneToMany in you examples below? According to the Hibernate manual
>>>>> the ManyToMany do not make sense for non cascade to delete orphan.
>>>>>
>>>>> David
>>>>>
>>>>> Martin Taal wrote:
>>>>>> Hi David,
>>>>>> My confusion, I thought that you were talking about containment
>>>>>> relations.
>>>>>>
>>>>>> An assocation defined like below should not result in
>>>>>> delete-orphan or remove:
>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>>>>> ecore:reference="secmsec:User">
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>> @ManyToMany(indexed=false) @JoinTable(name="UserRole")</xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:element>
>>>>>>
>>>>>> it should have the cascades (as a default): MERGE, PERSIST,
>>>>>> REFRESH resulting in the following cascades in hbm: MERGE,
>>>>>> SAVE-UPDATE, PERSIST, LOCK, REFRESH
>>>>>>
>>>>>> if you define it as containment, like below, then it has ALL as a
>>>>>> default which results in all, delete-orphan. Which you can
>>>>>> override using annotations in specific cases or globally by
>>>>>> setting CASCADE_POLICY_ON_CONTAINMENT.
>>>>>>
>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>> type="secmsec:User" ecore:opposite="userRole" name="roleUser">
>>>>>> <xsd:annotation>
>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>> @ManyToMany(indexed=false) @JoinTable(name="UserRole")</xsd:appinfo>
>>>>>> </xsd:annotation>
>>>>>> </xsd:element>
>>>>>>
>>>>>> gr. Martin
>>>>>>
>>>>>> David Wynter wrote:
>>>>>>> Hi Martin,
>>>>>>>
>>>>>>> Do I have to use this annotation at all. This option setting
>>>>>>> suggests that if I correct these tables that are effectively
>>>>>>> controlled vocabularies to all be non containment then this option:
>>>>>>>
>>>>>>> PersistenceOptions.CASCADE_POLICY_ON_NON_CONTAINMENT (default:
>>>>>>> not set): this option allows you to set the default cascade
>>>>>>> policy for non containment relations. It can be set to a comma
>>>>>>> delimited set of cascade values, for example MERGE, PERSIST,
>>>>>>> REFRESH. If this option is not set then then the system will use
>>>>>>> the following set: MERGE, PERSIST, REFRESH.
>>>>>>>
>>>>>>> Suggests the std behaviour should set the correct cascade behaviour.
>>>>>>>
>>>>>>> Thx.
>>>>>>>
>>>>>>> David
>>>>>>>
>>>>>>> Martin Taal wrote:
>>>>>>>> Hi David,
>>>>>>>> In JPA/annotations you have to use an array notation for
>>>>>>>> multiple values, so the correct format is this:
>>>>>>>> @OneToMany(mappedBy="Permission",
>>>>>>>> cascade={PERSIST,MERGE,REFRESH,REMOVE}, indexed=false)
>>>>>>>>
>>>>>>>> In addition a cascade is not a string but an enum (therefore
>>>>>>>> there are no double quotes around the values).
>>>>>>>>
>>>>>>>> gr. Martin
>>>>>>>>
>>>>>>>> David Wynter wrote:
>>>>>>>>> Hi Martin,
>>>>>>>>>
>>>>>>>>> I tried that
>>>>>>>>>
>>>>>>>>> Exception in thread "main"
>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>>>>>>>> Cannot convert 'PERSIST,MERGE,REFRESH,REMOVE' to 'CascadeType'
>>>>>>>>> type
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:51)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.ComplexNode.convert (ComplexNode.java:92)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:115)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:83)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:72)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:64)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:106)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:57)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.createORM apperFile(GenerateHBM.java:108)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.main(Gene rateHBM.java:79)
>>>>>>>>>
>>>>>>>>> Caused by: java.lang.IllegalArgumentException: The value
>>>>>>>>> 'PERSIST,MERGE,REFRESH,REMOVE' is not a valid enumerator of
>>>>>>>>> 'CascadeType'
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createCascadeTypeFromString(PannotationFactory Impl.java:546)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createFromString(PannotationFactoryImpl.java:1 54)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.ecore.util.EcoreUtil.createFromString(EcoreU til.java:3181)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:40)
>>>>>>>>>
>>>>>>>>> ... 9 more
>>>>>>>>>
>>>>>>>>> Using
>>>>>>>>>
>>>>>>>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>>>>>>>> name="permission" type="xsd:anyURI"
>>>>>>>>> ecore:reference="secmsec:Permission" ecore:opposite="role">
>>>>>>>>> <xsd:annotation>
>>>>>>>>> <xsd:appinfo
>>>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>>>> cascade="PERSIST,MERGE,REFRESH,REMOVE",
>>>>>>>>> indexed=false)</xsd:appinfo>
>>>>>>>>> </xsd:annotation>
>>>>>>>>> </xsd:element>
>>>>>>>>>
>>>>>>>>> Also used type = "IDREF" not sure of the difference in
>>>>>>>>> practice, seen both used in this context.
>>>>>>>>>
>>>>>>>>> David
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Martin Taal wrote:
>>>>>>>>>> Hi David,
>>>>>>>>>> Yes the JPA standard does not have a separate annotation for
>>>>>>>>>> delete-orphan, therefore ALL translates to all, delete-orphan.
>>>>>>>>>> To get the behavior you want you need the list all other values:
>>>>>>>>>> MERGE,PERSIST,REFRESH,REMOVE
>>>>>>>>>> instead of using ALL
>>>>>>>>>>
>>>>>>>>>> gr. Martin
>>>>>>>>>>
>>>>>>>>>> David Wynter wrote:
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> I followed the example in claims.xsd for preventing a cascade
>>>>>>>>>>> delete. This is for my Permission elements when a parent Role
>>>>>>>>>>> element is deleted. Here is my xsd.
>>>>>>>>>>>
>>>>>>>>>>> <xsd:complexType name="Role">
>>>>>>>>>>> <xsd:sequence minOccurs="0" maxOccurs="1">
>>>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>>>> name="permission" type="secmsec:Permission"
>>>>>>>>>>> ecore:opposite="role">
>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>> <xsd:appinfo
>>>>>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>>>>>> indexed=false cascade="ALL")</xsd:appinfo>
>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>> </xsd:element>
>>>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>>>>>>>>>> ecore:reference="secmsec:User">
>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>>>> @ManyToMany(indexed=false)
>>>>>>>>>>> @JoinTable(name="UserRole")</xsd:appinfo>
>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>> </xsd:element>
>>>>>>>>>>> </xsd:sequence>
>>>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>> </xsd:attribute>
>>>>>>>>>>> <xsd:attribute name="name" type="xsd:string">
>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>> <xsd:appinfo
>>>>>>>>>>> source="teneo.jpa">@Column(unique=true)</xsd:appinfo>
>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>> </xsd:attribute>
>>>>>>>>>>> </xsd:complexType>
>>>>>>>>>>>
>>>>>>>>>>> <xsd:complexType name="Permission">
>>>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>> <xsd:appinfo source="teneo.jpa">@Id
>>>>>>>>>>> @GeneratedValue(strategy=IDENTITY)</xsd:appinfo>
>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>> </xsd:attribute>
>>>>>>>>>>> <xsd:attribute name="name"
>>>>>>>>>>> type="xsd:string"></xsd:attribute>
>>>>>>>>>>> </xsd:complexType>
>>>>>>>>>>> <xsd:element name="permission"
>>>>>>>>>>> type="secmsec:Permission"></xsd:element>
>>>>>>>>>>>
>>>>>>>>>>> I also tried using a reference
>>>>>>>>>>>
>>>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>>>> name="permission" ecore:reference="secmsec:Permission"
>>>>>>>>>>> ecore:opposite="role">
>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>> <xsd:appinfo
>>>>>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>>>>>> indexed=false cascade="ALL")</xsd:appinfo>
>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>> </xsd:element>
>>>>>>>>>>>
>>>>>>>>>>> but I always end up with
>>>>>>>>>>>
>>>>>>>>>>> <bag name="permission" inverse="true" lazy="true"
>>>>>>>>>>> cascade="all,delete-orphan">
>>>>>>>>>>> <key update="true" foreign-key="role_permission">
>>>>>>>>>>> <column name="`permission_role_id`"
>>>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>>>> </key>
>>>>>>>>>>> <one-to-many entity-name="Permission"/>
>>>>>>>>>>> </bag>
>>>>>>>>>>>
>>>>>>>>>>> When what I think is required is cascade="all"
>>>>>>>>>>>
>>>>>>>>>>> What am I missing?
>>>>>>>>>>>
>>>>>>>>>>> Thx.
>>>>>>>>>>>
>>>>>>>>>>> David
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>
>>>>>>
>>>>
>>>>
>>
>>


--

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] @OneToMany cascade="ALL" not as expected [message #424666 is a reply to message #424664] Fri, 31 October 2008 19:09 Go to previous message
Martin Taal is currently offline Martin TaalFriend
Messages: 5468
Registered: July 2009
Senior Member
Hi David,
You can add a column annotation which has a insertable and updatable attribute. Then you don't need
to change the hbm file manually:
@Column(insertable=true updatable=true)

Also the @JoinColumn annotation has these two attributes.

I am not sure why you get the nameclash, if you set the use_mapping_file option then Teneo does not
generate an in-mem mapping. Maybe there are two hbm files in your output directory tree?

gr. Martin

David Wynter wrote:
> Hi,
>
> Since the alternative seemed to be that I could alter the
> hibernate.hbm.xml to have update=”false” insert=”false” were required
> and use the original
> <xsd:element minOccurs="0" maxOccurs="1" ref="gensec:rulesType" />
> which had worked except it gave me the update=”true” insert=”true”
>
> then use the
> props.setProperty(PersistenceOptions.USE_MAPPING_FILE, "true");
>
> I thought I might be able to move forward, but instead I get this.
>
> Exception in thread "main" org.hibernate.DuplicateMappingException:
> Duplicate class/entity mapping Accretion
> at org.hibernate.cfg.Mappings.addClass(Mappings.java:141)
>
> It seems to clash with the code that was previously generated?
>
> I have run out of ideas now on how to get the behaviour I need.
>
> Thx.
>
> David
>
>
>
> David Wynter wrote:
>> Hi,
>>
>> Thanks, that was a dooh moment.
>>
>> I still have problems though on my OneToOne relationships. I am using
>> this
>>
>> <xsd:element minOccurs="0" maxOccurs="1" name="rulesType"
>> ecore:reference="gensec:RulesType" ecore:opposite="jurisdiction">
>> <xsd:annotation>
>> <xsd:appinfo
>> source="teneo.jpa">@OneToOne(mappedBy="RulesType", indexed=false,
>> cascade={MERGE,PERSIST,REFRESH})</xsd:appinfo>
>> </xsd:annotation>
>> </xsd:element>
>>
>>
>> Which replaced the original
>>
>> <xsd:element minOccurs="0" maxOccurs="1" ref="gensec:rulesType" />
>>
>> Which generates code that allows aJurisdictionInstance.getRuleType()
>> that returned a RuleType object. But withthe @OneToOne annotation it
>> returns an EObject which requires a cast.
>>
>> When I try to run it I get this exception
>>
>> org.eclipse.emf.teneo.hibernate.HbMapperException: No efeature indexed
>> for eclass OneToOne
>> I googled it and found a issue with using a proxy, but found
>> nothing that explained what causes this.
>>
>> What I want to achieve is have a set of tables that are 1 to 1 or many
>> to 1 that are only ever update, deleted or whatever in isolation, not
>> by a class that has a reference to them. This should prevent the
>> TransientObjectException too. Am I on the right path?
>>
>> Thx.
>>
>> David
>>
>> Martin Taal wrote:
>>> Hi David,
>>> With multiple enum values you need curly brackets around them (an
>>> array of values).
>>> @OneToMany(mappedBy="Permission", indexed=false,
>>> cascade={MERGE,PERSIST,REFRESH})
>>>
>>> gr. Martin
>>>
>>> David Wynter wrote:
>>>> Hi Martin,
>>>>
>>>> I tried the
>>>>
>>>> <xsd:complexType name="Role">
>>>> <xsd:sequence minOccurs="0" maxOccurs="1">
>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>> name="permission" ecore:reference="secmsec:Permission"
>>>> ecore:opposite="role">
>>>> <xsd:annotation>
>>>> <xsd:appinfo
>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission", indexed=false,
>>>> cascade=MERGE,PERSIST,REFRESH)</xsd:appinfo>
>>>> </xsd:annotation>
>>>> </xsd:element>
>>>> .....
>>>>
>>>> But get this
>>>>
>>>> Exception in thread "main"
>>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>>> No = character after identifier, see _ for error position
>>>> @OneToMany(mappedBy="Permission", indexed=false,
>>>> cascade=MERGE,PERSIST,_REFRESH)
>>>>
>>>> I was trying to experiment to find out which if any of the cascade
>>>> enum types influence the hibernate definition. After reading this
>>>>
>>>> http://parasjain01.wordpress.com/2008/01/14/orghibernatetran sientobjectexception-object-references-an-unsaved-transient- instance-save-the-transient-instance-before-flushing/
>>>>
>>>>
>>>> I realised I need to had update=”false” insert=”false” set for all
>>>> the tables that contain non transient objects. In another model I
>>>> have over 100 tables that contain controlled vocabularies, which
>>>> none of the tables that have them as a reference by foreign key
>>>> should ever delete or attempt to persist.
>>>>
>>>> Thx.
>>>>
>>>> David
>>>>
>>>>
>>>>
>>>> Martin Taal wrote:
>>>>> Hi David,
>>>>> Yes this was copy-paste posting :-), delete-orphan and manytomany
>>>>> are not logical together.
>>>>>
>>>>> gr. Mmartin
>>>>>
>>>>> David Wynter wrote:
>>>>>> Hi Martin,
>>>>>>
>>>>>> Thanks that clarifies it perfectly. I had tried both types of
>>>>>> relationship, containment and non. I assume you meant to use
>>>>>> @OneToMany in you examples below? According to the Hibernate
>>>>>> manual the ManyToMany do not make sense for non cascade to delete
>>>>>> orphan.
>>>>>>
>>>>>> David
>>>>>>
>>>>>> Martin Taal wrote:
>>>>>>> Hi David,
>>>>>>> My confusion, I thought that you were talking about containment
>>>>>>> relations.
>>>>>>>
>>>>>>> An assocation defined like below should not result in
>>>>>>> delete-orphan or remove:
>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>>>>>> ecore:reference="secmsec:User">
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>> @ManyToMany(indexed=false) @JoinTable(name="UserRole")</xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>> </xsd:element>
>>>>>>>
>>>>>>> it should have the cascades (as a default): MERGE, PERSIST,
>>>>>>> REFRESH resulting in the following cascades in hbm: MERGE,
>>>>>>> SAVE-UPDATE, PERSIST, LOCK, REFRESH
>>>>>>>
>>>>>>> if you define it as containment, like below, then it has ALL as a
>>>>>>> default which results in all, delete-orphan. Which you can
>>>>>>> override using annotations in specific cases or globally by
>>>>>>> setting CASCADE_POLICY_ON_CONTAINMENT.
>>>>>>>
>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>> type="secmsec:User" ecore:opposite="userRole" name="roleUser">
>>>>>>> <xsd:annotation>
>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>> @ManyToMany(indexed=false) @JoinTable(name="UserRole")</xsd:appinfo>
>>>>>>> </xsd:annotation>
>>>>>>> </xsd:element>
>>>>>>>
>>>>>>> gr. Martin
>>>>>>>
>>>>>>> David Wynter wrote:
>>>>>>>> Hi Martin,
>>>>>>>>
>>>>>>>> Do I have to use this annotation at all. This option setting
>>>>>>>> suggests that if I correct these tables that are effectively
>>>>>>>> controlled vocabularies to all be non containment then this
>>>>>>>> option:
>>>>>>>>
>>>>>>>> PersistenceOptions.CASCADE_POLICY_ON_NON_CONTAINMENT (default:
>>>>>>>> not set): this option allows you to set the default cascade
>>>>>>>> policy for non containment relations. It can be set to a comma
>>>>>>>> delimited set of cascade values, for example MERGE, PERSIST,
>>>>>>>> REFRESH. If this option is not set then then the system will use
>>>>>>>> the following set: MERGE, PERSIST, REFRESH.
>>>>>>>>
>>>>>>>> Suggests the std behaviour should set the correct cascade
>>>>>>>> behaviour.
>>>>>>>>
>>>>>>>> Thx.
>>>>>>>>
>>>>>>>> David
>>>>>>>>
>>>>>>>> Martin Taal wrote:
>>>>>>>>> Hi David,
>>>>>>>>> In JPA/annotations you have to use an array notation for
>>>>>>>>> multiple values, so the correct format is this:
>>>>>>>>> @OneToMany(mappedBy="Permission",
>>>>>>>>> cascade={PERSIST,MERGE,REFRESH,REMOVE}, indexed=false)
>>>>>>>>>
>>>>>>>>> In addition a cascade is not a string but an enum (therefore
>>>>>>>>> there are no double quotes around the values).
>>>>>>>>>
>>>>>>>>> gr. Martin
>>>>>>>>>
>>>>>>>>> David Wynter wrote:
>>>>>>>>>> Hi Martin,
>>>>>>>>>>
>>>>>>>>>> I tried that
>>>>>>>>>>
>>>>>>>>>> Exception in thread "main"
>>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.AnnotationParserExc eption:
>>>>>>>>>> Cannot convert 'PERSIST,MERGE,REFRESH,REMOVE' to 'CascadeType'
>>>>>>>>>> type
>>>>>>>>>> at
>>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:51)
>>>>>>>>>>
>>>>>>>>>> at
>>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.ComplexNode.convert (ComplexNode.java:92)
>>>>>>>>>>
>>>>>>>>>> at
>>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.processAnnotatedModelElement(EAnnotationParserImporte r.java:115)
>>>>>>>>>>
>>>>>>>>>> at
>>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:83)
>>>>>>>>>>
>>>>>>>>>> at
>>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:72)
>>>>>>>>>>
>>>>>>>>>> at
>>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.EAnnotationParserIm porter.process(EAnnotationParserImporter.java:64)
>>>>>>>>>>
>>>>>>>>>> at
>>>>>>>>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:106)
>>>>>>>>>>
>>>>>>>>>> at
>>>>>>>>>> org.eclipse.emf.teneo.annotations.mapper.PersistenceMappingB uilder.buildMapping(PersistenceMappingBuilder.java:57)
>>>>>>>>>>
>>>>>>>>>> at
>>>>>>>>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.createORM apperFile(GenerateHBM.java:108)
>
>
>>>>>>>>>>
>>>>>>>>>> at
>>>>>>>>>> org.eclipse.emf.teneo.hibernate.mapper.GenerateHBM.main(Gene rateHBM.java:79)
>>>>>>>>>>
>>>>>>>>>> Caused by: java.lang.IllegalArgumentException: The value
>>>>>>>>>> 'PERSIST,MERGE,REFRESH,REMOVE' is not a valid enumerator of
>>>>>>>>>> 'CascadeType'
>>>>>>>>>> at
>>>>>>>>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createCascadeTypeFromString(PannotationFactory Impl.java:546)
>>>>>>>>>>
>>>>>>>>>> at
>>>>>>>>>> org.eclipse.emf.teneo.annotations.pannotation.impl.Pannotati onFactoryImpl.createFromString(PannotationFactoryImpl.java:1 54)
>>>>>>>>>>
>>>>>>>>>> at
>>>>>>>>>> org.eclipse.emf.ecore.util.EcoreUtil.createFromString(EcoreU til.java:3181)
>>>>>>>>>>
>>>>>>>>>> at
>>>>>>>>>> org.eclipse.emf.teneo.annotations.parser.ParserUtil.convertV alue(ParserUtil.java:40)
>>>>>>>>>>
>>>>>>>>>> ... 9 more
>>>>>>>>>>
>>>>>>>>>> Using
>>>>>>>>>>
>>>>>>>>>> <xsd:element maxOccurs="unbounded" minOccurs="0"
>>>>>>>>>> name="permission" type="xsd:anyURI"
>>>>>>>>>> ecore:reference="secmsec:Permission" ecore:opposite="role">
>>>>>>>>>> <xsd:annotation>
>>>>>>>>>> <xsd:appinfo
>>>>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>>>>> cascade="PERSIST,MERGE,REFRESH,REMOVE",
>>>>>>>>>> indexed=false)</xsd:appinfo>
>>>>>>>>>> </xsd:annotation>
>>>>>>>>>> </xsd:element>
>>>>>>>>>>
>>>>>>>>>> Also used type = "IDREF" not sure of the difference in
>>>>>>>>>> practice, seen both used in this context.
>>>>>>>>>>
>>>>>>>>>> David
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Martin Taal wrote:
>>>>>>>>>>> Hi David,
>>>>>>>>>>> Yes the JPA standard does not have a separate annotation for
>>>>>>>>>>> delete-orphan, therefore ALL translates to all,
>>>>>>>>>>> delete-orphan. To get the behavior you want you need the list
>>>>>>>>>>> all other values:
>>>>>>>>>>> MERGE,PERSIST,REFRESH,REMOVE
>>>>>>>>>>> instead of using ALL
>>>>>>>>>>>
>>>>>>>>>>> gr. Martin
>>>>>>>>>>>
>>>>>>>>>>> David Wynter wrote:
>>>>>>>>>>>> Hi,
>>>>>>>>>>>>
>>>>>>>>>>>> I followed the example in claims.xsd for preventing a
>>>>>>>>>>>> cascade delete. This is for my Permission elements when a
>>>>>>>>>>>> parent Role element is deleted. Here is my xsd.
>>>>>>>>>>>>
>>>>>>>>>>>> <xsd:complexType name="Role">
>>>>>>>>>>>> <xsd:sequence minOccurs="0" maxOccurs="1">
>>>>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>>>>> name="permission" type="secmsec:Permission"
>>>>>>>>>>>> ecore:opposite="role">
>>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>>> <xsd:appinfo
>>>>>>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>>>>>>> indexed=false cascade="ALL")</xsd:appinfo>
>>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>>> </xsd:element>
>>>>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>>>>> type="xsd:anyURI" ecore:opposite="userRole" name="roleUser"
>>>>>>>>>>>> ecore:reference="secmsec:User">
>>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>>> <xsd:appinfo source="teneo.jpa">
>>>>>>>>>>>> @ManyToMany(indexed=false)
>>>>>>>>>>>> @JoinTable(name="UserRole")</xsd:appinfo>
>>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>>> </xsd:element>
>>>>>>>>>>>> </xsd:sequence>
>>>>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>>> <xsd:appinfo source="teneo.jpa">@Id</xsd:appinfo>
>>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>>> </xsd:attribute>
>>>>>>>>>>>> <xsd:attribute name="name" type="xsd:string">
>>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>>> <xsd:appinfo
>>>>>>>>>>>> source="teneo.jpa">@Column(unique=true)</xsd:appinfo>
>>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>>> </xsd:attribute>
>>>>>>>>>>>> </xsd:complexType>
>>>>>>>>>>>>
>>>>>>>>>>>> <xsd:complexType name="Permission">
>>>>>>>>>>>> <xsd:attribute name="id" type="xsd:int">
>>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>>> <xsd:appinfo source="teneo.jpa">@Id
>>>>>>>>>>>> @GeneratedValue(strategy=IDENTITY)</xsd:appinfo>
>>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>>> </xsd:attribute>
>>>>>>>>>>>> <xsd:attribute name="name"
>>>>>>>>>>>> type="xsd:string"></xsd:attribute>
>>>>>>>>>>>> </xsd:complexType>
>>>>>>>>>>>> <xsd:element name="permission"
>>>>>>>>>>>> type="secmsec:Permission"></xsd:element>
>>>>>>>>>>>>
>>>>>>>>>>>> I also tried using a reference
>>>>>>>>>>>>
>>>>>>>>>>>> <xsd:element minOccurs="0" maxOccurs="unbounded"
>>>>>>>>>>>> name="permission" ecore:reference="secmsec:Permission"
>>>>>>>>>>>> ecore:opposite="role">
>>>>>>>>>>>> <xsd:annotation>
>>>>>>>>>>>> <xsd:appinfo
>>>>>>>>>>>> source="teneo.jpa">@OneToMany(mappedBy="Permission",
>>>>>>>>>>>> indexed=false cascade="ALL")</xsd:appinfo>
>>>>>>>>>>>> </xsd:annotation>
>>>>>>>>>>>> </xsd:element>
>>>>>>>>>>>>
>>>>>>>>>>>> but I always end up with
>>>>>>>>>>>>
>>>>>>>>>>>> <bag name="permission" inverse="true" lazy="true"
>>>>>>>>>>>> cascade="all,delete-orphan">
>>>>>>>>>>>> <key update="true" foreign-key="role_permission">
>>>>>>>>>>>> <column name="`permission_role_id`"
>>>>>>>>>>>> not-null="false" unique="false"/>
>>>>>>>>>>>> </key>
>>>>>>>>>>>> <one-to-many entity-name="Permission"/>
>>>>>>>>>>>> </bag>
>>>>>>>>>>>>
>>>>>>>>>>>> When what I think is required is cascade="all"
>>>>>>>>>>>>
>>>>>>>>>>>> What am I missing?
>>>>>>>>>>>>
>>>>>>>>>>>> Thx.
>>>>>>>>>>>>
>>>>>>>>>>>> David
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>
>>>>>>>
>>>>>
>>>>>
>>>
>>>


--

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
Previous Topic:Generate Schema behavior from a genmodel ?
Next Topic:Creating one EMF file of multiple resources
Goto Forum:
  


Current Time: Sat Apr 27 04:02:41 GMT 2024

Powered by FUDForum. Page generated in 0.05249 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top