Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Error Mapping a Join Table with Additional Columns

Hi!

I'm trying develop a ManytoMany relation with attributes in the join table
and I obtain always the same error "There should be one non-read-only
mapping defined for the primary key field", but I don't understand why.

I tried different alternatives and I managed to make it work but I think
they are not the correct method (using @IdClass or forcing join attributes)
 
I know it is more correct to use a generated Id attribute to the association
class, but I am making an study of eclipselink as a development platform and
I want to learn more about its operation.

Thanks in anticipation!

Best Regards, 
Daniel R. Criado


===========
Error description:
===========

Exception [EclipseLink-46] (Eclipse Persistence Services - 1.1.0.r3634):
org.eclipse.persistence.exceptions.DescriptorException
Exception Description: There should be one non-read-only mapping defined for
the primary key field [test4_5.test4_id].
Descriptor: RelationalDescriptor(leandra.test1_6_2.Test45 -->
[DatabaseTable(test4_5)])

Runtime Exceptions: 
---------------------------------------------------------

	at
org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:477)
	at
org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
	at
org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:666)
	at
org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:630)
	at
org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:229)
	at
org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:255)
	at
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:111)
	at
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:163)
	at
org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:150)
	at
org.springframework.orm.jpa.JpaTransactionManager.createEntityManagerForTransaction(JpaTransactionManager.java:392)
	at
org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:320)
	at
org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:374)
	at
org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:263)
	at
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:101)
	at
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
	at
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
	at $Proxy22.storeTest4(Unknown Source)
	at leandra.test1_6_2.TestJpaSpring.test(TestJpaSpring.java:21)
	at leandra.test1_6_2.TestJpaSpring.main(TestJpaSpring.java:11)
	
===========
Platform:
===========

- EclipseLink version: 1.1.0.r3634 (using javax.persistent_1.99)
- Spring Framework 2.5.6
- MySQL 5.1.33

===========
Code:
===========

@Entity
public class Test4 implements Serializable {
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;

	private String name;

	@OneToMany(mappedBy="test4")
	private Set<Test45> test45Collection;

	private static final long serialVersionUID = 1L;

	public Test4() {
		super();
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<Test45> getTest45Collection() {
		return this.test45Collection;
	}

	public void setTest45Collection(Set<Test45> test45Collection) {
		this.test45Collection = test45Collection;
	}

}

@Entity
public class Test5 implements Serializable {
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;

	private String name;

	@OneToMany(mappedBy="test5")
	private Set<Test45> test45Collection;

	private static final long serialVersionUID = 1L;

	public Test5() {
		super();
	}

	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Set<Test45> getTest45Collection() {
		return this.test45Collection;
	}

	public void setTest45Collection(Set<Test45> test45Collection) {
		this.test45Collection = test45Collection;
	}

}

@Entity
@Table(name="test4_5")
public class Test45 implements Serializable {
	@EmbeddedId
	private Test45PK pk;

	private boolean active;

	@ManyToOne
	private Test4 test4;

	@ManyToOne
	private Test5 test5;

	private static final long serialVersionUID = 1L;

	public Test45() {
		super();
	}
	
	public Test45PK getPk() {
		return this.pk;
	}
	
	public void setPk(Test45PK pk) {
		this.pk = pk;
	}

	public boolean getActive() {
		return this.active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public Test4 getTest4() {
		return this.test4;
	}

	public void setTest4(Test4 test4) {
		this.test4 = test4;
	}

	public Test5 getTest5() {
		return this.test5;
	}

	public void setTest5(Test5 test5) {
		this.test5 = test5;
	}

}

@Embeddable
public class Test45PK implements Serializable {
	@Column(name="test4_id", insertable=false, updatable=false)
	private int test4Id;

	@Column(name="test5_id", insertable=false, updatable=false)
	private int test5Id;

	private static final long serialVersionUID = 1L;

	public Test45PK() {
		super();
	}

	public int getTest4Id() {
		return this.test4Id;
	}

	public void setTest4Id(int test4Id) {
		this.test4Id = test4Id;
	}

	public int getTest5Id() {
		return this.test5Id;
	}

	public void setTest5Id(int test5Id) {
		this.test5Id = test5Id;
	}

	@Override
	public boolean equals(Object o) {
		if (o == this) {
			return true;
		}
		if ( ! (o instanceof Test45PK)) {
			return false;
		}
		Test45PK other = (Test45PK) o;
		return (this.test4Id == other.test4Id)
			&& (this.test5Id == other.test5Id);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int hash = 17;
		hash = hash * prime + this.test4Id;
		hash = hash * prime + this.test5Id;
		return hash;
	}

}
-- 
View this message in context: http://www.nabble.com/Error-Mapping-a-Join-Table-with-Additional-Columns-tp23556016p23556016.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top