-->
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.  [ 2 posts ] 
Author Message
 Post subject: GenericJDBCException with ORA-01008: not all variables bound
PostPosted: Mon Jan 16, 2006 6:05 am 
Beginner
Beginner

Joined: Fri Jan 13, 2006 8:07 am
Posts: 29
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.


Top
 Profile  
 
 Post subject: why ??
PostPosted: Mon Jan 16, 2006 10:27 am 
Beginner
Beginner

Joined: Fri Jan 13, 2006 8:07 am
Posts: 29
Hi,

Somehow I sorted the exceptions coming.
I changed the generator class as 'increment'.

But the values not inserting into the table. There is no exceptions or errors coming.

Can anybody have an idea why is this ?

My EventManager class is as follows :

package events;

import org.hibernate.Session;

import java.util.Date;
import java.util.List;
import util.HibernateUtil;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


public class EventManager {
private static Log log = LogFactory.getLog(HibernateUtil.class);
public static void main(String[] args) {

EventManager mgr = new EventManager();
long id = 101;
Event eve = new Event();
System.out.println("INSIDE LIST... ");
if (args[0].equals("store")) {

mgr.createAndStoreEvent("My Event", new Date());
}
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) {
try {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();

Event theEvent = new Event();

theEvent.setTitle(title);
theEvent.setDt(theDate);

session.save(theEvent);
session.update(theEvent);
System.out.println("event id : "+theEvent.getId());
System.out.println("event title : "+theEvent.getTitle());
session.getTransaction().commit();
session.connection().commit();

//session.connection().createStatement().execute("SHUTDOWN");
}catch(Exception e){}
}


private List listEvents() {

Session session = HibernateUtil.getSessionFactory().getCurrentSession();

session.beginTransaction();

List result = session.createQuery("from Event").list();

session.getTransaction().commit();

return result;
}

}


The result coming in the consol is :

clean:
run:
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
indise hibernate util ...
INSIDE LIST...
Hibernate: select max(EVENT_ID) from EVENTS
event id : 1
event title : My Event
BUILD SUCCESSFUL (total time: 7 seconds)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.