[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] ManyToOne on non primary keys

In looking at the code this is a bug, please log the issue in Bugzila,

https://bugs.eclipse.org/bugs/enter_bug.cgi?product=EclipseLink

As a workaround you can use a DescriptorCustomizer to configure the
OneToOneMapping through the EclipseLink code API (see docs on wiki).



machac wrote:
> 
> Halo,
> 
> there is the stack trace of this issue. If it is bug or not I don't know.
> I will wait for 
> your answer.
> Thank's
> Zdenek Machac
> 
> Exception [EclipseLink-7221] (Eclipse Persistence Services - 1.0.1 (Build
> 20080905)): 
> org.eclipse.persistence.exceptions.ValidationException
> Exception Description: A @JoinColumns was specified on the annotated
> element [private 
> jfx.ejb.entity.Ana jfx.ejb.entity.Zak.ana] from the entity class [class 
> jfx.ejb.entity.Zak]. When the source entity class uses a single primary
> key, only a single 
> (or zero) @JoinColumn should be specified.
>          at 
> org.eclipse.persistence.exceptions.ValidationException.excessiveJoinColumnsSpecified(ValidationException.java:2189)
>          at 
> org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.RelationshipAccessor.processJoinColumns(RelationshipAccessor.java:332)
>          at 
> org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.RelationshipAccessor.processJoinColumns(RelationshipAccessor.java:276)
>          at 
> org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ObjectAccessor.processOneToOneForeignKeyRelationship(ObjectAccessor.java:228)
>          at 
> org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ObjectAccessor.processOwningMappingKeys(ObjectAccessor.java:294)
>          at 
> org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.ManyToOneAccessor.process(ManyToOneAccessor.java:87)
>          at 
> org.eclipse.persistence.internal.jpa.metadata.accessors.mappings.RelationshipAccessor.processRelationship(RelationshipAccessor.java:363)
>          at 
> org.eclipse.persistence.internal.jpa.metadata.MetadataProject.processAccessorsWithRelationships(MetadataProject.java:643)
>          at 
> org.eclipse.persistence.internal.jpa.metadata.MetadataProject.process(MetadataProject.java:632)
>          at 
> org.eclipse.persistence.internal.jpa.metadata.MetadataProcessor.processORMMetadata(MetadataProcessor.java:452)
>          at 
> org.eclipse.persistence.internal.jpa.deployment.PersistenceUnitProcessor.processORMetadata(PersistenceUnitProcessor.java:303)
>          at 
> org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:830)
>          at 
> org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactory(PersistenceProvider.java:189)
>          at 
> weblogic.deployment.PersistenceUnitInfoImpl.createEntityManagerFactory(PersistenceUnitInfoImpl.java:330)
>          at 
> weblogic.deployment.PersistenceUnitInfoImpl.<init>(PersistenceUnitInfoImpl.java:123)
>          at 
> weblogic.deployment.AbstractPersistenceUnitRegistry.storeDescriptors(AbstractPersistenceUnitRegistry.java:331)
>          at 
> weblogic.deployment.AbstractPersistenceUnitRegistry.loadPersistenceDescriptors(AbstractPersistenceUnitRegistry.java:111)
>          at 
> weblogic.deployment.EarPersistenceUnitRegistry.<init>(EarPersistenceUnitRegistry.java:52)
>          at
> weblogic.application.internal.flow.JpaFlow.prepare(JpaFlow.java:54)
>          at
> weblogic.application.internal.BaseDeployment$1.next(BaseDeployment.java:615)
>          at 
> weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:37)
>          at
> weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.java:191)
>          at
> weblogic.application.internal.EarDeployment.prepare(EarDeployment.java:16)
>          at 
> weblogic.application.internal.DeploymentStateChecker.prepare(DeploymentStateChecker.java:155)
>          at 
> weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(AppContainerInvoker.java:60)
>          at 
> weblogic.deploy.internal.targetserver.operations.RedeployOperation.createAndPrepareContainer(RedeployOperation.java:98)
>          at 
> weblogic.deploy.internal.targetserver.operations.RedeployOperation.doPrepare(RedeployOperation.java:122)
>          at 
> weblogic.deploy.internal.targetserver.operations.AbstractOperation.prepare(AbstractOperation.java:217)
>          at 
> weblogic.deploy.internal.targetserver.DeploymentManager.handleDeploymentPrepare(DeploymentManager.java:723)
>          at 
> weblogic.deploy.internal.targetserver.DeploymentManager.prepareDeploymentList(DeploymentManager.java:1190)
>          at 
> weblogic.deploy.internal.targetserver.DeploymentManager.handlePrepare(DeploymentManager.java:248)
>          at 
> weblogic.deploy.internal.targetserver.DeploymentServiceDispatcher.prepare(DeploymentServiceDispatcher.java:159)
>          at 
> weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.doPrepareCallback(DeploymentReceiverCallbackDeliverer.java:157)
>          at 
> weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer.access$000(DeploymentReceiverCallbackDeliverer.java:12)
>          at 
> weblogic.deploy.service.internal.targetserver.DeploymentReceiverCallbackDeliverer$1.run(DeploymentReceiverCallbackDeliverer.java:45)
>          at 
> weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:516)
>          at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
>          at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
>  >
> 
> James Sutherland wrote:
>> This should work.  Please include the exception include stack trace that 
>> you
>> are getting.  It is most likely an issue with the annotations 
>> processing, as
>> EclipseLink does support ManyToOne's not by primary key.  If this is the
>> case, then please log a bug.
>> 
>> As a workaround you can use a DescriptorCustomizer to get the mapping
>> (OneToOneMapping) from the ClassDescriptor and reset the foreign key
>> fields
>> (probably easiest to set one foreign key in annotations to avoid
>> defaults,
>> then call addForeignKeyFieldName() to add the other).
>> 
>> 
>> 
>> machac wrote:
>>  >
>>  > Hallo,
>>  >
>>  > we have one problem:
>>  >
>>  > we use OpenJPA implementation and this use case works and we want 
>> migrate
>>  > to EclipseLink
>>  > but testing on entities
>>  >
>>  > public class Zak {
>>  >      @Id
>>  >      private int id;
>>  >
>>  >      @Column(name="zak_number")
>>  >      private String number;
>>  >
>>  >      @Column(name="zak_year")
>>  >      private int year;
>>  >
>>  >      @Column(name="zak_name")
>>  >      private String name;
>>  >
>>  >      @ManyToOne
>>  >      @JoinColumns({
>>  >          @JoinColumn(name="zak_ana",
>> referencedColumnName="ana_number"),
>>  >          @JoinColumn(name="zak_year", referencedColumnName="ana_year")
>>  >      })
>>  >      private Ana ana;
>>  >
>>  >      ...
>>  > }
>>  >
>>  >
>>  > public class Ana {
>>  >      @Id
>>  >      private int id;
>>  >
>>  >      @Column(name="ana_number")
>>  >      private String number;
>>  >
>>  >      @Column(name="ana_year")
>>  >      private int year;
>>  >
>>  >      @Column(name="ana_name")
>>  >      private String name;
>>  >
>>  >      ...
>>  > }
>>  >
>>  > failed because EclipseLink noted then Zak used 2 joined columns to
>> mapp
>>  > Ana but Ana has
>>  > only one primary key. Tables we can not changed because are from 
>> external
>>  > SW
>>  >
>>  > Supports EclipseLink mapping unidirectional ManyToOne to non pripary 
>> keys
>>  > columns?
>>  >
>>  > Thank's for any answer or help with such mapping.
>>  > Zdenek Machac
>> 
> 
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
> 
> 


-----
---
http://wiki.eclipse.org/User:James.sutherland.oracle.com James Sutherland 
http://www.eclipse.org/eclipselink/
 EclipseLink ,  http://www.oracle.com/technology/products/ias/toplink/
TopLink 
Wiki:  http://wiki.eclipse.org/EclipseLink EclipseLink , 
http://wiki.oracle.com/page/TopLink TopLink 
Forums:  http://forums.oracle.com/forums/forum.jspa?forumID=48 TopLink , 
http://www.nabble.com/EclipseLink-f26430.html EclipseLink 
Book:  http://en.wikibooks.org/wiki/Java_Persistence Java Persistence 
-- 
View this message in context: http://www.nabble.com/ManyToOne-on-non-primary-keys-tp19435773p19857939.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.