-->
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.  [ 6 posts ] 
Author Message
 Post subject: org.hibernate.exception.GenericJDBCException: batch Update
PostPosted: Sun Dec 02, 2007 8:00 pm 
Newbie

Joined: Sun Dec 02, 2007 7:28 pm
Posts: 5
Hi All,

I am facing a problem with my first hibernate application.
i am trying into insert a row in database(oracle 10g),but i am
getting error as :
Exception in thread "main" org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update.


Hibernate version:3.2

[b]Mapping documents:
hibernate.cfg.xml

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- Database connection settings -->
<property name="connection.driver_class">sun.jdbc.odbc.JdbcOdbcDriver</property>
<property name="connection.url">jdbc:odbc:test</property>
<property name="connection.username">scott</property>
<property name="connection.password">tiger</property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- Oracle dialect -->
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<property name="show_sql">true</property>

<mapping resource="events/Event.hbm.xml"/>
</session-factory>
</hibernate-configuration>

Event.hbm.xml :

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="events.Event" table="EVENTS">
<id name="id" column="ID">
<generator class="assigned"/>
</id>
<property name="date" type="date" column="EVENT_DATE"/>
<property name="title" column = "TITLE"/>
</class>
</hibernate-mapping>

[b]Code between sessionFactory.openSession() and session.close():


long i = 1;
session.beginTransaction();
Event theEvent = new Event();
theEvent.setId(i);
theEvent.setTitle(title);
//theEvent.setDate(theDate);
session.save(theEvent);
session.getTransaction().commit();


Full stack trace of any exception that occurs:

Exception in thread "main" org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:253)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:237)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at events.EventManager.createAndStoreEvent(EventManager.java:25)
at events.EventManager.main(EventManager.java:11)
Caused by: sun.jdbc.odbc.JdbcOdbcBatchUpdateException: General error
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.emulateExecuteBatch(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcPreparedStatement.executeBatchUpdate(Unknown Source)
at sun.jdbc.odbc.JdbcOdbcStatement.executeBatch(Unknown Source)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 9 more


Name and version of the database you are using:

Oracle 10g

The generated SQL (show_sql=true):

Hibernate: insert into EVENTS (EVENT_DATE, TITLE, ID) values (?, ?, ?)



Could anyone please help me out ..I serached this topic,but i did not find any answer which makes my first hibernate application works ..So can anyone please help me out and tell me what is the problem and fix?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 03, 2007 3:44 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi,

I think there is a problem with respect to the date field. Check it out
<property name="date" type="date" >
if you use property type="date" should have a timestamp in your Event class. If you have Date object change it to property type="Date"

If this doesn't help. Can you post your Event class??

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 03, 2007 9:19 pm 
Newbie

Joined: Sun Dec 02, 2007 7:28 pm
Posts: 5
HI,

thanks for ur reply....I tried with another example where i have not used date and it worked ...but for the same example i posted,still I was
not able to save the data ....I am sending you my Event Class.
So i want to know how can we save date value

I changed in the event.hbm.xml date type to timestamp and also to date..still it is not working and i ma getting the same exception ...I am sending you the table structure also ....

Table Structure :

id number
title varchar
event_date date


Event.java :

package events;

import java.util.Date;
public class Event {

private Long id;
private String title;
private Date date;
public Event() {}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}


Pls do reply me ........


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 04, 2007 3:43 am 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi,

Use the below method to format your date,
public static java.util.Date formatDate(Date date) {
String dateFormat = "dd-MM-yyyy";
SimpleDateFormat outFormat = new SimpleDateFormat(dateFormat);
String strDate = outFormat.format(date);
try {
SimpleDateFormat inFormat = new SimpleDateFormat(dateFormat);
return inFormat.parse(strDate, new ParsePosition(0));
} catch (Exception se) {
return null;
}
}

So you code should look like,
Code between sessionFactory.openSession() and session.close():
long i = 1;
session.beginTransaction();
Event theEvent = new Event();
theEvent.setId(i);
theEvent.setTitle(title);
theEvent.setDate(formatDate(theDate));
session.save(theEvent);
session.getTransaction().commit();

Let me know, if you still have problem.

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 05, 2007 12:34 am 
Newbie

Joined: Sun Dec 02, 2007 7:28 pm
Posts: 5
Hi ,

Thanks for ur reply...yes i tried with what you said ..but still i am getting the same error ...Tomorrow I will try with fresh example and let u know abt it ....event_date is null in my database and I am not passing the date value ...but still I am getting the same error ...Thats why I will try with new exeample and let you know ...

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 05, 2007 11:39 pm 
Newbie

Joined: Sun Dec 02, 2007 7:28 pm
Posts: 5
Hi ,

I got rid of the problem.The problem is because of long datatype for id in event class .I changed it to int and it is working now .

Thanks,
Rakesh.


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