You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by it...@daimler.com on 2009/05/25 11:44:38 UTC

Two Entities in an inheritance strategy InheritanceStrategy.JOINED -> always uses most specific Entity

Hello,

In our database model, we have a relationship between a table called 
'Partner' and a table called 'Vertriebspartner' that specializes the first 
by adding more information to the 'Partner'. However, there is not always 
an entry in the table 'Vertriebspartner' for every 'Partner'.

In my model I currently have the following inheritance relation defined 
for these two tables:

@Entity
@Table(name = "PARTNER", schema = "PART")
public class Partner
{
    @Id
    @Column(name = "PART_KEY")
    private BigDecimal partKey;
}

@Entity
@Table(name = "VERTRIEBSPARTNER")
@Inheritance(strategy = InheritanceType.JOINED)
@AttributeOverride(name="version", column=@Column(name="VERSION")) 
public class Vertriebspartner extends Partner 
{
}

I now have the problem, that in case I use a 'Partner' in a OneToMany or 
ManyToOne-Relationship, openJPA always tries (even though i use Partner 
and NOT Vertriebspartner) to join both. This leads to missing entries, as 
the join often leads to no entry at all, but there is definilty a Partner.

Thus:

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "PART_KEY", table = "WBZ_V")
private Partner partner;

ends in a select that joins Partner and Vertriebspartner. I even tried to 
apply targetEntity = Partner.class to the ManyToOne, but that did not help 
at all.

What do I do wrong here? Is the joined inheritance strategy not ment to be 
used when there is not always an entry available in the more specialized 
table? Is this maybe a problem in openJPA?

Thanks,

Heiko

If you are not the intended addressee, please inform us immediately that you have received this e-mail in error, and delete it. We thank you for your cooperation.