You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@openjpa.apache.org by macdoor <xd...@bj1860.net> on 2007/03/10 06:03:26 UTC

Can @JoinTable be used in combination with @ManyToOne?

Can I map a many to one association through a join table (association table)?

Like this, BSC->MSC is many to one relationship, and I want to store
relationship in a join table (MSC_BSC).

@Entity
public class Bsc {

    @Id
    protected long objid;
    @Id
    @Column(nullable=false)
    protected String objname;
    @Basic
    protected String objclass;
    @Basic
    protected Calendar created;
    @Basic
    protected String msc_name;

    @OneToMany(cascade={CascadeType.PERSIST,CascadeType.REMOVE},
fetch=FetchType.EAGER)
    protected List<Bts> bts;
    
    @ManyToOne(fetch=FetchType.EAGER)
    @InverseLogical
    @JoinTable(name="MSC_BSC",
    		inverseJoinColumns ={
    			@JoinColumn( name="msc_objid", referencedColumnName="objid"),
    			@JoinColumn( name="msc_oc", referencedColumnName="objclass")},
    		joinColumns ={
    			@JoinColumn( name="bsc_objid",referencedColumnName="objid"),
    			@JoinColumn( name="bsc_oc",referencedColumnName="objclass")})
    protected Msc msc;
...

I get the following exceptions,

Exception in thread "main" <4|true|0.9.7-incubating-SNAPSHOT>
org.apache.openjpa.persistence.ArgumentException: You have supplied columns
for "dmpjaxb.gen.Bsc.msc<element:class java.lang.Object>", but this mapping
cannot have columns in this context.
	at
org.apache.openjpa.jdbc.meta.MappingInfo.assertNoSchemaComponents(MappingInfo.java:323)
	at
org.apache.openjpa.jdbc.meta.strats.RelationFieldStrategy.map(RelationFieldStrategy.java:78)
	at
org.apache.openjpa.jdbc.meta.FieldMapping.setStrategy(FieldMapping.java:117)
	at
org.apache.openjpa.jdbc.meta.RuntimeStrategyInstaller.installStrategy(RuntimeStrategyInstaller.java:77)
	at
org.apache.openjpa.jdbc.meta.FieldMapping.resolveMapping(FieldMapping.java:435)
	at org.apache.openjpa.jdbc.meta.FieldMapping.resolve(FieldMapping.java:400)
	at
org.apache.openjpa.jdbc.meta.ClassMapping.resolveMapping(ClassMapping.java:781)
	at org.apache.openjpa.meta.ClassMetaData.resolve(ClassMetaData.java:1570)
	at
org.apache.openjpa.meta.MetaDataRepository.processBuffer(MetaDataRepository.java:656)
	at
org.apache.openjpa.meta.MetaDataRepository.resolveMapping(MetaDataRepository.java:617)
	at
org.apache.openjpa.meta.MetaDataRepository.resolve(MetaDataRepository.java:495)
	at
org.apache.openjpa.meta.MetaDataRepository.getMetaData(MetaDataRepository.java:285)
	at
org.apache.openjpa.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:276)
	at
org.apache.openjpa.jdbc.meta.MappingTool.getMapping(MappingTool.java:667)
	at
org.apache.openjpa.jdbc.meta.MappingTool.buildSchema(MappingTool.java:739)
	at org.apache.openjpa.jdbc.meta.MappingTool.run(MappingTool.java:637)
	at
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.synchronizeMappings(JDBCBrokerFactory.java:161)
	at
org.apache.openjpa.jdbc.kernel.JDBCBrokerFactory.newBrokerImpl(JDBCBrokerFactory.java:127)
	at
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:171)
	at
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:139)
	at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:187)
	at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:140)
	at
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:52)
	at dmpjaxb.Main.main(Main.java:50)

I want to know is this a limitation of OpenJPA or standard of JPA?
-- 
View this message in context: http://www.nabble.com/Can-%40JoinTable-be-used-in-combination-with-%40ManyToOne--tf3379841.html#a9407355
Sent from the open-jpa-dev mailing list archive at Nabble.com.


Re: Can @JoinTable be used in combination with @ManyToOne?

Posted by Abe White <aw...@bea.com>.
> Can I map a many to one association through a join table  
> (association table)?

You can't use a join table, but you can put your many-one foreign key  
column(s) in a secondary table, which amounts to the same thing.
_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.