You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Jeff Melching <jm...@us.ibm.com> on 2008/06/19 16:23:21 UTC
does openjpa support cascade-persist via a persistence-unit-defaults
mapping?
I am trying to create a tool to copy a graph from db backed persistence
storage to human readable form (xml, etc) and then restore that graph back
into the db (whether it exists or not) at a later time. I am having
trouble manipulating the cascading options (cascade-persist/cascade-merge)
for collections at runtime.
I have to manipulate the mappings at runtime because my application will
have different settings than the tool. I tried doing something like this,
but it has no effect on collections:
JPAFacadeHelper.getMetaData(em,
A.class).getField("someSet").setCascadePersist(ValueMetaData.CASCADE_AUTO);
One of the error messages i receive says this:
"Set the cascade attribute for this field to CascadeType.PERSIST or
CascadeType.ALL (JPA annotations) or "persist" or "all" (JPA orm.xml), or
enable cascade-persist globally, or manually persist the related field
value prior to flushing."
How do i enable cascade-persist globally? I thought it might be through
the persistence-unit-defaults, but no dice.
Does openjpa support this? If I include this mapping below in one of my
orm files the parser dies and throws an npe in
XMLPeristenceMetaDataParser:1047 (openjpa 1.1.0).
<persistence-unit-metadata>
<persistence-unit-defaults>
<cascade-persist/>
</persistence-unit-defaults>
</persistence-unit-metadata>
Re: does openjpa support cascade-persist via a
persistence-unit-defaults mapping?
Posted by Pinaki Poddar <pp...@apache.org>.
Hi Craig,
'persist' is already there. 'merge' (and may be 'refresh') sounds good
too.
Agree that 'delete'/'all' will be dangerous :)
The user should also be able to qualify the default cascade behavior per
mapping type i.e. one-to-one, one-to-many etc.
Craig L Russell wrote:
>
> Default cascade merge and persist seem like good things.
>
> Default cascade delete (you didn't mention it here, but for
> completeness) seems wrong.
>
> Craig
>
> On Jun 24, 2008, at 11:05 AM, Pinaki Poddar wrote:
>
>>
>> Hi,
>> Default cascade behavior looks like a useful feature. What do others
>> think?
>>
>> Cascade operations currently are not defaulted.
>>
>> But like many other behavior in OpenJPA, such behavior can be
>> plugged-in.
>>
>> Here is a small class attached to do just that.
>>
>> To activate it, you need to configure persistence.xml as
>> <property name="openjpa.MetaDataFactory"
>> value="cascade.CascadeMappingFactory(cascade='persist,merge')"/>
>>
>> This will, by default, add 'PERSIST" and 'MERGE' to all
>> relationships.
>> You can specify any of the valid CasacdeType enum values in a
>> comma-separated list in 'cascade' attribute
>>
>> http://www.nabble.com/file/p18096612/CascadeMappingFactory.class
>> CascadeMappingFactory.class
>> http://www.nabble.com/file/p18096612/CascadeMappingFactory.java
>> CascadeMappingFactory.java
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/openjpa---DBCP-tp17991707p18096612.html
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>
> Craig Russell
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> 408 276-5638 mailto:Craig.Russell@sun.com
> P.S. A good JDO? O, Gasp!
>
>
>
>
--
View this message in context: http://www.nabble.com/openjpa---DBCP-tp17991707p18098387.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: does openjpa support cascade-persist via a
persistence-unit-defaults mapping?
Posted by Pinaki Poddar <pp...@apache.org>.
> I'd rather see this configuration setting get promoted into JPA2's
> persistence.xml instead of introducing a new setting of our own.
Fully agree.
Raised a request to JPA2.0 spec group.
--
View this message in context: http://n2.nabble.com/openjpa---DBCP-tp210651p220005.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: does openjpa support cascade-persist via a persistence-unit-defaults mapping?
Posted by Patrick Linskey <pl...@gmail.com>.
Note that this is available within the JPA spec via the orm.xml's
persistence-unit-defaults section.
I'd rather see this configuration setting get promoted into JPA2's
persistence.xml instead of introducing a new setting of our own.
(In fact, I'd rather see cascade-persist at least be turned on by
default across the board. I've never understood the desirability of
disabling cascade-persist, and have never gotten a straight answer
from anyone about it.)
-Patrick
On Jun 24, 2008, at 11:17 AM, Craig L Russell wrote:
> Default cascade merge and persist seem like good things.
>
> Default cascade delete (you didn't mention it here, but for
> completeness) seems wrong.
>
> Craig
>
> On Jun 24, 2008, at 11:05 AM, Pinaki Poddar wrote:
>
>>
>> Hi,
>> Default cascade behavior looks like a useful feature. What do others
>> think?
>>
>> Cascade operations currently are not defaulted.
>>
>> But like many other behavior in OpenJPA, such behavior can be
>> plugged-in.
>>
>> Here is a small class attached to do just that.
>>
>> To activate it, you need to configure persistence.xml as
>> <property name="openjpa.MetaDataFactory"
>> value="cascade.CascadeMappingFactory(cascade='persist,merge')"/>
>>
>> This will, by default, add 'PERSIST" and 'MERGE' to all
>> relationships.
>> You can specify any of the valid CasacdeType enum values in a
>> comma-separated list in 'cascade' attribute
>>
>> http://www.nabble.com/file/p18096612/CascadeMappingFactory.class
>> CascadeMappingFactory.class
>> http://www.nabble.com/file/p18096612/CascadeMappingFactory.java
>> CascadeMappingFactory.java
>>
>>
>> --
>> View this message in context: http://www.nabble.com/openjpa---DBCP-tp17991707p18096612.html
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>
> Craig Russell
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> 408 276-5638 mailto:Craig.Russell@sun.com
> P.S. A good JDO? O, Gasp!
>
--
Patrick Linskey
202 669 5907
Re: does openjpa support cascade-persist via a persistence-unit-defaults mapping?
Posted by Patrick Linskey <pl...@gmail.com>.
Note that this is available within the JPA spec via the orm.xml's
persistence-unit-defaults section.
I'd rather see this configuration setting get promoted into JPA2's
persistence.xml instead of introducing a new setting of our own.
(In fact, I'd rather see cascade-persist at least be turned on by
default across the board. I've never understood the desirability of
disabling cascade-persist, and have never gotten a straight answer
from anyone about it.)
-Patrick
On Jun 24, 2008, at 11:17 AM, Craig L Russell wrote:
> Default cascade merge and persist seem like good things.
>
> Default cascade delete (you didn't mention it here, but for
> completeness) seems wrong.
>
> Craig
>
> On Jun 24, 2008, at 11:05 AM, Pinaki Poddar wrote:
>
>>
>> Hi,
>> Default cascade behavior looks like a useful feature. What do others
>> think?
>>
>> Cascade operations currently are not defaulted.
>>
>> But like many other behavior in OpenJPA, such behavior can be
>> plugged-in.
>>
>> Here is a small class attached to do just that.
>>
>> To activate it, you need to configure persistence.xml as
>> <property name="openjpa.MetaDataFactory"
>> value="cascade.CascadeMappingFactory(cascade='persist,merge')"/>
>>
>> This will, by default, add 'PERSIST" and 'MERGE' to all
>> relationships.
>> You can specify any of the valid CasacdeType enum values in a
>> comma-separated list in 'cascade' attribute
>>
>> http://www.nabble.com/file/p18096612/CascadeMappingFactory.class
>> CascadeMappingFactory.class
>> http://www.nabble.com/file/p18096612/CascadeMappingFactory.java
>> CascadeMappingFactory.java
>>
>>
>> --
>> View this message in context: http://www.nabble.com/openjpa---DBCP-tp17991707p18096612.html
>> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>>
>
> Craig Russell
> Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
> 408 276-5638 mailto:Craig.Russell@sun.com
> P.S. A good JDO? O, Gasp!
>
--
Patrick Linskey
202 669 5907
Re: does openjpa support cascade-persist via a
persistence-unit-defaults mapping?
Posted by Craig L Russell <Cr...@Sun.COM>.
Default cascade merge and persist seem like good things.
Default cascade delete (you didn't mention it here, but for
completeness) seems wrong.
Craig
On Jun 24, 2008, at 11:05 AM, Pinaki Poddar wrote:
>
> Hi,
> Default cascade behavior looks like a useful feature. What do others
> think?
>
> Cascade operations currently are not defaulted.
>
> But like many other behavior in OpenJPA, such behavior can be
> plugged-in.
>
> Here is a small class attached to do just that.
>
> To activate it, you need to configure persistence.xml as
> <property name="openjpa.MetaDataFactory"
> value="cascade.CascadeMappingFactory(cascade='persist,merge')"/>
>
> This will, by default, add 'PERSIST" and 'MERGE' to all
> relationships.
> You can specify any of the valid CasacdeType enum values in a
> comma-separated list in 'cascade' attribute
>
> http://www.nabble.com/file/p18096612/CascadeMappingFactory.class
> CascadeMappingFactory.class
> http://www.nabble.com/file/p18096612/CascadeMappingFactory.java
> CascadeMappingFactory.java
>
>
> --
> View this message in context: http://www.nabble.com/openjpa---DBCP-tp17991707p18096612.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!
Re: does openjpa support cascade-persist via a
persistence-unit-defaults mapping?
Posted by Craig L Russell <Cr...@Sun.COM>.
Default cascade merge and persist seem like good things.
Default cascade delete (you didn't mention it here, but for
completeness) seems wrong.
Craig
On Jun 24, 2008, at 11:05 AM, Pinaki Poddar wrote:
>
> Hi,
> Default cascade behavior looks like a useful feature. What do others
> think?
>
> Cascade operations currently are not defaulted.
>
> But like many other behavior in OpenJPA, such behavior can be
> plugged-in.
>
> Here is a small class attached to do just that.
>
> To activate it, you need to configure persistence.xml as
> <property name="openjpa.MetaDataFactory"
> value="cascade.CascadeMappingFactory(cascade='persist,merge')"/>
>
> This will, by default, add 'PERSIST" and 'MERGE' to all
> relationships.
> You can specify any of the valid CasacdeType enum values in a
> comma-separated list in 'cascade' attribute
>
> http://www.nabble.com/file/p18096612/CascadeMappingFactory.class
> CascadeMappingFactory.class
> http://www.nabble.com/file/p18096612/CascadeMappingFactory.java
> CascadeMappingFactory.java
>
>
> --
> View this message in context: http://www.nabble.com/openjpa---DBCP-tp17991707p18096612.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>
Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:Craig.Russell@sun.com
P.S. A good JDO? O, Gasp!
Re: does openjpa support cascade-persist via a
persistence-unit-defaults mapping?
Posted by Pinaki Poddar <pp...@apache.org>.
Hi,
Default cascade behavior looks like a useful feature. What do others
think?
Cascade operations currently are not defaulted.
But like many other behavior in OpenJPA, such behavior can be plugged-in.
Here is a small class attached to do just that.
To activate it, you need to configure persistence.xml as
<property name="openjpa.MetaDataFactory"
value="cascade.CascadeMappingFactory(cascade='persist,merge')"/>
This will, by default, add 'PERSIST" and 'MERGE' to all relationships.
You can specify any of the valid CasacdeType enum values in a
comma-separated list in 'cascade' attribute
http://www.nabble.com/file/p18096612/CascadeMappingFactory.class
CascadeMappingFactory.class
http://www.nabble.com/file/p18096612/CascadeMappingFactory.java
CascadeMappingFactory.java
--
View this message in context: http://www.nabble.com/openjpa---DBCP-tp17991707p18096612.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Re: does openjpa support cascade-persist via a persistence-unit-defaults
mapping?
Posted by Jeff Melching <jm...@us.ibm.com>.
didn't hear any responses on this. Anyway to add a cascade-persist at
runtime to a mapping or all mappings?
From:
Jeff Melching/St Louis/IBM@IBMUS
To:
users@openjpa.apache.org
Date:
06/19/2008 09:32 AM
Subject:
does openjpa support cascade-persist via a persistence-unit-defaults
mapping?
I am trying to create a tool to copy a graph from db backed persistence
storage to human readable form (xml, etc) and then restore that graph back
into the db (whether it exists or not) at a later time. I am having
trouble manipulating the cascading options (cascade-persist/cascade-merge)
for collections at runtime.
I have to manipulate the mappings at runtime because my application will
have different settings than the tool. I tried doing something like this,
but it has no effect on collections:
JPAFacadeHelper.getMetaData(em,
A.class).getField("someSet").setCascadePersist(ValueMetaData.CASCADE_AUTO);
One of the error messages i receive says this:
"Set the cascade attribute for this field to CascadeType.PERSIST or
CascadeType.ALL (JPA annotations) or "persist" or "all" (JPA orm.xml), or
enable cascade-persist globally, or manually persist the related field
value prior to flushing."
How do i enable cascade-persist globally? I thought it might be through
the persistence-unit-defaults, but no dice.
Does openjpa support this? If I include this mapping below in one of my
orm files the parser dies and throws an npe in
XMLPeristenceMetaDataParser:1047 (openjpa 1.1.0).
<persistence-unit-metadata>
<persistence-unit-defaults>
<cascade-persist/>
</persistence-unit-defaults>
</persistence-unit-metadata>
Re: does openjpa support cascade-persist via a
persistence-unit-defaults mapping?
Posted by Pinaki Poddar <pp...@apache.org>.
> How do i enable cascade-persist globally? I thought it might be through
the persistence-unit-defaults, but no dice.
You thought right.
> Does openjpa support this?
Yes.
> If I include this mapping below in one of my orm files the parser dies and
> throws an npe in
> XMLPeristenceMetaDataParser:1047 (openjpa 1.1.0).
<persistence-unit-metadata>
<persistence-unit-defaults>
<cascade-persist/>
</persistence-unit-defaults>
</persistence-unit-metadata>
Can you post the mapping file and the entity Java files? I just verified the
behavior of setting cascade-persist globally but does not seem to reproduce
the NPE...
--
View this message in context: http://www.nabble.com/openjpa---DBCP-tp17991707p18098300.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.