openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Howard Mak" <h...@antennasoftware.com>
Subject RE: bidirectional one-to-many relationship with join-table
Date Mon, 07 Jun 2010 22:08:25 GMT
Thanks.

@Entity
@Table(name="person")
public class Person { 
   @Id
   private long ssn;
   
   @OneToMany(cascade=CascadeType.ALL) 
   @JoinTable(name="person_addresses", 
       joinColumns        = @JoinColumn(name="person_ssn",
referencedColumnName="ssn"), 
       inverseJoinColumns = @JoinColumn(name="phone",
referencedColumnName="phone")) 
    private Set<Address> addresses = new HashSet<Address>();

@Entity
@Table(name="address")
public class Address { 
   @Id 
   private String phone; 

   @ManyToOne(fetch=FetchType.LAZY)
   @JoinColumn(table="person_addresses", referencedColumnName="ssn") 
   private Person person;
}

results in

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".
	at
org.apache.openjpa.jdbc.meta.MappingInfo.mergeColumn(MappingInfo.java:69
2)
	at
org.apache.openjpa.jdbc.meta.MappingInfo.createJoins(MappingInfo.java:13
04)
	at
org.apache.openjpa.jdbc.meta.MappingInfo.createForeignKey(MappingInfo.ja
va:1084)
	at
org.apache.openjpa.jdbc.meta.FieldMappingInfo.getJoin(FieldMappingInfo.j
ava:213)
	at
org.apache.openjpa.jdbc.meta.FieldMappingInfo.getJoin(FieldMappingInfo.j
ava:182)
	at
org.apache.openjpa.jdbc.meta.FieldMapping.mapJoin(FieldMapping.java:585)
	at
org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.map(RelationFi
eldStrategy.java:162)
	at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:
146)
	at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(Ru
ntimeStrategyInstaller.java:78)
	at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.ja
va:496)
	at
org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:461)
	at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.ja
va:853)
	at
org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1711)
	at
org.apache.openjpa.meta.MetaDataRepository.processBuffer(MetaDataReposit
ory.java:786)
	at
org.apache.openjpa.meta.MetaDataRepository.resolveMapping(MetaDataReposi
tory.java:747)
	at
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.ja
va:631)
	at
org.apache.openjpa.meta.MetaDataRepository.getMetaDataInternal(MetaDataR
epository.java:385)
	at
org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepositor
y.java:358)
	at
org.apache.openjpa.jdbc.meta.MappingRepository.getMapping(MappingReposit
ory.java:355)
	at
org.apache.openjpa.jdbc.meta.MappingTool.getMapping(MappingTool.java:679
)
	at
org.apache.openjpa.jdbc.meta.MappingTool.validate(MappingTool.java:737)
	at
org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:653)
	at
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDB
CBrokerFactory.java:149)
	at
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDB
CBrokerFactory.java:159)
	at
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBroke
rFactory.java:117)
	at
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBroker
Factory.java:194)
	at
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBr
okerFactory.java:152)
	at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityMana
ger(EntityManagerFactoryImpl.java:200)
	at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityMana
ger(EntityManagerFactoryImpl.java:151)
	at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityMana
ger(EntityManagerFactoryImpl.java:57)

but if I add @SecondaryTable
    @SecondaryTable(name="person_addresses",
pkJoinColumns=@PrimaryKeyJoinColumn(name="phone"))
    public class Address { 
    }

The exception goes away.  This is with Open JPA 2.0.0.  Is this a bug?

- Howard 

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


See @JoinColumn annotation

-----
Pinaki 
-- 
View this message in context:
http://openjpa.208410.n2.nabble.com/bidirectional-one-to-many-relationsh
ip-with-join-table-tp678479p5150661.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 administrator@antennasoftware.com

Mime
View raw message