1.      Auto-create of tables is disabled.  I have <property
name="openjpa.jdbc.SynchronizeMappings" value="validate"/>

2.      Yes, there is an existing schema.  Following was manually
created on my SQLServer:

        CREATE TABLE person_addresses (
                person_ssn BIGINT references person,
                phone      VARCHAR(255) references address);

3.      The problem w/ suggested edit is that I cannot change the table
columns [to follow JPA conventions].  Instead, I need to make JPA fit
the existing schema. :(

4.      Is applying @SecondaryTable(name="person_addresses") on Address
entity a suitable workaround (... seems to avoid the exception I've been
getting)?  Any problems other than the performance hit [incurred by
extra join] when selecting Address?


SIDENOTE:

5.      I've also noticed that on case sensitive SQLServer collations
(e.g., "Latin1_General_BIN"), I get the following exception on
EntityManagerFactory.createEntityManager():

                Exception in thread "main"
<openjpa-2.0.0-beta-r422266:903062M fatal user error>
org.apache.openjpa.persistence.ArgumentException: "model.Address.person"
declares column "ADDRESS_PHONE", but this column does not exist in table
"dbo.person_addresses".

        Does OpenJPA assume that DB collation is always case
insensitive?

Thanks for your help!

- Howard

-----Original Message-----
From: Pinaki Poddar [mailto:ppod...@apache.org] 
Sent: Monday, June 07, 2010 11:28 PM
To: users@openjpa.apache.org
Subject: RE: bidirectional one-to-many relationship with join-table


Hi,
  1. what is the settings for openjpa.jdbc.SynchronizeMappings property?
  2. is there an existing schema?
  
I ran your example as it is to define the schema on a MySQL databse.
It ended up with three columns on PERSON_ADDRESSES join table
   CREATE TABLE person_addresses (
      ADDRESS_PHONE VARCHAR(255), 
      PERSON_SSN BIGINT, 
      phone VARCHAR(255))

Quite possibly a bug.

Editing line 03 of your mapping spec 

01: @JoinTable(name="person_addresses",
02:      joinColumns = @JoinColumn(name="person_ssn",
referencedColumnName="ssn"),
03:       inverseJoinColumns = @JoinColumn(name="phone",
referencedColumnName="phone")) 

Edit line 03 to
   inverseJoinColumns = @JoinColumn(name="address_phone",
referencedColumnName="phone")) 

Got rid of the third column on the join table.
But obviously naming of join table's columns has a problem that requires
further investigation. 
But see if the suggested edit helps. 

-----
Pinaki 
-- 
View this message in context:
http://openjpa.208410.n2.nabble.com/bidirectional-one-to-many-relationsh
ip-with-join-table-tp678479p5152078.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are addressed. 
Please note that any views or opinions presented in this email are solely those 
of the author and do not necessarily represent those of the company. Finally, 
the recipient should check this email and any attachments for the presence of 
viruses. The company accepts no liability for any damage caused by any virus 
transmitted by this email. If you have received this email in error please 
delete it and notify the system administrator at 
administra...@antennasoftware.com

Reply via email to