-->
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: Could not execute JDBC batch update
PostPosted: Thu Dec 15, 2005 7:30 am 
Newbie

Joined: Tue Nov 29, 2005 6:33 am
Posts: 6
I am having two tables

1.logindetails - userid(primary key),password
2.personaldetails-userid(foreign key reference of logindetails),name

when i tried to store the data it shows the following error:


Hibernate version:3.1

Mapping documents:logindetails.hbm.xml,personaldetails.hbm.xml

Code between sessionFactory.openSession() and session.close():
Personaldetails ps=new Personaldetails();
ps.setName("deva");
ps.setRollno(new Integer(34));

org.hibernate.exception.ConstraintViolationException: [b]Could not execute JDBC batch update at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:69)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:200)
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:877)
at source.MainClass.main(MainClass.java:23)
Caused by: java.sql.BatchUpdateException: Cannot add or update a child row: a foreign key constraint fails
at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedStatement.java:853)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:193)
... 6 more
log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
[/b]

Name and version of the database you are using:MySQL 4


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 15, 2005 8:23 am 
Beginner
Beginner

Joined: Mon Aug 16, 2004 6:15 am
Posts: 24
Looking at the error message you got... [Cannot add or update a child row: a foreign key constraint fails] I would imagine that you've forgotten to set the logindetails of the personaldetails object you are trying to persist.

Without seeing your mapping files, this is a guess :)


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.