openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marc Prud'hommeaux <>
Subject Re: Sqeuences, Foreign Keys and Master-detail Relationship
Date Fri, 27 Jul 2007 19:51:07 GMT

On Jul 27, 2007, at 9:23 AM, YanSh wrote:

> Hi.
> I have a few questions. If anyone can answer any of the 3, I would  
> really
> appreciated it.
> 1. We have problems using sequences, sometimes the correct id is  
> not given
> back, but instead they send back a zero id. Can anyone tell me what is
> causing this?

Can you show us how you are declaring the sequences?

> 2. We have problems with foreign keys ( generation and referencing).

We'd need more details about your mappings and sequences and a  
description of the actual problem to hope to help with this.

> 3. There seems to be problems with out of order writing for master- 
> detail
> relationships. ( detail records are written before master thus making
> referntial integrity violation on detail table.) Is it possible to  
> receive
> any timeframe estimations  for this problem to be fixed?

Your problem that OpenJPA does not read foreign keys by default. The  
following excerpt from OPENJPA-39 might be helpful:

OpenJPA has to know where the DB foreign keys are.  You have a few  

- Using the org.apache.openjpa.persistence.ForeignKey annotation, and  
related annnotations
(ElementForeignKey, etc) to tell OpenJPA exactly which relations and  
joins have foreign keys
on them.
- Setting the "openjpa.jdbc.SchemaFactory" property to "native 
(ForeignKeys=true)" will tell
OpenJPA to read the existing schema from the DB, including foreign  
key locations, using JDBC
schema reflection.  Under this setting OpenJPA will also validate  
that the schema and mappings
-  Setting the "openjpa.jdbc.MappingDefaults" property to "jpa 
JoinForeignKeyDeleteAction=restrict)" will tell OpenJPA to just  
assume that all relations
and joins are backed by database foreign keys.

The first and third options also affect schema creation, in that  
OpenJPA's schema creation
tools will add foreign keys to to the annotated relations and joins /  
to all relations and
joins under those settings.

> Many thanks.
> Yan
> -- 
> View this message in context: 
> Foreign-Keys-and-Master-detail-Relationship-tf4158883.html#a11832433
> Sent from the OpenJPA Developers mailing list archive at

View raw message