Play! Associations Module


License

License

Categories

Categories

Maven Build Tools
GroupId

GroupId

com.google.code.maven-play-plugin.org.playframework.modules.associations
ArtifactId

ArtifactId

play-associations
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Play! Associations Module
Play! Associations Module
Source Code Management

Source Code Management

https://github.com/pareis/play-associations

Download play-associations

How to add to project

<!-- https://jarcasting.com/artifacts/com.google.code.maven-play-plugin.org.playframework.modules.associations/play-associations/ -->
<dependency>
    <groupId>com.google.code.maven-play-plugin.org.playframework.modules.associations</groupId>
    <artifactId>play-associations</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.google.code.maven-play-plugin.org.playframework.modules.associations/play-associations/
implementation 'com.google.code.maven-play-plugin.org.playframework.modules.associations:play-associations:1.0.1'
// https://jarcasting.com/artifacts/com.google.code.maven-play-plugin.org.playframework.modules.associations/play-associations/
implementation ("com.google.code.maven-play-plugin.org.playframework.modules.associations:play-associations:1.0.1")
'com.google.code.maven-play-plugin.org.playframework.modules.associations:play-associations:jar:1.0.1'
<dependency org="com.google.code.maven-play-plugin.org.playframework.modules.associations" name="play-associations" rev="1.0.1">
  <artifact name="play-associations" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.google.code.maven-play-plugin.org.playframework.modules.associations', module='play-associations', version='1.0.1')
)
libraryDependencies += "com.google.code.maven-play-plugin.org.playframework.modules.associations" % "play-associations" % "1.0.1"
[com.google.code.maven-play-plugin.org.playframework.modules.associations/play-associations "1.0.1"]

Dependencies

provided (1)

Group / Artifact Type Version
com.google.code.maven-play-plugin.org.playframework : play jar 1.2

Project Modules

There are no modules declared in this project.

[associations] Automatic bi-directional associations for play

A module that manages all your bi-directional model associations.

Description

Do you find writing code like this cumbersome and error prone?

    forum1.posts.remove(post);
    post.forum = forum2;
    forum2.posts.add(post);

Wouldn’t it be much easier if you could just write

    forum2.posts.add(post);

and the system handles all the wiring and rewiring for you? With the benefit of eliminating errors like “detached entity passed to persist” and such?

I have created a play module that does just that. Whenever you invoke one of the operations that changes a part of the association from whichever side, then the module completes this operation on all other affected parts. This includes not only the new target and its opposite reference, but it also manages to unlink a target object from its current associated object. All hassle free and safe. It works on @OneToOne, @OneToMany and @ManyToMany associations.

There are no dependencies introduced in your code. The module enhancer works on all properties of your @Entity classes having a “mappedBy” attribut on the @OneToOne, @OneToMany or @ManyToMany annotation. You do not need to declare anything else. The presence of the module is sufficient.

You can check it out at https://github.com/pareis/play-associations

Distributed under Apache 2.0 License

Written by André Pareis

Versions

Version
1.0.1