Maksim Maksim - 24 days ago 8
Java Question

Hibernate ManyToOne mapping exception

I am making some system, where I need @ManyToOne relation between two entities. I have 2 tables:

enter image description here

My mapping:

@Entity
@Table(name = "organizer", schema = "eventtracker")
public class OrganizerEntity {
private int organizerId;
private List<EventEntity> events;


@Id
@Column(name = "organizerId")
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int getOrganizerId() {
return organizerId;
}

public void setOrganizerId(int organizerId) {
this.organizerId = organizerId;
}

//other columns

@OneToMany(fetch = FetchType.EAGER, mappedBy = "organizer")
public List<EventEntity> getEvents() {
return events;
}

public void setEvents(List<EventEntity> events) {
this.events = events;
}


and:

@Entity
@Table(name = "event", schema = "eventtracker")
public class EventEntity {
private int eventId;
private OrganizerEntity organizer;

@Id
@Column(name = "eventId")
@GeneratedValue(strategy = GenerationType.IDENTITY)
public int getEventId() {
return eventId;
}

public void setEventId(int eventId) {
this.eventId = eventId;
}

//other columns

@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "organizer", referencedColumnName = "organizerId")
public OrganizerEntity getOrganizer() {
return organizer;
}

public void setOrganizer(OrganizerEntity organizer) {
this.organizer = organizer;
}

}


I get such exception:
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column
organizere4_.e' in 'field list'

Answer Source

Please verify your column names in the database table and in mapping table OrganizerEntity.specially the email field which might be creating the problem here.