@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?
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
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yup, looks to be what I would like, but as you say, caching may be a problem, I'm watching for future comment, thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.