You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by "Patrick Linskey (JIRA)" <ji...@apache.org> on 2007/11/06 18:10:50 UTC

[jira] Created: (OPENJPA-435) Change mapping defaults to assume foreign keys exist for relationships by default

Change mapping defaults to assume foreign keys exist for relationships by default
---------------------------------------------------------------------------------

                 Key: OPENJPA-435
                 URL: https://issues.apache.org/jira/browse/OPENJPA-435
             Project: OpenJPA
          Issue Type: Improvement
          Components: sql
    Affects Versions: 1.0.0, 0.9.7, 0.9.6, 0.9.0, 1.0.1, 1.0.2, 1.1.0
            Reporter: Patrick Linskey
             Fix For: 1.1.0


OpenJPA's current defaults assume that no foreign keys exist. This leads to potentially more optimal SQL ordering, but often also leads to FK constraint violations when obvious FKs exist but are not declared. We should change this default to be more user-friendly, and add a note to our optimization guide as appropriate if there are actions users should take to optimize.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-435) Change mapping defaults to assume foreign keys exist for relationships by default

Posted by "Patrick Linskey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12540490 ] 

Patrick Linskey commented on OPENJPA-435:
-----------------------------------------

I believe that this can be worked around in the short term by setting the MappingDefaults ForeignKeyDeleteAction and JoinForeignKeyDeleteAction properties to 'restrict':

<property name="openjpa.MappingDefaults" 
    value="ForeignKeyDeleteAction=restrict, JoinForeignKeyDeleteAction=restrict"/>

Could someone who is seeing this behavior in their app give this a try and comment on this issue, please?

> Change mapping defaults to assume foreign keys exist for relationships by default
> ---------------------------------------------------------------------------------
>
>                 Key: OPENJPA-435
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-435
>             Project: OpenJPA
>          Issue Type: Improvement
>          Components: sql
>    Affects Versions: 0.9.0, 0.9.6, 0.9.7, 1.0.0, 1.0.1, 1.0.2, 1.1.0
>            Reporter: Patrick Linskey
>             Fix For: 1.1.0
>
>
> OpenJPA's current defaults assume that no foreign keys exist. This leads to potentially more optimal SQL ordering, but often also leads to FK constraint violations when obvious FKs exist but are not declared. We should change this default to be more user-friendly, and add a note to our optimization guide as appropriate if there are actions users should take to optimize.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-435) Change mapping defaults to assume foreign keys exist for relationships by default

Posted by "Patrick Linskey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-435?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Patrick Linskey updated OPENJPA-435:
------------------------------------

    Comment: was deleted

> Change mapping defaults to assume foreign keys exist for relationships by default
> ---------------------------------------------------------------------------------
>
>                 Key: OPENJPA-435
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-435
>             Project: OpenJPA
>          Issue Type: Improvement
>          Components: sql
>    Affects Versions: 0.9.0, 0.9.6, 0.9.7, 1.0.0, 1.0.1, 1.0.2, 1.1.0
>            Reporter: Patrick Linskey
>             Fix For: 1.1.0
>
>
> OpenJPA's current defaults assume that no foreign keys exist. This leads to potentially more optimal SQL ordering, but often also leads to FK constraint violations when obvious FKs exist but are not declared. We should change this default to be more user-friendly, and add a note to our optimization guide as appropriate if there are actions users should take to optimize.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-435) Change mapping defaults to assume foreign keys exist for relationships by default

Posted by "Michael Dick (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-435?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Michael Dick updated OPENJPA-435:
---------------------------------

    Fix Version/s:     (was: 1.2.0)
                   1.3.0

Moving to next release

> Change mapping defaults to assume foreign keys exist for relationships by default
> ---------------------------------------------------------------------------------
>
>                 Key: OPENJPA-435
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-435
>             Project: OpenJPA
>          Issue Type: Improvement
>          Components: sql
>    Affects Versions: 0.9.0, 0.9.6, 0.9.7, 1.0.0, 1.0.1, 1.0.2, 1.1.0
>            Reporter: Patrick Linskey
>             Fix For: 1.3.0
>
>
> OpenJPA's current defaults assume that no foreign keys exist. This leads to potentially more optimal SQL ordering, but often also leads to FK constraint violations when obvious FKs exist but are not declared. We should change this default to be more user-friendly, and add a note to our optimization guide as appropriate if there are actions users should take to optimize.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-435) Change mapping defaults to assume foreign keys exist for relationships by default

Posted by "Willis Blackburn (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12914841#action_12914841 ] 

Willis Blackburn commented on OPENJPA-435:
------------------------------------------

+1!

It doesn't seem logical to assume that FKs don't exist.

Reason #1:  They usually do!  Let's assume that people using OpenJPA are intelligent and are designing production-quality databases.  Of course they're going to have FKs.

Reason #2:  The strategy of querying the database to discover the FKs seems at odds with the general JPA strategy of declaring the database metadata in code.  We let the code define the database, not vice-versa.

Reason #3:  It leads to the fewest surprises.  Consider:

    OpenJPA assumes FKs don't exist, and they don't:  OK
    OpenJPA assumes FKs don't exist, and they do:  FAIL!
    OpenJPA assumes FKs exist, and they don't:  No worries!
    OpenJPA assumes FKs exist, and they do:  OK



> Change mapping defaults to assume foreign keys exist for relationships by default
> ---------------------------------------------------------------------------------
>
>                 Key: OPENJPA-435
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-435
>             Project: OpenJPA
>          Issue Type: Improvement
>          Components: sql
>    Affects Versions: 0.9.0, 0.9.6, 0.9.7, 1.0.0, 1.0.1, 1.0.2, 1.1.0
>            Reporter: Patrick Linskey
>             Fix For: 1.3.0
>
>
> OpenJPA's current defaults assume that no foreign keys exist. This leads to potentially more optimal SQL ordering, but often also leads to FK constraint violations when obvious FKs exist but are not declared. We should change this default to be more user-friendly, and add a note to our optimization guide as appropriate if there are actions users should take to optimize.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (OPENJPA-435) Change mapping defaults to assume foreign keys exist for relationships by default

Posted by "Patrick Linskey (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12540492 ] 

Patrick Linskey commented on OPENJPA-435:
-----------------------------------------

I believe that this can be worked around in the short term by setting the MappingDefaults ForeignKeyDeleteAction and JoinForeignKeyDeleteAction properties to 'restrict':

<property name="openjpa.jdbc.MappingDefaults"
    value="ForeignKeyDeleteAction=restrict, JoinForeignKeyDeleteAction=restrict"/>

Could someone who is seeing this behavior in their app give this a try and comment on this issue, please?

Of course, another workaround is to tell OpenJPA to look for foreign key constraints in the database. This can be quite slow, though. FTR, you can do this like so:

<property name="openjpa.jdbc.SchemaFactory" value="native(ForeignKeys=true)"/>

> Change mapping defaults to assume foreign keys exist for relationships by default
> ---------------------------------------------------------------------------------
>
>                 Key: OPENJPA-435
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-435
>             Project: OpenJPA
>          Issue Type: Improvement
>          Components: sql
>    Affects Versions: 0.9.0, 0.9.6, 0.9.7, 1.0.0, 1.0.1, 1.0.2, 1.1.0
>            Reporter: Patrick Linskey
>             Fix For: 1.1.0
>
>
> OpenJPA's current defaults assume that no foreign keys exist. This leads to potentially more optimal SQL ordering, but often also leads to FK constraint violations when obvious FKs exist but are not declared. We should change this default to be more user-friendly, and add a note to our optimization guide as appropriate if there are actions users should take to optimize.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Re: [jira] Commented: (OPENJPA-435) Change mapping defaults to assume foreign keys exist for relationships by default

Posted by Patrick Linskey <pl...@gmail.com>.
Hi,

OPENJPA-435 discusses changing the default foreign key behavior to  
assume RESTRICT constraints on all foreign keys. This is different  
than OpenJPA's current behavior, which assumes no foreign keys by  
default.

I think that we should change this default in OpenJPA 1.1.0, and  
include a new Compatibility flag to turn on the old behavior. Thoughts?

-Patrick

On Nov 6, 2007, at 9:38 PM, Prashant Bhat (JIRA) wrote:

>
>    [ https://issues.apache.org/jira/browse/OPENJPA-435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel 
> #action_12540672 ]
>
> Prashant Bhat commented on OPENJPA-435:
> ---------------------------------------
>
> I'm using the first option for mapping tool and also during  
> entityManagerFactory creation:
> <property name="openjpa.jdbc.MappingDefaults"
>    value="ForeignKeyDeleteAction=restrict,  
> JoinForeignKeyDeleteAction=restrict"/>
>
> And for me it's working perfectly with all constraints and I agree  
> that changing the default behaviour to this makes it a lot easier  
> for beginners(as I had the same issue and the manual was not very  
> clear for me then! May be it's updated now)
>
> Regards,
> Prashant
>
>
>> Change mapping defaults to assume foreign keys exist for  
>> relationships by default
>> ---------------------------------------------------------------------------------
>>
>>                Key: OPENJPA-435
>>                URL: https://issues.apache.org/jira/browse/OPENJPA-435
>>            Project: OpenJPA
>>         Issue Type: Improvement
>>         Components: sql
>>   Affects Versions: 0.9.0, 0.9.6, 0.9.7, 1.0.0, 1.0.1, 1.0.2, 1.1.0
>>           Reporter: Patrick Linskey
>>            Fix For: 1.1.0
>>
>>
>> OpenJPA's current defaults assume that no foreign keys exist. This  
>> leads to potentially more optimal SQL ordering, but often also  
>> leads to FK constraint violations when obvious FKs exist but are  
>> not declared. We should change this default to be more user- 
>> friendly, and add a note to our optimization guide as appropriate  
>> if there are actions users should take to optimize.
>
> -- 
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>

-- 
Patrick Linskey
202 669 5907





[jira] Commented: (OPENJPA-435) Change mapping defaults to assume foreign keys exist for relationships by default

Posted by "Prashant Bhat (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/OPENJPA-435?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12540672 ] 

Prashant Bhat commented on OPENJPA-435:
---------------------------------------

I'm using the first option for mapping tool and also during entityManagerFactory creation:
<property name="openjpa.jdbc.MappingDefaults"
    value="ForeignKeyDeleteAction=restrict, JoinForeignKeyDeleteAction=restrict"/> 

And for me it's working perfectly with all constraints and I agree that changing the default behaviour to this makes it a lot easier for beginners(as I had the same issue and the manual was not very clear for me then! May be it's updated now)

Regards,
Prashant


> Change mapping defaults to assume foreign keys exist for relationships by default
> ---------------------------------------------------------------------------------
>
>                 Key: OPENJPA-435
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-435
>             Project: OpenJPA
>          Issue Type: Improvement
>          Components: sql
>    Affects Versions: 0.9.0, 0.9.6, 0.9.7, 1.0.0, 1.0.1, 1.0.2, 1.1.0
>            Reporter: Patrick Linskey
>             Fix For: 1.1.0
>
>
> OpenJPA's current defaults assume that no foreign keys exist. This leads to potentially more optimal SQL ordering, but often also leads to FK constraint violations when obvious FKs exist but are not declared. We should change this default to be more user-friendly, and add a note to our optimization guide as appropriate if there are actions users should take to optimize.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (OPENJPA-435) Change mapping defaults to assume foreign keys exist for relationships by default

Posted by "Patrick Linskey (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/OPENJPA-435?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Patrick Linskey updated OPENJPA-435:
------------------------------------

    Fix Version/s:     (was: 1.1.0)
                   1.2.0

> Change mapping defaults to assume foreign keys exist for relationships by default
> ---------------------------------------------------------------------------------
>
>                 Key: OPENJPA-435
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-435
>             Project: OpenJPA
>          Issue Type: Improvement
>          Components: sql
>    Affects Versions: 0.9.0, 0.9.6, 0.9.7, 1.0.0, 1.0.1, 1.0.2, 1.1.0
>            Reporter: Patrick Linskey
>             Fix For: 1.2.0
>
>
> OpenJPA's current defaults assume that no foreign keys exist. This leads to potentially more optimal SQL ordering, but often also leads to FK constraint violations when obvious FKs exist but are not declared. We should change this default to be more user-friendly, and add a note to our optimization guide as appropriate if there are actions users should take to optimize.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.