Hi
I am trying to work out the first hibernate example Event in hibernate.org.
I am using oracle as databse. Since I cannot create a sequence in the database, I used 'assigned' as the generator class. The thing I don't understand is, when we gibe 'assigned' ,where should we set the key value ? In the table , or do we need to assigne it in the code ?
My EventManager class is :
/*
* EventManager.java
*
* Created on 12 January 2006, 10:33
*/
package events;
import org.hibernate.Session;
import java.util.Date;
import java.util.List;
import util.HibernateUtil;
public class EventManager {
public static void main(String[] args) {
EventManager mgr = new EventManager();
long id = 101; Event eve = new Event(); eve.setId(id); System.out.println("INSIDE LIST... ");
if (args[0].equals("store")) {
mgr.createAndStoreEvent("My Event", new Date(),id);
}
else if (args[0].equals("list")) {
List events = mgr.listEvents();
for (int i = 0; i < events.size(); i++) {
Event theEvent = (Event) events.get(i);
System.out.println("Event: " + theEvent.getTitle() +
" Time: " + theEvent.getDt());
}
}
HibernateUtil.getSessionFactory().close();
}
private void createAndStoreEvent(String title, Date theDate,long id) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Event theEvent = new Event();
//theEvent.setId(id);
theEvent.setTitle(title);
theEvent.setDt(theDate);
session.save(theEvent);
session.getTransaction().commit();
}
private List listEvents() {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
List result = session.createQuery("from Event").list();
session.getTransaction().commit();
return result;
}
}
I am getting the exception org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update. And an sql Exception java.sql.SQLException: ORA-01008: not all variables bound
Can you have a look at it ? Is this correct ?If not, how can I correct this ?
Please give you reply asap.
Thanks.
|