Created
March 29, 2016 04:27
-
-
Save cosbor11/0325eaacc97a446425a1 to your computer and use it in GitHub Desktop.
Entity definitions for fetch policy example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Series.java | |
| @Entity | |
| public class Series extends ManagedEntity implements IManagedEntity | |
| { | |
| @Attribute | |
| @Identifier | |
| public String seriesId; | |
| @Relationship(type = RelationshipType.ONE_TO_MANY, | |
| cascadePolicy = CascadePolicy.ALL, | |
| inverseClass = Season.class, | |
| fetchPolicy = FetchPolicy.EAGER, | |
| inverse = "series") | |
| public List<Season> seasons; | |
| } | |
| // Season.java | |
| @Entity | |
| public class Season extends ManagedEntity implements IManagedEntity | |
| { | |
| public Season() | |
| { | |
| } | |
| public Season(int seasonNumber, int seasonYear) | |
| { | |
| this.seasonNumber = seasonNumber; | |
| this.seasonYear = seasonYear; | |
| } | |
| @Attribute | |
| @Identifier(generator = IdentifierGenerator.SEQUENCE) | |
| public long seasonId; | |
| @Attribute | |
| public int seasonNumber; | |
| @Attribute | |
| public int seasonYear; | |
| @Relationship(type = RelationshipType.MANY_TO_ONE, | |
| cascadePolicy = CascadePolicy.NONE, | |
| inverseClass = Series.class, | |
| inverse = "seasons") | |
| public Series series; | |
| @Relationship(type = RelationshipType.ONE_TO_MANY, | |
| cascadePolicy = CascadePolicy.SAVE, | |
| inverse = "season", | |
| inverseClass = Episode.class, | |
| fetchPolicy = FetchPolicy.LAZY) | |
| public List<Episode> episodes; | |
| } | |
| // Episode.java | |
| @Entity | |
| public class Episode extends ManagedEntity implements IManagedEntity | |
| { | |
| public Episode() | |
| { | |
| } | |
| public Episode(String episodeId, int episodeNumber) | |
| { | |
| this.episodeId = episodeId; | |
| this.episodeNumber = episodeNumber; | |
| } | |
| @Attribute | |
| @Identifier | |
| public String episodeId; | |
| @Attribute | |
| public int episodeNumber; | |
| @Relationship(type = RelationshipType.MANY_TO_ONE, | |
| cascadePolicy = CascadePolicy.NONE, | |
| inverse = "episodes", | |
| inverseClass = Season.class) | |
| public Season season; | |
| @Relationship(type = RelationshipType.ONE_TO_MANY, | |
| inverseClass = Actor.class, | |
| cascadePolicy = CascadePolicy.SAVE, | |
| fetchPolicy = FetchPolicy.NONE) | |
| public List<Actor> actors; | |
| } | |
| // Actor.java | |
| @Entity | |
| public class Actor extends Person implements IManagedEntity | |
| { | |
| @Identifier(generator = IdentifierGenerator.SEQUENCE) | |
| @Attribute | |
| public int actorId; | |
| @Attribute | |
| public String firstName; | |
| @Attribute | |
| public String lastName; | |
| @Relationship(type = RelationshipType.MANY_TO_MANY, | |
| cascadePolicy = CascadePolicy.NONE, | |
| inverseClass = Movie.class, | |
| inverse = "actors") | |
| public List<Movie> movies; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment