sorry plz synchronize. I have done that now already. Sebastian
2013/2/10 Maxim Solodovnik <[email protected]> > I set no ForeignKey annotations. > > > On Sun, Feb 10, 2013 at 5:19 AM, [email protected] < > [email protected]> wrote: > > > @Maxim: Have you already done that locally or should I do that task? > > > > Sebastian > > > > > > 2013/2/10 [email protected] <[email protected]> > > > > > 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 <[email protected]> > > > > > >> I'm afraid the answer below mean we need to annotate everything > > explicitly > > >> > > >> ---------- Forwarded message ---------- > > >> From: Kevin Sutter <[email protected]> > > >> Date: Wed, Feb 6, 2013 at 9:33 PM > > >> Subject: Re: No foreign keys created by openJPA > > >> To: Maxim Solodovnik <[email protected]> > > >> Cc: [email protected] > > >> > > >> > > >> 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 < > [email protected] > > >> >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 <[email protected]> > > >> 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, [email protected] < > > >> >> [email protected] > > >> >> > 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 > > >> >> > [email protected] > > >> >> > > > >> >> > > >> > > > >> > > > >> > > > >> > -- > > >> > 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 > > > [email protected] > > > > > > > > > > > -- > > Sebastian Wagner > > https://twitter.com/#!/dead_lock > > http://www.webbase-design.de > > http://www.wagner-sebastian.com > > [email protected] > > > > > > -- > WBR > Maxim aka solomax > -- Sebastian Wagner https://twitter.com/#!/dead_lock http://www.webbase-design.de http://www.wagner-sebastian.com [email protected]
