Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * Copyright 2007 Daniel Spiewak
  * Licensed under the Apache License, Version 2.0 (the "License"); 
  * you may not use this file except in compliance with the License. 
  * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software 
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
 * See the License for the specific language governing permissions and
 * limitations under the License.

Marks a method as relevant only to a one-to-one relation. This informs ActiveObjects that the return value for the method in question should be determined from a one-to-one relation onto the type in the return value. For example:

public interface User {
     // ...
     public Password getPassword();

Thus the return value of the getPassword() method would be determined by a query something like the following:

SELECT id FROM passwords WHERE userID = ?

If the where() clause is specified, it will be used in addition to the base, necessary criterion to determine the returned entities. Thus, the one-to-one relation could be referenced in the following way:

public interface User {
     // ...
     @OneToOne(where="deleted = FALSE")
     public Password getPassword();

This would lead to a query like the following:

SELECT id FROM passwords WHERE userID = ? AND (deleted = FALSE)

Daniel Spiewak
public @interface OneToOne {


The name of the corresponding getter method in the remote entity.

If this is not specified, a warning will be logged at migration time, and ActiveObjects may behave in unexpected ways. Future versions of ActiveObjects may require that this property be specified.

See also:
    String reverse() default "";


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.

	String where() default "";
New to GrepCode? Check out our FAQ X