-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Annotations, auto_increment, generatedvalue help needed,
PostPosted: Fri May 18, 2007 10:27 am 
Newbie

Joined: Fri May 18, 2007 10:21 am
Posts: 2
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 2:57 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
You're probably using Hibernate 3.2.4 and being bitten by this bug:
http://opensource.atlassian.com/project ... e/HHH-2618

-Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 3:14 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Actually this is the correct bug, and it is fixed in SP1:
http://opensource.atlassian.com/project ... e/HHH-2605

-Chris

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 5:30 pm 
Newbie

Joined: Fri May 18, 2007 10:21 am
Posts: 2
GREAT!!!!! After upgrade works like a charm... i'm really new to hibernate... and i thought that i'm doing anything wrong... i spent whole day with this freaky thing! You are HERO!


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 5:31 pm 
Red Hat Associate
Red Hat Associate

Joined: Mon Aug 16, 2004 11:14 am
Posts: 253
Location: Raleigh, NC
Welcome to the community :)

_________________
Chris Bredesen
Senior Software Maintenance Engineer, JBoss


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.