View Javadoc
1   package ejava.jpa.examples.tuning.bo;
2   
3   import java.util.UUID;
4   
5   import javax.persistence.*;
6   
7   @Entity
8   @Table(name="JPATUNE_MOVIEROLE")
9   //@IdClass(MovieRolePK.class)
10  public class MovieRole {
11  	@Id
12  	@Column(name="ID", length=36)
13  	private String id;
14  	
15  	//@Id
16  	@ManyToOne(optional=false, fetch=FetchType.LAZY)
17  	@JoinColumn(name="MOVIE_ID")
18  	private Movie movie;
19  
20  	//@Id
21  	@Column(name="MOVIE_ROLE", length=32, nullable=false)
22  	private String role;
23  	
24  	@ManyToOne(optional=false, fetch=FetchType.LAZY,
25  			cascade={CascadeType.DETACH})
26  	@JoinColumn(name="ACTOR_ID")
27  	private Actor actor;
28  
29  	public MovieRole() {
30  		id=UUID.randomUUID().toString();
31  	}
32  	public MovieRole(String id, Movie movie, String role) {
33  		this.id = id;
34  		this.movie = movie;
35  		this.role = role;
36  	}
37  	public MovieRole(Movie movie, String role) {
38  		this();
39  		this.movie = movie;
40  		this.role = role;
41  	}
42  	
43  	public String getId() { return id; }
44  
45  	public Movie getMovie() { return movie; }
46  	MovieRole setMovie(Movie movie) { this.movie=movie; return this; }
47  	public String getRole() { return role; }
48  
49  	public Actor getActor() { return actor; }
50  	public MovieRole setActor(Actor actor) {
51  		this.actor = actor;
52  		return this;
53  	}
54  
55  	@Override
56  	public String toString() {
57  		StringBuilder text = new StringBuilder()
58  			.append(movie.getTitle())
59  			.append(" ")
60  			.append(role);
61  		if (actor != null) {
62  			text.append(" ").append(actor);
63  		}
64  		return text.toString();
65  	}
66  }