pitiful
pitiful

Reputation: 21

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!

Upvotes: 0

Views: 50

Answers (1)

Gaurav Shakya
Gaurav Shakya

Reputation: 121

Add this in Player Class:

@ManyToOne(fetch = FetchType.LAZY)

private Team team;

And replace in Team Class:

mappedBy = "player" ----> mappedBy = "team"

Upvotes: 1

Related Questions