Hibernate Spring annotation confused
Hibernate Spring annotation confused
I'm confused in S. H. Annotation. Here is my code
for my first class:
@Entity
@Table(name="player")
public class Player implements Serializable
{
@Id
@Column(name="id_player")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String name;
private String pseudo;
}
and my second class:
@Entity
@Table(name="team")
public class Team implements Serializable
{
@Id
@Column(name="id_team")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
private String name;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "player")
private Set<Player> players = new HashSet<Player>();
}
it throws the exception:
mappedBy reference an unknown target entity property:
Player.Team in Team.players
i have getters and setters in these class.
how can i make it works? Thank you!
i know the class Player doesn't have Team value, and can i fix it without adding that?
– pitiful
Jul 2 at 13:26
1 Answer
1
Add this in Player Class:
Player
@ManyToOne(fetch = FetchType.LAZY)
private Team team;
And replace in Team Class:
Team
mappedBy = "player" ----> mappedBy = "team"
Thank you! it works realy good! It was helpful for me!
– pitiful
Jul 2 at 13:41
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
thank you, but it doesn't work! It throws the same Exception.
– pitiful
Jul 2 at 13:21