You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openmeetings.apache.org by "seba.wagner@gmail.com" <se...@gmail.com> on 2013/02/05 08:07:09 UTC

No foreign keys created by openJPA

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

I guess this is all what configures our schema creation:
<property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>

What I would expect is for example for attributes/mapping like (example 1
simple ManyToOne association):
    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "roomtypes_id")
    private RoomType roomtype;

That the attribute roomtypes_id will be created together with a FK and and
Indice. However Only Indice is created no FK.

The same for any attribute that has a ManyToOne or OneToMany or ManyToMany
annotation.

So the question is:
Is there a config value for SynchronizeMappings that automatically creates
not only the Indices but also the FK's for those relations?
Or do we really need to annotate every attribute with @ForeignKey?

Bonus question :)
How would that work with a one-sided one-many association without a cross
table?

For example (example 2 one-sided one-many association)
@OneToMany
    @ElementJoinColumn(name = "whiteboarditem_id", referencedColumnName =
"id")
    private Collection<WhiteboardItem> roomItems;

If I add:
@ForeignKey(enabled = true)
to example 1 => ForeignKey is created by SchemaTool
to example 2 => ForeignKey is _not_ created by SchemaTool

How can I make SchemaTool to create FK in example 2?


Thanks!
Sebastian
-- 
Sebastian Wagner
https://twitter.com/#!/dead_lock
http://www.webbase-design.de
http://www.wagner-sebastian.com
seba.wagner@gmail.com

RE: No foreign keys created by openJPA

Posted by Henno Vermeulen <he...@huizemolenaar.nl>.
We use a setting of

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

And this (also?) seems to create foreign key constraints in the schema.


-----Oorspronkelijk bericht-----
Van: jcarman@carmanconsulting.com [mailto:jcarman@carmanconsulting.com] Namens James Carman
Verzonden: zondag 10 februari 2013 7:30
Aan: users@openjpa.apache.org
Onderwerp: Re: No foreign keys created by openJPA

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 <kw...@gmail.com>
> > Date: Wed, Feb 6, 2013 at 9:33 PM
> > Subject: Re: No foreign keys created by openJPA
> > To: Maxim Solodovnik <so...@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 <kw...@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>

Re: No foreign keys created by openJPA

Posted by James Carman <ja...@carmanconsulting.com>.
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 <kw...@gmail.com>
> > Date: Wed, Feb 6, 2013 at 9:33 PM
> > Subject: Re: No foreign keys created by openJPA
> > To: Maxim Solodovnik <so...@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 <kw...@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>

Re: No foreign keys created by openJPA

Posted by Maxim Solodovnik <so...@gmail.com>.
I saw your commit, great job :)


On Sun, Feb 10, 2013 at 9:45 AM, seba.wagner@gmail.com <
seba.wagner@gmail.com> wrote:

> sorry plz synchronize.
> I have done that now already.
>
> Sebastian
>
>
> 2013/2/10 Maxim Solodovnik <so...@gmail.com>
>
> > I set no ForeignKey annotations.
> >
> >
> > On Sun, Feb 10, 2013 at 5:19 AM, seba.wagner@gmail.com <
> > seba.wagner@gmail.com> wrote:
> >
> > > @Maxim: Have you already done that locally or should I do that task?
> > >
> > > Sebastian
> > >
> > >
> > > 2013/2/10 seba.wagner@gmail.com <se...@gmail.com>
> > >
> > > > 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 <so...@gmail.com>
> > > >
> > > >> I'm afraid the answer below mean we need to annotate everything
> > > explicitly
> > > >>
> > > >> ---------- Forwarded message ----------
> > > >> From: Kevin Sutter <kw...@gmail.com>
> > > >> Date: Wed, Feb 6, 2013 at 9:33 PM
> > > >> Subject: Re: No foreign keys created by openJPA
> > > >> To: Maxim Solodovnik <so...@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 <kw...@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
> > > >> >> >
> > > >> >> > I guess this is all what configures our schema creation:
> > > >> >> > <property name="openjpa.jdbc.SynchronizeMappings"
> > > >> value="buildSchema"/>
> > > >> >> >
> > > >> >> > What I would expect is for example for attributes/mapping like
> > > >> (example
> > > >> >> 1
> > > >> >> > simple ManyToOne association):
> > > >> >> >     @ManyToOne(fetch = FetchType.EAGER)
> > > >> >> >     @JoinColumn(name = "roomtypes_id")
> > > >> >> >     private RoomType roomtype;
> > > >> >> >
> > > >> >> > That the attribute roomtypes_id will be created together with a
> > FK
> > > >> and
> > > >> >> and
> > > >> >> > Indice. However Only Indice is created no FK.
> > > >> >> >
> > > >> >> > The same for any attribute that has a ManyToOne or OneToMany or
> > > >> >> ManyToMany
> > > >> >> > annotation.
> > > >> >> >
> > > >> >> > So the question is:
> > > >> >> > Is there a config value for SynchronizeMappings that
> > automatically
> > > >> >> creates
> > > >> >> > not only the Indices but also the FK's for those relations?
> > > >> >> > Or do we really need to annotate every attribute with
> > @ForeignKey?
> > > >> >> >
> > > >> >> > Bonus question :)
> > > >> >> > How would that work with a one-sided one-many association
> > without a
> > > >> >> cross
> > > >> >> > table?
> > > >> >> >
> > > >> >> > For example (example 2 one-sided one-many association)
> > > >> >> > @OneToMany
> > > >> >> >     @ElementJoinColumn(name = "whiteboarditem_id",
> > > >> referencedColumnName
> > > >> >> =
> > > >> >> > "id")
> > > >> >> >     private Collection<WhiteboardItem> roomItems;
> > > >> >> >
> > > >> >> > If I add:
> > > >> >> > @ForeignKey(enabled = true)
> > > >> >> > to example 1 => ForeignKey is created by SchemaTool
> > > >> >> > to example 2 => ForeignKey is _not_ created by SchemaTool
> > > >> >> >
> > > >> >> > How can I make SchemaTool to create FK in example 2?
> > > >> >> >
> > > >> >> >
> > > >> >> > Thanks!
> > > >> >> > Sebastian
> > > >> >> > --
> > > >> >> > Sebastian Wagner
> > > >> >> > https://twitter.com/#!/dead_lock
> > > >> >> > http://www.webbase-design.de
> > > >> >> > http://www.wagner-sebastian.com
> > > >> >> > seba.wagner@gmail.com
> > > >> >> >
> > > >> >>
> > > >> >
> > > >> >
> > > >> >
> > > >> > --
> > > >> > WBR
> > > >> > Maxim aka solomax
> > > >> >
> > > >>
> > > >>
> > > >>
> > > >>
> > > >> --
> > > >> WBR
> > > >> Maxim aka solomax
> > > >>
> > > >
> > > >
> > > >
> > > > --
> > > > Sebastian Wagner
> > > > https://twitter.com/#!/dead_lock
> > > > http://www.webbase-design.de
> > > > http://www.wagner-sebastian.com
> > > > seba.wagner@gmail.com
> > > >
> > >
> > >
> > >
> > > --
> > > Sebastian Wagner
> > > https://twitter.com/#!/dead_lock
> > > http://www.webbase-design.de
> > > http://www.wagner-sebastian.com
> > > seba.wagner@gmail.com
> > >
> >
> >
> >
> > --
> > WBR
> > Maxim aka solomax
> >
>
>
>
> --
> Sebastian Wagner
> https://twitter.com/#!/dead_lock
> http://www.webbase-design.de
> http://www.wagner-sebastian.com
> seba.wagner@gmail.com
>



-- 
WBR
Maxim aka solomax

Re: No foreign keys created by openJPA

Posted by "seba.wagner@gmail.com" <se...@gmail.com>.
sorry plz synchronize.
I have done that now already.

Sebastian


2013/2/10 Maxim Solodovnik <so...@gmail.com>

> I set no ForeignKey annotations.
>
>
> On Sun, Feb 10, 2013 at 5:19 AM, seba.wagner@gmail.com <
> seba.wagner@gmail.com> wrote:
>
> > @Maxim: Have you already done that locally or should I do that task?
> >
> > Sebastian
> >
> >
> > 2013/2/10 seba.wagner@gmail.com <se...@gmail.com>
> >
> > > 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 <so...@gmail.com>
> > >
> > >> I'm afraid the answer below mean we need to annotate everything
> > explicitly
> > >>
> > >> ---------- Forwarded message ----------
> > >> From: Kevin Sutter <kw...@gmail.com>
> > >> Date: Wed, Feb 6, 2013 at 9:33 PM
> > >> Subject: Re: No foreign keys created by openJPA
> > >> To: Maxim Solodovnik <so...@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 <kw...@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
> > >> >> >
> > >> >> > I guess this is all what configures our schema creation:
> > >> >> > <property name="openjpa.jdbc.SynchronizeMappings"
> > >> value="buildSchema"/>
> > >> >> >
> > >> >> > What I would expect is for example for attributes/mapping like
> > >> (example
> > >> >> 1
> > >> >> > simple ManyToOne association):
> > >> >> >     @ManyToOne(fetch = FetchType.EAGER)
> > >> >> >     @JoinColumn(name = "roomtypes_id")
> > >> >> >     private RoomType roomtype;
> > >> >> >
> > >> >> > That the attribute roomtypes_id will be created together with a
> FK
> > >> and
> > >> >> and
> > >> >> > Indice. However Only Indice is created no FK.
> > >> >> >
> > >> >> > The same for any attribute that has a ManyToOne or OneToMany or
> > >> >> ManyToMany
> > >> >> > annotation.
> > >> >> >
> > >> >> > So the question is:
> > >> >> > Is there a config value for SynchronizeMappings that
> automatically
> > >> >> creates
> > >> >> > not only the Indices but also the FK's for those relations?
> > >> >> > Or do we really need to annotate every attribute with
> @ForeignKey?
> > >> >> >
> > >> >> > Bonus question :)
> > >> >> > How would that work with a one-sided one-many association
> without a
> > >> >> cross
> > >> >> > table?
> > >> >> >
> > >> >> > For example (example 2 one-sided one-many association)
> > >> >> > @OneToMany
> > >> >> >     @ElementJoinColumn(name = "whiteboarditem_id",
> > >> referencedColumnName
> > >> >> =
> > >> >> > "id")
> > >> >> >     private Collection<WhiteboardItem> roomItems;
> > >> >> >
> > >> >> > If I add:
> > >> >> > @ForeignKey(enabled = true)
> > >> >> > to example 1 => ForeignKey is created by SchemaTool
> > >> >> > to example 2 => ForeignKey is _not_ created by SchemaTool
> > >> >> >
> > >> >> > How can I make SchemaTool to create FK in example 2?
> > >> >> >
> > >> >> >
> > >> >> > Thanks!
> > >> >> > Sebastian
> > >> >> > --
> > >> >> > Sebastian Wagner
> > >> >> > https://twitter.com/#!/dead_lock
> > >> >> > http://www.webbase-design.de
> > >> >> > http://www.wagner-sebastian.com
> > >> >> > seba.wagner@gmail.com
> > >> >> >
> > >> >>
> > >> >
> > >> >
> > >> >
> > >> > --
> > >> > WBR
> > >> > Maxim aka solomax
> > >> >
> > >>
> > >>
> > >>
> > >>
> > >> --
> > >> WBR
> > >> Maxim aka solomax
> > >>
> > >
> > >
> > >
> > > --
> > > Sebastian Wagner
> > > https://twitter.com/#!/dead_lock
> > > http://www.webbase-design.de
> > > http://www.wagner-sebastian.com
> > > seba.wagner@gmail.com
> > >
> >
> >
> >
> > --
> > Sebastian Wagner
> > https://twitter.com/#!/dead_lock
> > http://www.webbase-design.de
> > http://www.wagner-sebastian.com
> > seba.wagner@gmail.com
> >
>
>
>
> --
> WBR
> Maxim aka solomax
>



-- 
Sebastian Wagner
https://twitter.com/#!/dead_lock
http://www.webbase-design.de
http://www.wagner-sebastian.com
seba.wagner@gmail.com

Re: No foreign keys created by openJPA

Posted by Maxim Solodovnik <so...@gmail.com>.
I set no ForeignKey annotations.


On Sun, Feb 10, 2013 at 5:19 AM, seba.wagner@gmail.com <
seba.wagner@gmail.com> wrote:

> @Maxim: Have you already done that locally or should I do that task?
>
> Sebastian
>
>
> 2013/2/10 seba.wagner@gmail.com <se...@gmail.com>
>
> > 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 <so...@gmail.com>
> >
> >> I'm afraid the answer below mean we need to annotate everything
> explicitly
> >>
> >> ---------- Forwarded message ----------
> >> From: Kevin Sutter <kw...@gmail.com>
> >> Date: Wed, Feb 6, 2013 at 9:33 PM
> >> Subject: Re: No foreign keys created by openJPA
> >> To: Maxim Solodovnik <so...@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 <kw...@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
> >> >> >
> >> >> > I guess this is all what configures our schema creation:
> >> >> > <property name="openjpa.jdbc.SynchronizeMappings"
> >> value="buildSchema"/>
> >> >> >
> >> >> > What I would expect is for example for attributes/mapping like
> >> (example
> >> >> 1
> >> >> > simple ManyToOne association):
> >> >> >     @ManyToOne(fetch = FetchType.EAGER)
> >> >> >     @JoinColumn(name = "roomtypes_id")
> >> >> >     private RoomType roomtype;
> >> >> >
> >> >> > That the attribute roomtypes_id will be created together with a FK
> >> and
> >> >> and
> >> >> > Indice. However Only Indice is created no FK.
> >> >> >
> >> >> > The same for any attribute that has a ManyToOne or OneToMany or
> >> >> ManyToMany
> >> >> > annotation.
> >> >> >
> >> >> > So the question is:
> >> >> > Is there a config value for SynchronizeMappings that automatically
> >> >> creates
> >> >> > not only the Indices but also the FK's for those relations?
> >> >> > Or do we really need to annotate every attribute with @ForeignKey?
> >> >> >
> >> >> > Bonus question :)
> >> >> > How would that work with a one-sided one-many association without a
> >> >> cross
> >> >> > table?
> >> >> >
> >> >> > For example (example 2 one-sided one-many association)
> >> >> > @OneToMany
> >> >> >     @ElementJoinColumn(name = "whiteboarditem_id",
> >> referencedColumnName
> >> >> =
> >> >> > "id")
> >> >> >     private Collection<WhiteboardItem> roomItems;
> >> >> >
> >> >> > If I add:
> >> >> > @ForeignKey(enabled = true)
> >> >> > to example 1 => ForeignKey is created by SchemaTool
> >> >> > to example 2 => ForeignKey is _not_ created by SchemaTool
> >> >> >
> >> >> > How can I make SchemaTool to create FK in example 2?
> >> >> >
> >> >> >
> >> >> > Thanks!
> >> >> > Sebastian
> >> >> > --
> >> >> > Sebastian Wagner
> >> >> > https://twitter.com/#!/dead_lock
> >> >> > http://www.webbase-design.de
> >> >> > http://www.wagner-sebastian.com
> >> >> > seba.wagner@gmail.com
> >> >> >
> >> >>
> >> >
> >> >
> >> >
> >> > --
> >> > WBR
> >> > Maxim aka solomax
> >> >
> >>
> >>
> >>
> >>
> >> --
> >> WBR
> >> Maxim aka solomax
> >>
> >
> >
> >
> > --
> > Sebastian Wagner
> > https://twitter.com/#!/dead_lock
> > http://www.webbase-design.de
> > http://www.wagner-sebastian.com
> > seba.wagner@gmail.com
> >
>
>
>
> --
> Sebastian Wagner
> https://twitter.com/#!/dead_lock
> http://www.webbase-design.de
> http://www.wagner-sebastian.com
> seba.wagner@gmail.com
>



-- 
WBR
Maxim aka solomax

Re: No foreign keys created by openJPA

Posted by "seba.wagner@gmail.com" <se...@gmail.com>.
@Maxim: Have you already done that locally or should I do that task?

Sebastian


2013/2/10 seba.wagner@gmail.com <se...@gmail.com>

> 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 <so...@gmail.com>
>
>> I'm afraid the answer below mean we need to annotate everything explicitly
>>
>> ---------- Forwarded message ----------
>> From: Kevin Sutter <kw...@gmail.com>
>> Date: Wed, Feb 6, 2013 at 9:33 PM
>> Subject: Re: No foreign keys created by openJPA
>> To: Maxim Solodovnik <so...@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 <kw...@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
>> >> >
>> >> > I guess this is all what configures our schema creation:
>> >> > <property name="openjpa.jdbc.SynchronizeMappings"
>> value="buildSchema"/>
>> >> >
>> >> > What I would expect is for example for attributes/mapping like
>> (example
>> >> 1
>> >> > simple ManyToOne association):
>> >> >     @ManyToOne(fetch = FetchType.EAGER)
>> >> >     @JoinColumn(name = "roomtypes_id")
>> >> >     private RoomType roomtype;
>> >> >
>> >> > That the attribute roomtypes_id will be created together with a FK
>> and
>> >> and
>> >> > Indice. However Only Indice is created no FK.
>> >> >
>> >> > The same for any attribute that has a ManyToOne or OneToMany or
>> >> ManyToMany
>> >> > annotation.
>> >> >
>> >> > So the question is:
>> >> > Is there a config value for SynchronizeMappings that automatically
>> >> creates
>> >> > not only the Indices but also the FK's for those relations?
>> >> > Or do we really need to annotate every attribute with @ForeignKey?
>> >> >
>> >> > Bonus question :)
>> >> > How would that work with a one-sided one-many association without a
>> >> cross
>> >> > table?
>> >> >
>> >> > For example (example 2 one-sided one-many association)
>> >> > @OneToMany
>> >> >     @ElementJoinColumn(name = "whiteboarditem_id",
>> referencedColumnName
>> >> =
>> >> > "id")
>> >> >     private Collection<WhiteboardItem> roomItems;
>> >> >
>> >> > If I add:
>> >> > @ForeignKey(enabled = true)
>> >> > to example 1 => ForeignKey is created by SchemaTool
>> >> > to example 2 => ForeignKey is _not_ created by SchemaTool
>> >> >
>> >> > How can I make SchemaTool to create FK in example 2?
>> >> >
>> >> >
>> >> > Thanks!
>> >> > Sebastian
>> >> > --
>> >> > Sebastian Wagner
>> >> > https://twitter.com/#!/dead_lock
>> >> > http://www.webbase-design.de
>> >> > http://www.wagner-sebastian.com
>> >> > seba.wagner@gmail.com
>> >> >
>> >>
>> >
>> >
>> >
>> > --
>> > WBR
>> > Maxim aka solomax
>> >
>>
>>
>>
>>
>> --
>> WBR
>> Maxim aka solomax
>>
>
>
>
> --
> Sebastian Wagner
> https://twitter.com/#!/dead_lock
> http://www.webbase-design.de
> http://www.wagner-sebastian.com
> seba.wagner@gmail.com
>



-- 
Sebastian Wagner
https://twitter.com/#!/dead_lock
http://www.webbase-design.de
http://www.wagner-sebastian.com
seba.wagner@gmail.com

Re: No foreign keys created by openJPA

Posted by "seba.wagner@gmail.com" <se...@gmail.com>.
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 <so...@gmail.com>

> I'm afraid the answer below mean we need to annotate everything explicitly
>
> ---------- Forwarded message ----------
> From: Kevin Sutter <kw...@gmail.com>
> Date: Wed, Feb 6, 2013 at 9:33 PM
> Subject: Re: No foreign keys created by openJPA
> To: Maxim Solodovnik <so...@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 <kw...@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
> >> >
> >> > I guess this is all what configures our schema creation:
> >> > <property name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema"/>
> >> >
> >> > What I would expect is for example for attributes/mapping like
> (example
> >> 1
> >> > simple ManyToOne association):
> >> >     @ManyToOne(fetch = FetchType.EAGER)
> >> >     @JoinColumn(name = "roomtypes_id")
> >> >     private RoomType roomtype;
> >> >
> >> > That the attribute roomtypes_id will be created together with a FK and
> >> and
> >> > Indice. However Only Indice is created no FK.
> >> >
> >> > The same for any attribute that has a ManyToOne or OneToMany or
> >> ManyToMany
> >> > annotation.
> >> >
> >> > So the question is:
> >> > Is there a config value for SynchronizeMappings that automatically
> >> creates
> >> > not only the Indices but also the FK's for those relations?
> >> > Or do we really need to annotate every attribute with @ForeignKey?
> >> >
> >> > Bonus question :)
> >> > How would that work with a one-sided one-many association without a
> >> cross
> >> > table?
> >> >
> >> > For example (example 2 one-sided one-many association)
> >> > @OneToMany
> >> >     @ElementJoinColumn(name = "whiteboarditem_id",
> referencedColumnName
> >> =
> >> > "id")
> >> >     private Collection<WhiteboardItem> roomItems;
> >> >
> >> > If I add:
> >> > @ForeignKey(enabled = true)
> >> > to example 1 => ForeignKey is created by SchemaTool
> >> > to example 2 => ForeignKey is _not_ created by SchemaTool
> >> >
> >> > How can I make SchemaTool to create FK in example 2?
> >> >
> >> >
> >> > Thanks!
> >> > Sebastian
> >> > --
> >> > Sebastian Wagner
> >> > https://twitter.com/#!/dead_lock
> >> > http://www.webbase-design.de
> >> > http://www.wagner-sebastian.com
> >> > seba.wagner@gmail.com
> >> >
> >>
> >
> >
> >
> > --
> > WBR
> > Maxim aka solomax
> >
>
>
>
>
> --
> WBR
> Maxim aka solomax
>



-- 
Sebastian Wagner
https://twitter.com/#!/dead_lock
http://www.webbase-design.de
http://www.wagner-sebastian.com
seba.wagner@gmail.com

Re: No foreign keys created by openJPA

Posted by "seba.wagner@gmail.com" <se...@gmail.com>.
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 <so...@gmail.com>

> I'm afraid the answer below mean we need to annotate everything explicitly
>
> ---------- Forwarded message ----------
> From: Kevin Sutter <kw...@gmail.com>
> Date: Wed, Feb 6, 2013 at 9:33 PM
> Subject: Re: No foreign keys created by openJPA
> To: Maxim Solodovnik <so...@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 <kw...@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
> >> >
> >> > I guess this is all what configures our schema creation:
> >> > <property name="openjpa.jdbc.SynchronizeMappings"
> value="buildSchema"/>
> >> >
> >> > What I would expect is for example for attributes/mapping like
> (example
> >> 1
> >> > simple ManyToOne association):
> >> >     @ManyToOne(fetch = FetchType.EAGER)
> >> >     @JoinColumn(name = "roomtypes_id")
> >> >     private RoomType roomtype;
> >> >
> >> > That the attribute roomtypes_id will be created together with a FK and
> >> and
> >> > Indice. However Only Indice is created no FK.
> >> >
> >> > The same for any attribute that has a ManyToOne or OneToMany or
> >> ManyToMany
> >> > annotation.
> >> >
> >> > So the question is:
> >> > Is there a config value for SynchronizeMappings that automatically
> >> creates
> >> > not only the Indices but also the FK's for those relations?
> >> > Or do we really need to annotate every attribute with @ForeignKey?
> >> >
> >> > Bonus question :)
> >> > How would that work with a one-sided one-many association without a
> >> cross
> >> > table?
> >> >
> >> > For example (example 2 one-sided one-many association)
> >> > @OneToMany
> >> >     @ElementJoinColumn(name = "whiteboarditem_id",
> referencedColumnName
> >> =
> >> > "id")
> >> >     private Collection<WhiteboardItem> roomItems;
> >> >
> >> > If I add:
> >> > @ForeignKey(enabled = true)
> >> > to example 1 => ForeignKey is created by SchemaTool
> >> > to example 2 => ForeignKey is _not_ created by SchemaTool
> >> >
> >> > How can I make SchemaTool to create FK in example 2?
> >> >
> >> >
> >> > Thanks!
> >> > Sebastian
> >> > --
> >> > Sebastian Wagner
> >> > https://twitter.com/#!/dead_lock
> >> > http://www.webbase-design.de
> >> > http://www.wagner-sebastian.com
> >> > seba.wagner@gmail.com
> >> >
> >>
> >
> >
> >
> > --
> > WBR
> > Maxim aka solomax
> >
>
>
>
>
> --
> WBR
> Maxim aka solomax
>



-- 
Sebastian Wagner
https://twitter.com/#!/dead_lock
http://www.webbase-design.de
http://www.wagner-sebastian.com
seba.wagner@gmail.com

Fwd: No foreign keys created by openJPA

Posted by Maxim Solodovnik <so...@gmail.com>.
I'm afraid the answer below mean we need to annotate everything explicitly

---------- Forwarded message ----------
From: Kevin Sutter <kw...@gmail.com>
Date: Wed, Feb 6, 2013 at 9:33 PM
Subject: Re: No foreign keys created by openJPA
To: Maxim Solodovnik <so...@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 <so...@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 <kw...@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
>> >
>> > I guess this is all what configures our schema creation:
>> > <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
>> >
>> > What I would expect is for example for attributes/mapping like (example
>> 1
>> > simple ManyToOne association):
>> >     @ManyToOne(fetch = FetchType.EAGER)
>> >     @JoinColumn(name = "roomtypes_id")
>> >     private RoomType roomtype;
>> >
>> > That the attribute roomtypes_id will be created together with a FK and
>> and
>> > Indice. However Only Indice is created no FK.
>> >
>> > The same for any attribute that has a ManyToOne or OneToMany or
>> ManyToMany
>> > annotation.
>> >
>> > So the question is:
>> > Is there a config value for SynchronizeMappings that automatically
>> creates
>> > not only the Indices but also the FK's for those relations?
>> > Or do we really need to annotate every attribute with @ForeignKey?
>> >
>> > Bonus question :)
>> > How would that work with a one-sided one-many association without a
>> cross
>> > table?
>> >
>> > For example (example 2 one-sided one-many association)
>> > @OneToMany
>> >     @ElementJoinColumn(name = "whiteboarditem_id", referencedColumnName
>> =
>> > "id")
>> >     private Collection<WhiteboardItem> roomItems;
>> >
>> > If I add:
>> > @ForeignKey(enabled = true)
>> > to example 1 => ForeignKey is created by SchemaTool
>> > to example 2 => ForeignKey is _not_ created by SchemaTool
>> >
>> > How can I make SchemaTool to create FK in example 2?
>> >
>> >
>> > Thanks!
>> > Sebastian
>> > --
>> > Sebastian Wagner
>> > https://twitter.com/#!/dead_lock
>> > http://www.webbase-design.de
>> > http://www.wagner-sebastian.com
>> > seba.wagner@gmail.com
>> >
>>
>
>
>
> --
> WBR
> Maxim aka solomax
>




-- 
WBR
Maxim aka solomax

Re: No foreign keys created by openJPA

Posted by Kevin Sutter <kw...@gmail.com>.
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 <so...@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 <kw...@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
>> >
>> > I guess this is all what configures our schema creation:
>> > <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
>> >
>> > What I would expect is for example for attributes/mapping like (example
>> 1
>> > simple ManyToOne association):
>> >     @ManyToOne(fetch = FetchType.EAGER)
>> >     @JoinColumn(name = "roomtypes_id")
>> >     private RoomType roomtype;
>> >
>> > That the attribute roomtypes_id will be created together with a FK and
>> and
>> > Indice. However Only Indice is created no FK.
>> >
>> > The same for any attribute that has a ManyToOne or OneToMany or
>> ManyToMany
>> > annotation.
>> >
>> > So the question is:
>> > Is there a config value for SynchronizeMappings that automatically
>> creates
>> > not only the Indices but also the FK's for those relations?
>> > Or do we really need to annotate every attribute with @ForeignKey?
>> >
>> > Bonus question :)
>> > How would that work with a one-sided one-many association without a
>> cross
>> > table?
>> >
>> > For example (example 2 one-sided one-many association)
>> > @OneToMany
>> >     @ElementJoinColumn(name = "whiteboarditem_id", referencedColumnName
>> =
>> > "id")
>> >     private Collection<WhiteboardItem> roomItems;
>> >
>> > If I add:
>> > @ForeignKey(enabled = true)
>> > to example 1 => ForeignKey is created by SchemaTool
>> > to example 2 => ForeignKey is _not_ created by SchemaTool
>> >
>> > How can I make SchemaTool to create FK in example 2?
>> >
>> >
>> > Thanks!
>> > Sebastian
>> > --
>> > Sebastian Wagner
>> > https://twitter.com/#!/dead_lock
>> > http://www.webbase-design.de
>> > http://www.wagner-sebastian.com
>> > seba.wagner@gmail.com
>> >
>>
>
>
>
> --
> WBR
> Maxim aka solomax
>

Fwd: No foreign keys created by openJPA

Posted by Maxim Solodovnik <so...@gmail.com>.
---------- Forwarded message ----------
Date: Wed, Feb 6, 2013 at 11:00 AM
Subject: Re: No foreign keys created by openJPA
Cc: users@openjpa.apache.org


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 <kw...@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
> >
> > I guess this is all what configures our schema creation:
> > <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
> >
> > What I would expect is for example for attributes/mapping like (example 1
> > simple ManyToOne association):
> >     @ManyToOne(fetch = FetchType.EAGER)
> >     @JoinColumn(name = "roomtypes_id")
> >     private RoomType roomtype;
> >
> > That the attribute roomtypes_id will be created together with a FK and
> and
> > Indice. However Only Indice is created no FK.
> >
> > The same for any attribute that has a ManyToOne or OneToMany or
> ManyToMany
> > annotation.
> >
> > So the question is:
> > Is there a config value for SynchronizeMappings that automatically
> creates
> > not only the Indices but also the FK's for those relations?
> > Or do we really need to annotate every attribute with @ForeignKey?
> >
> > Bonus question :)
> > How would that work with a one-sided one-many association without a cross
> > table?
> >
> > For example (example 2 one-sided one-many association)
> > @OneToMany
> >     @ElementJoinColumn(name = "whiteboarditem_id", referencedColumnName =
> > "id")
> >     private Collection<WhiteboardItem> roomItems;
> >
> > If I add:
> > @ForeignKey(enabled = true)
> > to example 1 => ForeignKey is created by SchemaTool
> > to example 2 => ForeignKey is _not_ created by SchemaTool
> >
> > How can I make SchemaTool to create FK in example 2?
> >
> >
> > Thanks!
> > Sebastian
> > --
> > Sebastian Wagner
> > https://twitter.com/#!/dead_lock
> > http://www.webbase-design.de
> > http://www.wagner-sebastian.com
> > seba.wagner@gmail.com
> >
>



-- 
WBR
Maxim aka solomax



-- 
WBR
Maxim aka solomax

Re: No foreign keys created by openJPA

Posted by Maxim Solodovnik <so...@gmail.com>.
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 <kw...@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
> >
> > I guess this is all what configures our schema creation:
> > <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
> >
> > What I would expect is for example for attributes/mapping like (example 1
> > simple ManyToOne association):
> >     @ManyToOne(fetch = FetchType.EAGER)
> >     @JoinColumn(name = "roomtypes_id")
> >     private RoomType roomtype;
> >
> > That the attribute roomtypes_id will be created together with a FK and
> and
> > Indice. However Only Indice is created no FK.
> >
> > The same for any attribute that has a ManyToOne or OneToMany or
> ManyToMany
> > annotation.
> >
> > So the question is:
> > Is there a config value for SynchronizeMappings that automatically
> creates
> > not only the Indices but also the FK's for those relations?
> > Or do we really need to annotate every attribute with @ForeignKey?
> >
> > Bonus question :)
> > How would that work with a one-sided one-many association without a cross
> > table?
> >
> > For example (example 2 one-sided one-many association)
> > @OneToMany
> >     @ElementJoinColumn(name = "whiteboarditem_id", referencedColumnName =
> > "id")
> >     private Collection<WhiteboardItem> roomItems;
> >
> > If I add:
> > @ForeignKey(enabled = true)
> > to example 1 => ForeignKey is created by SchemaTool
> > to example 2 => ForeignKey is _not_ created by SchemaTool
> >
> > How can I make SchemaTool to create FK in example 2?
> >
> >
> > Thanks!
> > Sebastian
> > --
> > Sebastian Wagner
> > https://twitter.com/#!/dead_lock
> > http://www.webbase-design.de
> > http://www.wagner-sebastian.com
> > seba.wagner@gmail.com
> >
>



-- 
WBR
Maxim aka solomax

Re: No foreign keys created by openJPA

Posted by Maxim Solodovnik <so...@gmail.com>.
OK, testing it right now :)


On Wed, Feb 6, 2013 at 9:54 AM, seba.wagner@gmail.com <seba.wagner@gmail.com
> wrote:

> THX Kevin!
>
> @Maxim we should try that!
> Am 06.02.2013 03:59 schrieb "Kevin Sutter" <kw...@gmail.com>:
>
> 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
>> >
>> > I guess this is all what configures our schema creation:
>> > <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
>> >
>> > What I would expect is for example for attributes/mapping like (example
>> 1
>> > simple ManyToOne association):
>> >     @ManyToOne(fetch = FetchType.EAGER)
>> >     @JoinColumn(name = "roomtypes_id")
>> >     private RoomType roomtype;
>> >
>> > That the attribute roomtypes_id will be created together with a FK and
>> and
>> > Indice. However Only Indice is created no FK.
>> >
>> > The same for any attribute that has a ManyToOne or OneToMany or
>> ManyToMany
>> > annotation.
>> >
>> > So the question is:
>> > Is there a config value for SynchronizeMappings that automatically
>> creates
>> > not only the Indices but also the FK's for those relations?
>> > Or do we really need to annotate every attribute with @ForeignKey?
>> >
>> > Bonus question :)
>> > How would that work with a one-sided one-many association without a
>> cross
>> > table?
>> >
>> > For example (example 2 one-sided one-many association)
>> > @OneToMany
>> >     @ElementJoinColumn(name = "whiteboarditem_id", referencedColumnName
>> =
>> > "id")
>> >     private Collection<WhiteboardItem> roomItems;
>> >
>> > If I add:
>> > @ForeignKey(enabled = true)
>> > to example 1 => ForeignKey is created by SchemaTool
>> > to example 2 => ForeignKey is _not_ created by SchemaTool
>> >
>> > How can I make SchemaTool to create FK in example 2?
>> >
>> >
>> > Thanks!
>> > Sebastian
>> > --
>> > Sebastian Wagner
>> > https://twitter.com/#!/dead_lock
>> > http://www.webbase-design.de
>> > http://www.wagner-sebastian.com
>> > seba.wagner@gmail.com
>> >
>>
>


-- 
WBR
Maxim aka solomax

Re: No foreign keys created by openJPA

Posted by Maxim Solodovnik <so...@gmail.com>.
OK, testing it right now :)


On Wed, Feb 6, 2013 at 9:54 AM, seba.wagner@gmail.com <seba.wagner@gmail.com
> wrote:

> THX Kevin!
>
> @Maxim we should try that!
> Am 06.02.2013 03:59 schrieb "Kevin Sutter" <kw...@gmail.com>:
>
> 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
>> >
>> > I guess this is all what configures our schema creation:
>> > <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
>> >
>> > What I would expect is for example for attributes/mapping like (example
>> 1
>> > simple ManyToOne association):
>> >     @ManyToOne(fetch = FetchType.EAGER)
>> >     @JoinColumn(name = "roomtypes_id")
>> >     private RoomType roomtype;
>> >
>> > That the attribute roomtypes_id will be created together with a FK and
>> and
>> > Indice. However Only Indice is created no FK.
>> >
>> > The same for any attribute that has a ManyToOne or OneToMany or
>> ManyToMany
>> > annotation.
>> >
>> > So the question is:
>> > Is there a config value for SynchronizeMappings that automatically
>> creates
>> > not only the Indices but also the FK's for those relations?
>> > Or do we really need to annotate every attribute with @ForeignKey?
>> >
>> > Bonus question :)
>> > How would that work with a one-sided one-many association without a
>> cross
>> > table?
>> >
>> > For example (example 2 one-sided one-many association)
>> > @OneToMany
>> >     @ElementJoinColumn(name = "whiteboarditem_id", referencedColumnName
>> =
>> > "id")
>> >     private Collection<WhiteboardItem> roomItems;
>> >
>> > If I add:
>> > @ForeignKey(enabled = true)
>> > to example 1 => ForeignKey is created by SchemaTool
>> > to example 2 => ForeignKey is _not_ created by SchemaTool
>> >
>> > How can I make SchemaTool to create FK in example 2?
>> >
>> >
>> > Thanks!
>> > Sebastian
>> > --
>> > Sebastian Wagner
>> > https://twitter.com/#!/dead_lock
>> > http://www.webbase-design.de
>> > http://www.wagner-sebastian.com
>> > seba.wagner@gmail.com
>> >
>>
>


-- 
WBR
Maxim aka solomax

Re: No foreign keys created by openJPA

Posted by "seba.wagner@gmail.com" <se...@gmail.com>.
THX Kevin!

@Maxim we should try that!
Am 06.02.2013 03:59 schrieb "Kevin Sutter" <kw...@gmail.com>:

> 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
> >
> > I guess this is all what configures our schema creation:
> > <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
> >
> > What I would expect is for example for attributes/mapping like (example 1
> > simple ManyToOne association):
> >     @ManyToOne(fetch = FetchType.EAGER)
> >     @JoinColumn(name = "roomtypes_id")
> >     private RoomType roomtype;
> >
> > That the attribute roomtypes_id will be created together with a FK and
> and
> > Indice. However Only Indice is created no FK.
> >
> > The same for any attribute that has a ManyToOne or OneToMany or
> ManyToMany
> > annotation.
> >
> > So the question is:
> > Is there a config value for SynchronizeMappings that automatically
> creates
> > not only the Indices but also the FK's for those relations?
> > Or do we really need to annotate every attribute with @ForeignKey?
> >
> > Bonus question :)
> > How would that work with a one-sided one-many association without a cross
> > table?
> >
> > For example (example 2 one-sided one-many association)
> > @OneToMany
> >     @ElementJoinColumn(name = "whiteboarditem_id", referencedColumnName =
> > "id")
> >     private Collection<WhiteboardItem> roomItems;
> >
> > If I add:
> > @ForeignKey(enabled = true)
> > to example 1 => ForeignKey is created by SchemaTool
> > to example 2 => ForeignKey is _not_ created by SchemaTool
> >
> > How can I make SchemaTool to create FK in example 2?
> >
> >
> > Thanks!
> > Sebastian
> > --
> > Sebastian Wagner
> > https://twitter.com/#!/dead_lock
> > http://www.webbase-design.de
> > http://www.wagner-sebastian.com
> > seba.wagner@gmail.com
> >
>

Re: No foreign keys created by openJPA

Posted by "seba.wagner@gmail.com" <se...@gmail.com>.
THX Kevin!

@Maxim we should try that!
Am 06.02.2013 03:59 schrieb "Kevin Sutter" <kw...@gmail.com>:

> 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
> >
> > I guess this is all what configures our schema creation:
> > <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
> >
> > What I would expect is for example for attributes/mapping like (example 1
> > simple ManyToOne association):
> >     @ManyToOne(fetch = FetchType.EAGER)
> >     @JoinColumn(name = "roomtypes_id")
> >     private RoomType roomtype;
> >
> > That the attribute roomtypes_id will be created together with a FK and
> and
> > Indice. However Only Indice is created no FK.
> >
> > The same for any attribute that has a ManyToOne or OneToMany or
> ManyToMany
> > annotation.
> >
> > So the question is:
> > Is there a config value for SynchronizeMappings that automatically
> creates
> > not only the Indices but also the FK's for those relations?
> > Or do we really need to annotate every attribute with @ForeignKey?
> >
> > Bonus question :)
> > How would that work with a one-sided one-many association without a cross
> > table?
> >
> > For example (example 2 one-sided one-many association)
> > @OneToMany
> >     @ElementJoinColumn(name = "whiteboarditem_id", referencedColumnName =
> > "id")
> >     private Collection<WhiteboardItem> roomItems;
> >
> > If I add:
> > @ForeignKey(enabled = true)
> > to example 1 => ForeignKey is created by SchemaTool
> > to example 2 => ForeignKey is _not_ created by SchemaTool
> >
> > How can I make SchemaTool to create FK in example 2?
> >
> >
> > Thanks!
> > Sebastian
> > --
> > Sebastian Wagner
> > https://twitter.com/#!/dead_lock
> > http://www.webbase-design.de
> > http://www.wagner-sebastian.com
> > seba.wagner@gmail.com
> >
>

Re: No foreign keys created by openJPA

Posted by Kevin Sutter <kw...@gmail.com>.
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
>
> I guess this is all what configures our schema creation:
> <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema"/>
>
> What I would expect is for example for attributes/mapping like (example 1
> simple ManyToOne association):
>     @ManyToOne(fetch = FetchType.EAGER)
>     @JoinColumn(name = "roomtypes_id")
>     private RoomType roomtype;
>
> That the attribute roomtypes_id will be created together with a FK and and
> Indice. However Only Indice is created no FK.
>
> The same for any attribute that has a ManyToOne or OneToMany or ManyToMany
> annotation.
>
> So the question is:
> Is there a config value for SynchronizeMappings that automatically creates
> not only the Indices but also the FK's for those relations?
> Or do we really need to annotate every attribute with @ForeignKey?
>
> Bonus question :)
> How would that work with a one-sided one-many association without a cross
> table?
>
> For example (example 2 one-sided one-many association)
> @OneToMany
>     @ElementJoinColumn(name = "whiteboarditem_id", referencedColumnName =
> "id")
>     private Collection<WhiteboardItem> roomItems;
>
> If I add:
> @ForeignKey(enabled = true)
> to example 1 => ForeignKey is created by SchemaTool
> to example 2 => ForeignKey is _not_ created by SchemaTool
>
> How can I make SchemaTool to create FK in example 2?
>
>
> Thanks!
> Sebastian
> --
> Sebastian Wagner
> https://twitter.com/#!/dead_lock
> http://www.webbase-design.de
> http://www.wagner-sebastian.com
> seba.wagner@gmail.com
>