Return-Path: X-Original-To: apmail-openjpa-users-archive@minotaur.apache.org Delivered-To: apmail-openjpa-users-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 99D43EF3A for ; Sat, 9 Feb 2013 22:19:17 +0000 (UTC) Received: (qmail 69605 invoked by uid 500); 9 Feb 2013 22:19:17 -0000 Delivered-To: apmail-openjpa-users-archive@openjpa.apache.org Received: (qmail 69551 invoked by uid 500); 9 Feb 2013 22:19:17 -0000 Mailing-List: contact users-help@openjpa.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: users@openjpa.apache.org Delivered-To: mailing list users@openjpa.apache.org Received: (qmail 69543 invoked by uid 99); 9 Feb 2013 22:19:17 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Feb 2013 22:19:17 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of seba.wagner@gmail.com designates 209.85.212.173 as permitted sender) Received: from [209.85.212.173] (HELO mail-wi0-f173.google.com) (209.85.212.173) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 09 Feb 2013 22:19:10 +0000 Received: by mail-wi0-f173.google.com with SMTP id hq4so2045656wib.0 for ; Sat, 09 Feb 2013 14:18:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=aQFQahTBDBBrHR6ei/EmOPwSCz3RapJaK4lJrPGvekE=; b=k4GzVoiNj/jbrvEiC2Bp6kdz0bPtcqg6mwBKfuzdP9RDeKB8fDNonWLUk0SxP8t1aa houSRdm5fcQ2nYwVrXKnj3lsA//IUYGYwiKPfsc2Ef23yRTTepHutCQO6Z+Bfih79sKj zbYBv5udt/c5bEk6xH912QQL+BVs5UaOl7CSfLJHUOjYdHg5SY9pex5J6REIHVSJVpV9 fxuCE62JkZcaon1IEkqMCRIL96oS3FlKOICWGy7sCC5/7zCEmnoKS0AEe+9tzGlElxZp SW0nWoZg1U8+jN/1gptEYdf4IxxMkMqGUbDNHf0jmq0kb/bq6fvlD6rUlo2TUUL/IWot Utiw== X-Received: by 10.180.77.68 with SMTP id q4mr8953208wiw.10.1360448329646; Sat, 09 Feb 2013 14:18:49 -0800 (PST) MIME-Version: 1.0 Received: by 10.194.172.2 with HTTP; Sat, 9 Feb 2013 14:18:29 -0800 (PST) In-Reply-To: References: From: "seba.wagner@gmail.com" Date: Sun, 10 Feb 2013 11:18:29 +1300 Message-ID: Subject: Re: No foreign keys created by openJPA To: dev Cc: users@openjpa.apache.org Content-Type: multipart/alternative; boundary=f46d043893bd6c80e104d5520f81 X-Virus-Checked: Checked by ClamAV on apache.org --f46d043893bd6c80e104d5520f81 Content-Type: text/plain; charset=ISO-8859-1 Yes, from my point of view having: or just: 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 > I'm afraid the answer below mean we need to annotate everything explicitly > > ---------- Forwarded message ---------- > From: Kevin Sutter > Date: Wed, Feb 6, 2013 at 9:33 PM > Subject: Re: No foreign keys created by openJPA > To: Maxim Solodovnik > 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 >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 wrote: > > > >> Hi Sebastian, > >> There are two ways to get the ForeignKeys automatically processed. > >> > >> >> 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]: > >> > >> >> 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: > >> > 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 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 --f46d043893bd6c80e104d5520f81--