Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Multitenancy and @EmbeddedId(Got error Entity class [class entity.Customer] has both an @EmbdeddedId (on attribute [customerPK]) and an @Id (on attribute []. Both ID types cannot be specified on the same entity.)
Multitenancy and @EmbeddedId [message #965727] Wed, 31 October 2012 13:11 Go to next message
Ambroży Kleks is currently offline Ambroży Kleks
Messages: 2
Registered: October 2012
Junior Member
Hi,

Have simple entity with embeded ID:

@Entity
@Table(name = "customer", catalog = "db", schema = "")
@Multitenant(MultitenantType.SINGLE_TABLE)
@TenantDiscriminatorColumn(name = "tenant_id", contextProperty = "tenant.id", primaryKey = true)

@EmbeddedId
protected CustomerPK customerPK;
...

During start of application got errors:
Internal Exception: Exception [EclipseLink-7163] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.ValidationException
Exception Description: Entity class [class entity.Customer] has both an @EmbdeddedId (on attribute [customerPK]) and an @Id (on attribute []. Both ID types cannot be specified on the same entity.
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createPredeployFailedPersistenceException(EntityManagerSetupImpl.java:1541)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1532)
at org.eclipse.persistence.internal.jpa.deployment.JPAInitializer.callPredeploy(JPAInitializer.java:98)
at org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory(PersistenceProvider.java:108)



The problem is, I have no @ID in my entity, so why eclipselink complains about that?




Re: Multitenancy and @EmbeddedId [message #973636 is a reply to message #965727] Tue, 06 November 2012 13:51 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

My guess is it is related to your setting "primaryKey = true" in the @TenantDiscriminatorColumn. Try removing that.
It could be an issue with this flag and an @EmbeddedId, you could also try using an @IdClass instead.

If you can include your whole class, it would be easier to understand.


James : Wiki : Book : Blog : Twitter
Re: Multitenancy and @EmbeddedId [message #974673 is a reply to message #973636] Wed, 07 November 2012 08:35 Go to previous messageGo to next message
Ambroży Kleks is currently offline Ambroży Kleks
Messages: 2
Registered: October 2012
Junior Member
Hi, thanks for your answer. When set primaryKey = false, another error occurs

[EclipseLink-7337] (Eclipse Persistence Services - 2.4.1.v20121003-ad44345): org.eclipse.persistence.exceptions.ValidationException Exception Description: The mapped tenant discriminator column [db.customer.tenant_id] on the class [entity.Customer] must be marked as read only. In JPA this is done by setting insertable=false and updatable=false on the column e.g. @Column(name="TENANT_ID", insertable=false, updatable=false).
at org.eclipse.persistence.internal.sessions.DatabaseSessionImpl.initializeDescriptors(DatabaseSessionImpl.java:638)


I cannot set updatable=false because I have no @Column(name="TENANT_ID") in my Entity. My tenant_id is part of @EmbeddedId.

What actually primaryKey attribute means? And how to use it to start working. I tried to find any example on the net, but found nothing ;(
Re: Multitenancy and @EmbeddedId [message #982950 is a reply to message #974673] Tue, 13 November 2012 15:04 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Please log a bug for the issue with the EmeddedId, I think this could be an issue in multitenancy.

Can you remove your EmbeddedId, and remove using the TENANT_ID as part of your primary key? You could use a generated id instead.
Note, that you can put an @Column annotation on the Embeddedable that defines the EmbeddedId.


James : Wiki : Book : Blog : Twitter
Re: Multitenancy and @EmbeddedId [message #1008696 is a reply to message #982950] Wed, 13 February 2013 15:50 Go to previous message
John Goyer is currently offline John Goyer
Messages: 1
Registered: February 2013
Junior Member
There is an issue open for this bug -- https://bugs.eclipse.org/bugs/show_bug.cgi?id=367241.
Previous Topic:Not able to build a criteria with "like expression"
Next Topic:Simple Auditing Example
Goto Forum:
  


Current Time: Mon Sep 22 16:19:32 GMT 2014

Powered by FUDForum. Page generated in 0.02443 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software