[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.rt.eclipselink] Re: Is TABLE PER CLASS supposed to work with eclipselink-2.0.0.v20090731-r4765 (m6)
|
Hello James,
thank you for your answer. I'm not quite sure what you mean by "include your mappings for both sides of the relationship". According to the JPA specification the annotations I provided for the mappings are sufficient. As far as I understood the specification (see below), table and column names are automatically created by the persistence provider if the annotations are omitted. I have a small self contained example which works with hibernate but fails with eclipselink when InheritanceType.TABLE_PER_CLASS is used. With InheritanceType.SINGLE_TABLE my example works with both providers. Unfortunately I haven't found out yet how I could attach my example to a message in this forum. Thanks again for looking into this.
Martin
2.10.4 Bidirectional ManyToMany Relationships
Assuming that:
Entity A references a collection of Entity B.
Entity B references a collection of Entity A.
Entity A is the owner of the relationship.
The following mapping defaults apply:
Entity A is mapped to a table named A.
Entity B is mapped to a table named B.
There is a join table that is named A_B (owner name first). This join table has two foreign key
columns. One foreign key column refers to table A and has the same type as the primary key of
table A. The name of this foreign key column is formed as the concatenation of the following:
the name of the relationship property or field of entity B; "_"; the name of the primary key col-
umn in table A. The other foreign key column refers to table B and has the same type as the pri-
mary key of table B. The name of this foreign key column is formed as the concatenation of the
following: the name of the relationship property or field of entity A; "_"; the name of the pri-
mary key column in table B.
Example:
@Entity
public class Project {
private Collection<Employee> employees;
@ManyToMany
public Collection<Employee> getEmployees() {
return employees;
}
public void setEmployees(Collection<Employee> employees) {
this.employees = employees;
}
...
}
@Entity
public class Employee {
private Collection<Project> projects;
@ManyToMany(mappedBy="employees")
public Collection<Project> getProjects() {
return projects;
}
public void setProjects(Collection<Project> projects) {
this.projects = projects;
}
...
}
In this example:
Entity Project references a collection of Entity Employee.
Entity Employee references a collection of Entity Project.
Entity Project is the owner of the relationship.
The following mapping defaults apply:
Entity Project is mapped to a table named PROJECT.
Entity Employee is mapped to a table named EMPLOYEE.
There is a join table that is named PROJECT_EMPLOYEE (owner name first). This join table
has two foreign key columns. One foreign key column refers to table PROJECT and has the
same type as the primary key of PROJECT. The name of this foreign key column is
PROJECTS_<PK of PROJECT>, where <PK of PROJECT> denotes the name of the primary
key column of table PROJECT. The other foreign key column refers to table EMPLOYEE and
has the same type as the primary key of EMPLOYEE. The name of this foreign key column is
EMPLOYEES_<PK of EMPLOYEE>, where <PK of EMPLOYEE> denotes the name of the
primary key column of table EMPLOYEE.
This is the entire output created by my example with eclipselink:
[java] Aug 26, 2009 7:12:08 PM org.eclipse.persistence.session.file:.../jpa/JPA-ManyToManyBidirectional/build/-JPAService_eclipselink
[java] INFO: EclipseLink, version: Eclipse Persistence Services - 2.0.0.v20090731-r4765
[java] Aug 26, 2009 7:12:08 PM org.eclipse.persistence.session.file:.../jpa/JPA-ManyToManyBidirectional/build/-JPAService_eclipselink
[java] SEVERE:
[java] Local Exception Stack:
[java] Exception [EclipseLink-0] (Eclipse Persistence Services - 2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.IntegrityException
[java] Descriptor Exceptions:
[java] ---------------------------------------------------------
[java] Exception [EclipseLink-80] (Eclipse Persistence Services - 2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.DescriptorException
[java] Exception Description: The relation key field [DEPARTMENT.departments_ID] for this mapping must exist in the relation table.
[java] Mapping: org.eclipse.persistence.mappings.ManyToManyMapping[students]
[java] Descriptor: RelationalDescriptor(Department --> [DatabaseTable(DEPARTMENT)])
[java] Exception [EclipseLink-41] (Eclipse Persistence Services - 2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.DescriptorException
[java] Exception Description: A non-read-only mapping must be defined for the sequence number field.
[java] Descriptor: RelationalDescriptor(Department --> [DatabaseTable(DEPARTMENT)])
[java] Runtime Exceptions:
[java] ---------------------------------------------------------
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:478)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:671)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:633)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:233)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:263)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:135)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:187)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:175)
[java] at Main.main(Main.java:12)
[java] Descriptor Exceptions:
[java] ---------------------------------------------------------
[java] Local Exception Stack:
[java] Exception [EclipseLink-80] (Eclipse Persistence Services - 2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.DescriptorException
[java] Exception Description: The relation key field [DEPARTMENT.departments_ID] for this mapping must exist in the relation table.
[java] Mapping: org.eclipse.persistence.mappings.ManyToManyMapping[students]
[java] Descriptor: RelationalDescriptor(Department --> [DatabaseTable(DEPARTMENT)])
[java] at org.eclipse.persistence.exceptions.DescriptorException.relationKeyFieldNotProperlySpecified(DescriptorException.java:1407)
[java] at org.eclipse.persistence.mappings.RelationTableMechanism.initializeSourceRelationKeys(RelationTableMechanism.java:464)
[java] at org.eclipse.persistence.mappings.RelationTableMechanism.initialize(RelationTableMechanism.java:304)
[java] at org.eclipse.persistence.mappings.ManyToManyMapping.initialize(ManyToManyMapping.java:394)
[java] at org.eclipse.persistence.descriptors.ClassDescriptor.initialize(ClassDescriptor.java:2608)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:449)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:671)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:633)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:233)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:263)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:135)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:187)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:175)
[java] at Main.main(Main.java:12)
[java] Local Exception Stack:
[java] Exception [EclipseLink-41] (Eclipse Persistence Services - 2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.DescriptorException
[java] Exception Description: A non-read-only mapping must be defined for the sequence number field.
[java] Descriptor: RelationalDescriptor(Department --> [DatabaseTable(DEPARTMENT)])
[java] at org.eclipse.persistence.exceptions.DescriptorException.mappingForSequenceNumberField(DescriptorException.java:910)
[java] at org.eclipse.persistence.internal.descriptors.ObjectBuilder.validate(ObjectBuilder.java:2815)
[java] at org.eclipse.persistence.descriptors.ClassDescriptor.selfValidationAfterInitialization(ClassDescriptor.java:3490)
[java] at org.eclipse.persistence.descriptors.ClassDescriptor.validateAfterInitialization(ClassDescriptor.java:5212)
[java] at org.eclipse.persistence.descriptors.ClassDescriptor.postInitialize(ClassDescriptor.java:3209)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:463)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:671)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:633)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:233)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:263)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:135)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:187)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:175)
[java] at Main.main(Main.java:12)
[java] Runtime Exceptions:
[java] ---------------------------------------------------------
[java] Aug 26, 2009 7:12:08 PM org.eclipse.persistence.session.file:.../jpa/JPA-ManyToManyBidirectional/build/-JPAService_eclipselink.ejb
[java] SEVERE:
[java] Local Exception Stack:
[java] Exception [EclipseLink-0] (Eclipse Persistence Services - 2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.IntegrityException
[java] Descriptor Exceptions:
[java] ---------------------------------------------------------
[java] Exception [EclipseLink-80] (Eclipse Persistence Services - 2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.DescriptorException
[java] Exception Description: The relation key field [DEPARTMENT.departments_ID] for this mapping must exist in the relation table.
[java] Mapping: org.eclipse.persistence.mappings.ManyToManyMapping[students]
[java] Descriptor: RelationalDescriptor(Department --> [DatabaseTable(DEPARTMENT)])
[java] Exception [EclipseLink-41] (Eclipse Persistence Services - 2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.DescriptorException
[java] Exception Description: A non-read-only mapping must be defined for the sequence number field.
[java] Descriptor: RelationalDescriptor(Department --> [DatabaseTable(DEPARTMENT)])
[java] Runtime Exceptions:
[java] ---------------------------------------------------------
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:478)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:671)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:633)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:233)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:263)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:135)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:187)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:175)
[java] at Main.main(Main.java:12)
[java] Descriptor Exceptions:
[java] ---------------------------------------------------------
[java] Local Exception Stack:
[java] Exception [EclipseLink-80] (Eclipse Persistence Services - 2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.DescriptorException
[java] Exception Description: The relation key field [DEPARTMENT.departments_ID] for this mapping must exist in the relation table.
[java] Mapping: org.eclipse.persistence.mappings.ManyToManyMapping[students]
[java] Descriptor: RelationalDescriptor(Department --> [DatabaseTable(DEPARTMENT)])
[java] at org.eclipse.persistence.exceptions.DescriptorException.relationKeyFieldNotProperlySpecified(DescriptorException.java:1407)
[java] at org.eclipse.persistence.mappings.RelationTableMechanism.initializeSourceRelationKeys(RelationTableMechanism.java:464)
[java] at org.eclipse.persistence.mappings.RelationTableMechanism.initialize(RelationTableMechanism.java:304)
[java] at org.eclipse.persistence.mappings.ManyToManyMapping.initialize(ManyToManyMapping.java:394)
[java] at org.eclipse.persistence.descriptors.ClassDescriptor.initialize(ClassDescriptor.java:2608)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:449)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:671)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:633)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:233)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:263)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:135)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:187)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:175)
[java] at Main.main(Main.java:12)
[java] Local Exception Stack:
[java] Exception [EclipseLink-41] (Eclipse Persistence Services - 2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.DescriptorException
[java] Exception Description: A non-read-only mapping must be defined for the sequence number field.
[java] Descriptor: RelationalDescriptor(Department --> [DatabaseTable(DEPARTMENT)])
[java] at org.eclipse.persistence.exceptions.DescriptorException.mappingForSequenceNumberField(DescriptorException.java:910)
[java] at org.eclipse.persistence.internal.descriptors.ObjectBuilder.validate(ObjectBuilder.java:2815)
[java] at org.eclipse.persistence.descriptors.ClassDescriptor.selfValidationAfterInitialization(ClassDescriptor.java:3490)
[java] at org.eclipse.persistence.descriptors.ClassDescriptor.validateAfterInitialization(ClassDescriptor.java:5212)
[java] at org.eclipse.persistence.descriptors.ClassDescriptor.postInitialize(ClassDescriptor.java:3209)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:463)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:671)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:633)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:233)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:263)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:135)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:187)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:175)
[java] at Main.main(Main.java:12)
[java] Runtime Exceptions:
[java] ---------------------------------------------------------
[java] Exception in thread "main" javax.persistence.PersistenceException: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.IntegrityException
[java] Descriptor Exceptions:
[java] ---------------------------------------------------------
[java] Exception [EclipseLink-80] (Eclipse Persistence Services - 2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.DescriptorException
[java] Exception Description: The relation key field [DEPARTMENT.departments_ID] for this mapping must exist in the relation table.
[java] Mapping: org.eclipse.persistence.mappings.ManyToManyMapping[students]
[java] Descriptor: RelationalDescriptor(Department --> [DatabaseTable(DEPARTMENT)])
[java] Exception [EclipseLink-41] (Eclipse Persistence Services - 2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.DescriptorException
[java] Exception Description: A non-read-only mapping must be defined for the sequence number field.
[java] Descriptor: RelationalDescriptor(Department --> [DatabaseTable(DEPARTMENT)])
[java] Runtime Exceptions:
[java] ---------------------------------------------------------
[java] at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:284)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.getServerSession(EntityManagerFactoryImpl.java:135)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManagerImpl(EntityManagerFactoryImpl.java:187)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:175)
[java] at Main.main(Main.java:12)
[java] Caused by: Exception [EclipseLink-0] (Eclipse Persistence Services - 2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.IntegrityException
[java] Descriptor Exceptions:
[java] ---------------------------------------------------------
[java] Exception [EclipseLink-80] (Eclipse Persistence Services - 2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.DescriptorException
[java] Exception Description: The relation key field [DEPARTMENT.departments_ID] for this mapping must exist in the relation table.
[java] Mapping: org.eclipse.persistence.mappings.ManyToManyMapping[students]
[java] Descriptor: RelationalDescriptor(Department --> [DatabaseTable(DEPARTMENT)])
[java] Exception [EclipseLink-41] (Eclipse Persistence Services - 2.0.0.v20090731-r4765): org.eclipse.persistence.exceptions.DescriptorException
[java] Exception Description: A non-read-only mapping must be defined for the sequence number field.
[java] Descriptor: RelationalDescriptor(Department --> [DatabaseTable(DEPARTMENT)])
[java] Runtime Exceptions:
[java] ---------------------------------------------------------
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:478)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:406)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.postConnectDatasource(DatabaseSessionImpl.java:671)
[java] at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.login(DatabaseSessionImpl.java:633)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerFactoryProvider.login(EntityManagerFactoryProvider.java:233)
[java] at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.deploy(EntityManagerSetupImpl.java:263)
[java] ... 4 more
[java] Java Result: 1