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

@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

This widget could not be displayed.

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

This widget could not be displayed.

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?

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.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in Teamwork

What teamwork quotes inspire you?

Hey everyone! My name is Natalie and I'm an editor of the Atlassian Blog and I've got a question for you: What's your favorite quote about teamwork?  We've compiled a list here, along with...

134 views 16 7
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you