You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by Jean-Baptiste BRIAUD -- Novlog <j-...@novlog.com> on 2010/04/02 12:15:05 UTC

Lack of foreign key constraint

Hi,

I just noticed that on the SQL file produced by OpenJPA to install DB schema, there are no integrity referential constraints.
In other words, on relationship, there is no indication that one column is a foreign key.
primary key are there but not foreign keys.

Is it a problem (I didn't found any issue with that before I noticed) ?
Can I force that to be generated ?

I tested that using MySQL and SqlServer, same behavior : no foreign key constraints generated in SQL file.
I'm using 2.0 beta 2 and will migrate to beta 3 very soon.

Any idea ?


Re: Lack of foreign key constraint

Posted by Michael Dick <mi...@gmail.com>.
Hi Jean-Baptiste,

Historically OpenJPA does not create a FK constraint by default. You can
indicate that one should be created by adding the @ForeignKey annotation
(OpenJPA specific) to your entity classes. The schema tool and related tools
will 'manipulate' foreign keys, but I don't remember seeing them create a
FK.

Once you have the FK constraints set up OpenJPA will recognize them if
either of these are true :
* If the annotation is present in your entities
* You've set the Schema Factory to 'native'.

More information in the manual at
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_mapping_jpa_fk
http://openjpa.apache.org/builds/latest/docs/manual/manual.html#ref_guide_schema_info_factory

Hope this helps,
-mike

On Fri, Apr 2, 2010 at 4:15 AM, Jean-Baptiste BRIAUD -- Novlog <
j-b.briaud@novlog.com> wrote:

> Hi,
>
> I just noticed that on the SQL file produced by OpenJPA to install DB
> schema, there are no integrity referential constraints.
> In other words, on relationship, there is no indication that one column is
> a foreign key.
> primary key are there but not foreign keys.
>
> Is it a problem (I didn't found any issue with that before I noticed) ?
> Can I force that to be generated ?
>
> I tested that using MySQL and SqlServer, same behavior : no foreign key
> constraints generated in SQL file.
> I'm using 2.0 beta 2 and will migrate to beta 3 very soon.
>
> Any idea ?
>
>