AO - neat way for multiple OneToOne type references in a type

Andy Brook [Plugin People]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 19, 2012

@OneToOne allows mapping of Types in AO, but how AO maps these is done from the direction of WindowType, (i.e. setX on WindowType), and will work fine, for exactly one method, but not so much for mulitple methods, to illustrate the point, the following Entity X will not be able to return different values due to lack of a discriminator:

interface X extends Entity { 
@OneToOne WindowTypeXref getTheSquareWindow(); 
@OneToOne WindowTypeXref getTheRoundWindow(); 
@OneToOne WindowTypeXref getTheOvalWindow();
}

interface WindowTypeXref extends Entity { 
public X getX(); 
public void setX(X anX); 
public void setWindowType(WindowType t); 
public WindowType getWindowType(); 
}

Ideally I'd like to be able to add a where clause to @OneToOne, eg (@Discriminator="SOMECOL='oval'"). With that future feature out there, I'm currently left with:

1) storing the KEY to the XREF in X (I'd do this to be able to have a many to one reference from Xref to WindowType)

2) having multiple tables, one per 'method' in X (Id rather not increase in table cruft)

Is there a neater solution?

2 answers

1 accepted

1 vote
Answer accepted
Samuel Le Berrigaud
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 4, 2012

Hey Andy,

I think I found a way that would satisfy you, but there seem to be some caching issue preventing this from working as expected, see https://studio.atlassian.com/browse/AO-313

0 votes
Samuel Le Berrigaud
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 28, 2012

Why don't you define your entities like so?

interface X extends Entity
{ 
    WindowTypeXref getTheSquareWindow();
    void setTheSquareWindow(WindowTypeXref w);
 
    WindowTypeXref getTheRoundWindow();
    void setTheRoundWindow(WindowTypeXref w);

    WindowTypeXref getTheOvalWindow();
    void setTheOvalWindow(WindowTypeXref w);
}

interface WindowTypeXref extends Entity
{ 
    @OneToOne public X getX(); 

    void setWindowType(WindowType t); 
    WindowType getWindowType(); 
}

Isn't that achieving the same, or am I missing something?

Andy Brook [Plugin People]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 29, 2012

Hi Sam, let me restate, perhaps I gave a bad example. Putting into terms I can relate to today, so I have a [Config] which can be many, I have [TemplateSets] which can be many, but each TemplateSet has a type identifier (window analogy). Wahat I wanted to do was have mulitple methods in [Config] retrieving a specific [TemplateSet] through an Xref, which is why @onetoone didnt work, as "there can be only one" reference per table?

In any case, for now, I resorted to breaking referential integrity and just storing the ID of the [TemplateSet] three times, in the [Config], which works fine, with surrounding logic to protect deletion etc. It also allow relatively simple determination from [TemplateSet] waht [Config] refer to it.

Andy Brook [Plugin People]
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
March 4, 2012

Yup, looks to be what I would like, but as you say, caching may be a problem, I'm watching for future comment, thanks!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events