openjpa-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From macdoor <xd...@bj1860.net>
Subject Can @JoinTable be used in combination with @ManyToOne?
Date Sat, 10 Mar 2007 05:03:26 GMT

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.


Mime
View raw message