aybekbuka
aybekbuka

Reputation: 428

entity onetomany ..annotation exception

I have two classes mapped OneToMany, ManyToOne, and i get exception:

org.hibernate.AnnotationException: mappedBy reference an unknown target entity property: entity_package.TicketEntity.ownerEntity in entity_package.UserEntity.ownedTickets

here is the code :

public class UserEntity implements Serializable {

@OneToMany(mappedBy="ownerEntity")
public List<TicketEntity> getOwnedTickets() {
    return tickets;
}
public void setOwnedTickets(List<TicketEntity> tickets) {
    this.tickets = tickets;
}

and ...

public class TicketEntity implements Serializable {

private UserEntity ownerEntity;

@ManyToOne
@JoinColumn(name="owner_id")
public UserEntity getOwner() {
    return ownerEntity;
}
public void setOwner(UserEntity owner) {
    this.ownerEntity = owner;
}

whats wrong ?

Upvotes: 1

Views: 641

Answers (1)

yair
yair

Reputation: 9255

The property name is owner as defined by the annotated getter. Use:

@OneToMany(mappedBy="owner")
public List<TicketEntity> getOwnedTickets() {

Upvotes: 4

Related Questions