|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |
@Retention(value=RUNTIME) @Target(value=METHOD) public @interface ManyToMany
Marks a method as relevant only to a many-to-many relation. This informs ActiveObjects that the return value for the method in question should be determined from a many-to-many relation through the specified type onto the type in the return value. For example:
public interface Person { // ... @ManyToMany(Authorship.class) public Book[] getBooks(); }
Thus the return value of the getBooks()
method
would be determined by a query something like the following:
SELECT bookID FROM authorships WHERE personID = ?
If the where()
clause is specified, it will be used
in addition to the base, necessary criterion to determine the
returned entities. Thus, the many-to-many relation could be referenced
in the following way:
public interface Person { // ... @ManyToMany(value=Authorship.class, where="deleted = FALSE") public Book[] getBooks(); }
This would lead to a query like the following:
SELECT bookID FROM authorships WHERE personID = ? AND (deleted = FALSE)
The value()
parameter is not optional.
Required Element Summary | |
---|---|
java.lang.Class<? extends RawEntity<?>> |
value
The type through which the many-to-many relation is defined. |
Optional Element Summary | |
---|---|
java.lang.String |
where
A String clause allowing developer-specified additional conditions to be imposed on the relationship. |
Element Detail |
---|
public abstract java.lang.Class<? extends RawEntity<?>> value
people
table has a many-to-many
relation on books
, it would most likely be through an
authorships
table. Thus, the value of this parameter
could be Authorship.class
public abstract java.lang.String where
A String clause allowing developer-specified additional conditions to be imposed on the relationship. The String must be a proper SQL WHERE clause:
"deleted = FALSE"
One must be extremely careful with this sort of thing though because sometimes (as is the case with the above sample), the unparameterized code may not execute as expected against every database (due to differences in typing and value handling). Thus, in all but non-trivial cases, defined implementations should be used.
Implementation
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT |