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.wag...@gmail.com <seba.wag...@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.wag...@gmail.com >