Doesnt that tie me to the openjpa implementation? Is there a reason
why a foreign key constraint should not be created if the database
makes it possible, ie mysql / oracle etc.? Or is it specified by the
jpa specs that no foreign keys are to be made?

Regards,

KlaasJan

On 9/7/07, CASERO Jaime <[EMAIL PROTECTED]> wrote:
> I'm afraid you have to use "@ForeignKey" annotation to force JPA to
> create the foreign key at DB level.
>
> http://openjpa.apache.org/builds/1.0.0/apache-openjpa-1.0.0/docs/manual/
> ref_guide_mapping_jpa.html#ref_guide_mapping_jpa_fk
>
> Use this setting in your persistence.xml during development, to set JPA
> to create the necessary Foreign Key, even if the schema was already
> created.
>             <property name="openjpa.jdbc.SynchronizeMappings"
>                 value="buildSchema(ForeignKeys=true)"/>
>
> -----Original Message-----
> From: klaasjan elzinga [mailto:[EMAIL PROTECTED]
> Sent: Thursday, September 06, 2007 10:40 PM
> To: users@openjpa.apache.org
> Subject: DDL for foreign key constraints.
>
> Hi there,
>
> I am trying to get openjpa to generate foreign key constraints. I have
> to following annotations:
>
> ... on the parent:
>
>     @OneToMany(targetEntity=Message.class, cascade=CascadeType.ALL,
> mappedBy="mailingList")
>     private List<Message> messages = new ArrayList<Message>();
>
>
> ... on the child
>
>     @ManyToOne(targetEntity=MailingList.class, optional=false)
>     @JoinColumn(referencedColumnName="id", table="mailinglist")
>     private MailingList mailingList;
>
> But openjpa w/ mysql does not generate a foreign key constraint:
> mysql> show create table message;
> | message | CREATE TABLE `message` (
>   `id` bigint(20) NOT NULL,
>   `state` smallint(6) default NULL,
>   `version` int(11) default NULL,
>   `mailingList_id` bigint(20) default NULL,
>   PRIMARY KEY  (`id`),
>   KEY `I_MESSAGE_MAILINGLIST` (`mailingList_id`)
> ) ENGINE=InnoDB DEFAULT CHARSET=latin1 |
>
> Am I missing something? (besides the constraint ;)
>
> Regards,
>
> KlaasJan
>
> Confidentiality Statement:
>
> This message is intended only for the individual or entity to which it is 
> addressed. It may contain privileged, confidential information which is 
> exempt from disclosure under applicable laws. If you are not the intended 
> recipient, please note that you are strictly prohibited from disseminating or 
> distributing this information (other than to the intended recipient) or 
> copying this information. If you have received this communication in error, 
> please notify us immediately by return email.
> -----------------------------
>

Reply via email to