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 2public interface Blog extends Entity { ... @OneToOne BlogConfiguration getConfiguration(); ... }
And here is how this is defined in the BlogConfiguration
:
BlogConfiguration.java
1 2public interface BlogConfiguration extends Entity { void setBlog(Blog blog); Blog getBlog(); ... }
Then setting the relation ship is as simple as:
1 2final BlogConfiguration configuration = entityManager.create(BlogConfiguration.class); ... configuration.setBlog(blog); // setting the blog here configuration.save();
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.
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: