openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From James Carman <ja...@carmanconsulting.com>
Subject Re: No foreign keys created by openJPA
Date Sun, 10 Feb 2013 06:30:17 GMT
Sounds like a bug to me.

On Saturday, February 9, 2013, seba.wagner@gmail.com wrote:

> Yes,
>
> from my point of view having:
> <property name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema(ForeignKeys=true)"/>
> <property name="openjpa.jdbc.SchemaFactory"
> value="native(ForeignKeys=true)"/>
>
> or just:
> <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
>
> has simply no effect at all.
> Attributes with ManyToOne or OneToMany relations have no FKs created in the
> database. Only Indices.
> You have to actively annotate every single attribute with @ForeignKey.
> There is no other way of telling OpenJPA to create a foreign key.
> The docs also say not much about it:
>
> http://people.apache.org/~mikedd/nightly.builds/apache-openjpa-2.3.0-SNAPSHOT/docs/docbook/manual.html#ref_guide_mapping_synch
>
> You can enable or disable it. An attribute "(ForeignKeys=true)" seems to be
> not known to the Synchronize mappings.
> Maybe that would be something like a feature request:
> "Automatically created ForeignKeys in runtime forward mapping for
> @ManyToOne relations."
>
> In the meantime we will have to annotate every attribute with @ForeignKey.
>
> Sebastian
>
> 2013/2/7 Maxim Solodovnik <solomax666@gmail.com <javascript:;>>
>
> > I'm afraid the answer below mean we need to annotate everything
> explicitly
> >
> > ---------- Forwarded message ----------
> > From: Kevin Sutter <kwsutter@gmail.com>
> > Date: Wed, Feb 6, 2013 at 9:33 PM
> > Subject: Re: No foreign keys created by openJPA
> > To: Maxim Solodovnik <solomax666@gmail.com>
> > Cc: users@openjpa.apache.org
> >
> >
> > Hi guys,
> > I didn't see the properties being used in the persistence.xml file that
> you
> > posted...
> >
> > But, in any case, these properties are mainly used for reading foreign
> key
> > information from the database.  During the table mapping processing,
> there
> > may be some verification of foreign key constraints as well.  This allows
> > OpenJPA to make more intelligent decisions when submitting SQL statements
> > in batch to avoid constraint collisions.
> >
> > If you are looking for explicit foreign key specifications, then you'll
> > probably have to use the @ForeignKey annotation.
> >
> > Hope this helps,
> > Kevin
> >
> >
> > On Tue, Feb 5, 2013 at 10:00 PM, Maxim Solodovnik <solomax666@gmail.com
> > >wrote:
> >
> > > Hello Kevin,
> > >
> > > I just test both properties (added to the persistence.xml) on MySQL 5.5
> > > (InnoDB)
> > > and foreign keys were created only for the fields annotated with
> > > @ForeignKey :(
> > > Is it expected behavior?
> > >
> > > openJPA version is 2.2.1
> > >
> > > foreign keys were checked with following SQL:
> > > SELECT * FROM information_schema.TABLE_CONSTRAINTS WHERE
> > > information_schema.TABLE_CONSTRAINTS.CONSTRAINT_TYPE = 'FOREIGN KEY';
> > >
> > > properties were added to the following xml:
> > >
> > >
> >
> https://svn.apache.org/repos/asf/openmeetings/trunk/singlewebapp/src/META-INF/mysql_persistence.xml
> > >
> > >
> > > Thanks in advance for your help
> > >
> > >
> > > On Tue, Feb 5, 2013 at 9:58 PM, Kevin Sutter <kwsutter@gmail.com>
> wrote:
> > >
> > >> Hi Sebastian,
> > >> There are two ways to get the ForeignKeys automatically processed.
> > >>
> > >> <property name="openjpa.jdbc.SynchronizeMappings"
> > >> value="buildSchema(ForeignKeys=true)"/>
> > >>
> > >> Since you were already using a variation of this property, maybe this
> is
> > >> the easiest mechanism.  A very similar capability is provided by the
> > >> Schema
> > >> Factory [1]:
> > >>
> > >> <property name="openjpa.jdbc.SchemaFactory"
> > >> value="native(ForeignKeys=true)"/>
> > >>
> > >> And, of course, there is the manual means of specifying the
> ForeignKeys
> > >> via
> > >> the @ForeignKey annotation.
> > >>
> > >> Hope this helps,
> > >> Kevin
> > >>
> > >> [1]
> > >>
> > >>
> >
> http://people.apache.org/~mikedd/nightly.builds/apache-openjpa-2.3.0-SNAPSHOT/docs/docbook/manual.html#ref_guide_schema_info_factory
> > >>
> > >> On Tue, Feb 5, 2013 at 1:07 AM, seba.wagner@gmail.com <
> > >> seba.wagner@gmail.com
> > >> > wrote:
> > >>
> > >> > We are using MySQL with InnoDB and OpenJPA 2.2.1
> > >> >
> > >> > We face an issue in the automatic table schema creation:
> > >> > Indices are created but no foreign keys.
> > >> >
> > >> > We are using this configuration file:
> > >> >
> > >> >
> > >>
> >
> <http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/META-INF/mysql_persistence.xml?view=markup>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message