@Multitenant @Inheritance Single table causing inconsistence issues for save

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

@Multitenant @Inheritance Single table causing inconsistence issues for save

Sowmiya
This post was updated on .
@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.
>
> After some more debugging I figured, in this method
> *org.eclipse.persistence.internal.sessions.DatabaseSessionIm
> pl#initializeDescriptors(java.util.Collection,
> boolean) *, based on the order in which the descriptors are processed, the
> result varies.
>
> What is the logic behind the order in which the entities are processed to
> initialize the metadata? Can I influence the order in which it is
> processed?
>
> Version of eclipse link used is 2.5.1.
>
>

_______________________________________________
eclipselink-users mailing list
eclipselink-users@eclipse.org
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: @Multitenant @Inheritance Single table causing inconsistence issues for save

William Dazey
I would suggest not naming your EmbeddedId class "EmbeddedId". Im guessing this class name was changed to post in your email, but incase it wasnt, it may be worth renaming and retesting since these kind of namespace collisions can lead to non-deterministic behavior when classloading.

Also, I am not familiar with @Multitenant annotation, but taking a look at the wiki (http://www.eclipse.org/eclipselink/documentation/2.5/jpa/extensions/a_multitenant.htm), two things are listed as for @Multitenant(TABLE_PER_TENANT):

    To configure table-per-tenant multitenancy, you must specify:

  • A table-per-tenant property to identify the user. This can be set per entity manager, or it can be set at the entity manager factory to isolate table-per-tenant per persistence unit.)

  • A tenant table discriminator to identify and isolate the tenant's tables from other tenants' tables. The discriminator types are SCHEMA, SUFFIX, and PREFIX. For more information about tenant discriminator types, see "@TenantTableDiscriminator".


Maybe someone more familiar with the use of @Multitenant can expand on it's usage.



On Tue, Dec 26, 2017 at 6:06 AM, Sowmiya Chellamuthu <[hidden email]> wrote:


@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.

After some more debugging I figured, in this method
*org.eclipse.persistence.internal.sessions.DatabaseSessionImpl#initializeDescriptors(java.util.Collection,
boolean) *, based on the order in which the descriptors are processed, the
result varies.

What is the logic behind the order in which the entities are processed to
initialize the metadata? Can I influence the order in which it is processed?

Version of eclipse link used is 2.5.1.




_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: @Multitenant @Inheritance Single table causing inconsistence issues for save

Sowmiya
William,

Thanks for your inputs.

EmbeddedID as class name is for illustration purpose only. Actual class name is different.

As for the multitenant settings, it is being set while creating the EntityManager.

In fact, the @Mutitenant(TABLE_PER_ENTITY)  setup works fine with entities where there is no Inheritance concept.

On Wed, Dec 27, 2017 at 4:19 AM, William Dazey <[hidden email]> wrote:
I would suggest not naming your EmbeddedId class "EmbeddedId". Im guessing this class name was changed to post in your email, but incase it wasnt, it may be worth renaming and retesting since these kind of namespace collisions can lead to non-deterministic behavior when classloading.

Also, I am not familiar with @Multitenant annotation, but taking a look at the wiki (http://www.eclipse.org/eclipselink/documentation/2.5/jpa/extensions/a_multitenant.htm), two things are listed as for @Multitenant(TABLE_PER_TENANT):

    To configure table-per-tenant multitenancy, you must specify:

  • A table-per-tenant property to identify the user. This can be set per entity manager, or it can be set at the entity manager factory to isolate table-per-tenant per persistence unit.)

  • A tenant table discriminator to identify and isolate the tenant's tables from other tenants' tables. The discriminator types are SCHEMA, SUFFIX, and PREFIX. For more information about tenant discriminator types, see "@TenantTableDiscriminator".


Maybe someone more familiar with the use of @Multitenant can expand on it's usage.



On Tue, Dec 26, 2017 at 6:06 AM, Sowmiya Chellamuthu <[hidden email]> wrote:


@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.

After some more debugging I figured, in this method
*org.eclipse.persistence.internal.sessions.DatabaseSessionImpl#initializeDescriptors(java.util.Collection,
boolean) *, based on the order in which the descriptors are processed, the
result varies.

What is the logic behind the order in which the entities are processed to
initialize the metadata? Can I influence the order in which it is processed?

Version of eclipse link used is 2.5.1.




_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


_______________________________________________
eclipselink-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipselink-users