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

1 vote

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

0 vote

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 Join to answer
Community showcase
Maarten Cautreels
Posted Thursday in Off-topic

Friday Fun: What's your favourite beer/drink

As a Belgian, beer-lover and home brewer, beer is one of my great passions. I love the fact that with just a few ingredients (usually just water, hop and malt) you can create so many different tastes...

281 views 38 9
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot