Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Multi level inheritance example

No, it can't handle this way

Here's a SQL statement from what has been generated for a HarmNotification query:

SELECT CO_SEQ_NOTIFICATION, ... FROM TB_NOTIFICATION
WHERE ((CO_SEQ_NOTIFICATION = ?) AND (TP_NOTIFICATION IN (?, ?, ?, ?, ?, ?, ?)))
    bind => [4, I, DG, CQ, PA, DE, VL, ME]

It should have been
WHERE ((CO_SEQ_NOTIFICATION = ?) AND TP_NOTIFICATION = '?' AND (TP_HARM IN (?, ?, ?, ?, ?, ?)))
    bind => [4, I, DG, CQ, PA, DE, VL, ME]


So i tried to use JOINED on Notification class as you suggested, but then it fails looking for an unknown HarmNotification table.

Not sure if it can just be done using Tenant, but if so it's gonna be a problem to update all the repositories to set this on EntityManager.

Any other thoughts?

Thanks


2013/6/11 Guy Pelletier <guy.pelletier@xxxxxxxxxx>
Just to follow up some more. What will happen in this case is the second @Inheritance metadata (along with The @DiscriminatorColumn will be ignored) and you'll remain within a single @Inheritance(SINGLE_TABLE) hierarchy from Notification.

Perhaps what you want is? Are you generating the tables or mapping to an existing schema?

@Inheritance(JOINED)
class Notification

@Inheritance(SINGLE_TABLE)
@DiscriminatorValue("I") // TP_NOTIFICATION
@DiscriminatorColumn(name="TP_HARM" ,...)
class HarmNotification extends Notification

@DiscriminatorValue("DG") //TP_HARM
class DengueNotification extends HarmNotification

@DiscriminatorValue("N") // TP_NOTIFICATION
class NegativeNotification extends Notification

Cheers,
Guy

On 11/06/2013 10:19 AM, Luciano Santos wrote:
I'll try this out... Hibernate can't handle this for sure.


2013/6/11 Guy Pelletier <guy.pelletier@xxxxxxxxxx>
Hi Luciano,

That model in theory is valid and should work yes. Let us know if you encounter any issues.

Cheers,
Guy


On 11/06/2013 10:09 AM, Luciano Santos wrote:
Hi Guy,

Thanks for your answer. Actually i don't think the standard JPA behavior is enogh for me (unless EclipseLink is smart enough to handle it), because two levels of inheritance.

HarmNotification extensions have all TP_NOTIFICATION = 'I" plus a TP_HARM value to identify itself (Ex.: DG for DengueNotification, IN for InfuenzaNotification)
NegativeNotification doesn't qualify as a HarmNotification, it's just a Notification, and it does't have any harm associated of course, so it just hava TP_NOTIFICATION = 'N'

I agree that the best scenario for me would to have like you said something like this:

@Inheritance(SINGLE_TABLE)
@DiscriminatorColumn(name="TP_NOTIFICATION" ,...)
class Notification

@Inheritance(SINGLE_TABLE)
@DiscriminatorValue("I") // TP_NOTIFICATION
@DiscriminatorColumn(name="TP_HARM" ,...)
class HarmNotification extends Notification

@DiscriminatorValue("DG") //TP_HARM
class DengueNotification extends HarmNotification

@DiscriminatorValue("N") // TP_NOTIFICATION
class NegativeNotification extends Notification

But i am pretty sure it doesn't work right?

Thanks

2013/6/11 Guy Pelletier <guy.pelletier@xxxxxxxxxx>
Luciano,

@TenantDiscriminatorColumn is defaulting the contextProperty to
eclipselink.tenant-id therefore you must set the default contextProperty, that is, eclipselink.tenant-id either in your persistence.xml, or per entity manager. Eg. em.setProperty("eclipselink.tenant-id", value);

Also, please note your are using multitenancy but given the subject I wonder if you meant to use

@Inheritance(SINGLE_TABLE)

@DiscriminatorColumn(name ="TP_NOTIFICATION")

instead?

Cheers,
Guy

On 11/06/2013 8:25 AM, Luciano Santos wrote:
Hello.

I am struggling a little bit to make this single table two level/two column inheritance:

@Multitenant(SINGLE_TABLE)
@TenantDiscriminatorColumn(name = "TP_NOTIFICATION")
public abstract class Notification
...
@Column(name = "TP_NOTIFICATION", length = 1, insertable=false, updatable=false)
    private NotificationType type;
...
}

@DiscriminatorValue("N")
class NegativeNotification extends Notification {}

@DiscriminatorValue("H")
@TenantDiscriminatorColumn(name="TP_HARM", length=2)
class HarmNotification
...
    @Column(name = "TP_HARM", insertable=false, updatable=false)
    private HarmType harmType;
...
}

@DiscriminatorValue("IN")
class InfluenzaNotification extends HarmNotification

@DiscriminatorValue("PE")
class PertussisNotification extends HarmNotification

...

So far the deployment is OK, but a query for HarmNotification fails on the say to try a store operation:
Exception Description: No value was provided for the session property [eclipselink.tenant-id]. This exception is possible when using additional criteria or tenant discriminator columns without specifying the associated contextual property. These properties must be set through Entity Manager, Entity Manager Factory or persistence unit properties. If using native EclipseLink, these properties should be set directly on the session.
Query: ReadAllQuery(referenceClass=HarmNotification sql="SELECT t0.CO_SEQ_...

Do you guys have an example on how i need to declare this to make it work?

Thanks

Luciano G Santos


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users

--

Oracle
Guy Pelletier

ORACLE Canada, 45 O'Connor Street Suite 400 Ottawa, Ontario Canada K1P 1A4

Green Oracle Oracle is committed to developing practices and products that help protect the environment


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users



--

Oracle
Guy Pelletier

ORACLE Canada, 45 O'Connor Street Suite 400 Ottawa, Ontario Canada K1P 1A4

Green Oracle Oracle is committed to developing practices and products that help protect the environment



--

Oracle
Guy Pelletier

ORACLE Canada, 45 O'Connor Street Suite 400 Ottawa, Ontario Canada K1P 1A4

Green
            Oracle Oracle is committed to developing practices and products that help protect the environment



Back to the top