Bug 528997 - Using @Multitenant along with @Inheritance(SINGLE_TABLE) annotation causing inconsistent failure
Summary: Using @Multitenant along with @Inheritance(SINGLE_TABLE) annotation causing i...
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 critical (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: core
Depends on:
Blocks:
 
Reported: 2017-12-20 05:05 EST by Sowmiya Chellamuthu CLA
Modified: 2022-06-09 10:15 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sowmiya Chellamuthu CLA 2017-12-20 05:05:34 EST
@MappedSuperClass
public abstract class BaseMappedSuperClass {
   @EmbeddedId  
   private EmbeddedId id;
}

@Entity
@Multitenant(MultitenantType.TABLE_PER_TENANT)
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "typeCol")
public abstract class Vehicle extends BaseMappedSuperClass{
   private String name;
}

@Entity(name = "Cycle")
@Multitenant(MultitenantType.TABLE_PER_TENANT)
@DiscriminatorValue(value = "Cycle")
public class Cycle extends Vehicle {
   private String bellType;
}

@Entity(name = "Bus")
@Multitenant(MultitenantType.TABLE_PER_TENANT)
@DiscriminatorValue(value = "Bus")
public class Bus extends Vehicle {
   private String gearType;
}

I have the above entity structure and if I try to do an insert op on the entity Cycle or Bus, it fails inconsistently, because of the missing primary key field (id).

When I tried to debug the JPA codebase, I figured that the tenant discriminator, which is tenant_id in my case is not appended to the table name prefix for the embeddedId field 'Id' and the discriminator column field 'typeCol'.

What is more interesting is that this behavior is not consistent. If I restart my application and try, it works. If I restart again and try,it does not work.
Comment 1 Sowmiya Chellamuthu CLA 2017-12-26 06:19:49 EST
org.eclipse.persistence.internal.sessions.DatabaseSessionImpl#initializeDescriptors(java.util.Collection, boolean) 

The above method processes the descriptors for the entities defined.  Here based on the order in which it is being processed, the issue occurs or not.
Comment 2 Eclipse Webmaster CLA 2022-06-09 10:10:06 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 3 Eclipse Webmaster CLA 2022-06-09 10:15:26 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink