-->
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.  [ 19 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Fri Jan 13, 2006 10:52 am 
Regular
Regular

Joined: Tue Jan 03, 2006 9:20 am
Posts: 74
Haven't tried Oracle with Hibernate (I'm just experimenting with it myself at the moment).

But at least you're at the point of trying to actually execute some SQL against the database, you have Hibernate up and running and telling Oracle to do something Oracle doesn't want to do.

You have set the class to use a generator in the database (native) for the sequence number (primary key) of the table.
My guess is that the DDL didn't generate that sequence (which in Oracle is handled through a database mechanism if I remember correctly, it's been a few years).
I'd start with checking the actual SQL code used to generate the table, see what it is trying to do.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 11:09 am 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
http://www.hibernate.org/296.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 12:03 pm 
Beginner
Beginner

Joined: Fri Jan 13, 2006 8:07 am
Posts: 29
Thank you very much for jwenting and Tim.

so from your reply i understand that i need to create a sequence for oracle.

But instead if i give increment or native or assigned , the error is different.

if I gave ' assigned ' as a generator class , the error is :

Hibernate: insert into EVENTS (EVENT_DATE, TITLE, EVENT_ID) values (?, ?, ?)
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:140)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:980)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:353)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at events.EventManager.createAndStoreEvent(Unknown Source)
at events.EventManager.main(Unknown Source)
Caused by: java.sql.SQLException: ORA-01008: not all variables bound

at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168)
at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208)
at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543)
at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1405)
at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteFetch(TTC7Protocol.java:822)
at oracle.jdbc.driver.OracleStatement.executeNonQuery(OracleStatement.java:1446)
at oracle.jdbc.driver.OracleStatement.doExecuteOther(OracleStatement.java:1371)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:2883)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
... 9 more

and my EventManager class :

/*
* 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();
System.out.println("INSIDE LIST... ");
if (args[0].equals("store")) {
long id = 101;
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;
}

}


can you please have a look, i would like to get this example sorted out , please


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 13, 2006 4:52 pm 
Regular
Regular

Joined: Wed Jun 29, 2005 11:14 pm
Posts: 119
Location: København
When you use assigned, you need to set the key yourself in the code. There are generators that hibernate iteself can use.

http://www.hibernate.org/hib_docs/refer ... aration-id and read 5.1.4

Try a hibernate increment generator to get you started but think about it's lack of scalability where you will want to use the link I posted before and let the DB generate the ID...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 19 posts ]  Go to page Previous  1, 2

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.