Hi!
please, i need some assistance... I have two entities - users, and events... there is many-to-many relationship...
Code:
@Entity
@Table(name="events")
public class Event {
@Id
@Column(name="event_id")
private int id;
private String title;
public Event(){
this.id = 0;
this.title = new String();
}
public Event(int id, String title) throws EmptyDataException{
if (title=="") throw new EmptyDataException();
//this.id = id;
this.title = title;
}
public int getId(){
return this.id;
}
public void setId(int id){
this.id = id;
}
public String getTitle(){
return this.title;
}
public void setTitle(String title){
this.title = title;
}
}
Code:
@Entity
@Table(name="USER")
public class User {
@Id @GeneratedValue
@Column(name="user_id")
private int id;
private String name;
private String address;
@ManyToMany(targetEntity=Event.class)
private Set events = new HashSet();
public User(){
this.id = 0;
this.name = new String("");
this.address = new String("");
}
public User(String name, String address) throws EmptyDataException{
if (name=="" || address==""){
throw new EmptyDataException();
}
else {
//this.id = id;
this.name = name;
this.address = address;
}
}
public void setId(int id){
this.id = id;
}
public int getId(){
return this.id;
}
public void setName(String name){
this.name = name;
}
public String getName(){
return this.name;
}
public void setAddress(String address){
this.address = address;
}
public String getAddress(){
return this.address;
}
public void setEvents(Set events){
this.events = events;
}
public Set getEvents(){
return this.events;
}
}
when i try to call
Code:
User newUser = new User(request.getParameter("name"), request.getParameter("address"));
session.persist(newUser);
i get this:
java.sql.SQLException: No value specified for parameter 3
Hibernate:
insert
into
USER
(address, name, user_id)
values
(?, ?, ?)
please advice... the DB behind is mysql, user_id is int(10) not null auto increment primary key. thanks