Last updated Dec 8, 2017

OneToOne relationship

In Active Objects a one to one relationship is defined thanks to the net.java.ao.OneToOne annotation.

In the DogFood blog there is such a relationship defined between the Blog and its BlogConfiguration:

Blog.java

1
2
public interface Blog extends Entity
{
    ...
    @OneToOne
    BlogConfiguration getConfiguration();
    ...
}

And here is how this is defined in the BlogConfiguration:

BlogConfiguration.java

1
2
public interface BlogConfiguration extends Entity
{
    void setBlog(Blog blog);
    Blog getBlog();
    ...
}

Then setting the relation ship is as simple as:

1
2
final BlogConfiguration configuration = entityManager.create(BlogConfiguration.class);
...
configuration.setBlog(blog); // setting the blog here
configuration.save();

New attributes on entity annotations in Active Objects 0.22.1

The OneToOne, OneToMany and ManyToMany annotations are used to define relationships in Active Objects. If you have used one of these to annotate a method as one end of a relationship, you can now set an attribute(s) that specifies the method on the remote end of the relationship. In versions prior to 0.22.1, Active Objects would attempt to infer the method by the type, which did not work in all situations.

  • OneToOne and OneToMany annotations: New "reverse" attribute. Set this to the name of the corresponding getter on the remote interface.

If you do not set these attributes, Active Objects will revert to inferring the method by type. However, in a future upgrade, specifying these attributes will be required.

Note, the Active Objects plugin was upgraded to 0.22.1 in JIRA 6.1.

Rate this page: