-->
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: java.sql.BatchUpdateException:
PostPosted: Sun Feb 19, 2012 4:00 pm 
Newbie

Joined: Sun Feb 19, 2012 3:42 pm
Posts: 2
java.sql.BatchUpdateException: ORA-02291: integrity constraint (SONGSLIB.SONGSDETAIL_ALBUM_FK1) violated - parent key not found

at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10070)
atjava.sql.BatchUpdateException: ORA-02291: integrity constraint (SONGSLIB.SONGSDETAIL_ALBUM_FK1) violated - parent key not found oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:213)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
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 com.gp.songslib.dao.impl.SaveSongsInfoDaoImpl.saveAlbum(SaveSongsInfoDaoImpl.java:35)
at mysonglibrary.MySongLibrary.main(MySongLibrary.java:30)
2012-02-20 01:08:32,301 WARN [main] org.hibernate.util.JDBCExceptionReporter - SQL Error: 2291, SQLState: 23000
2012-02-20 01:08:32,301 ERROR [main] org.hibernate.util.JDBCExceptionReporter - ORA-02291: integrity constraint (SONGSLIB.SONGSDETAIL_ALBUM_FK1) violated - parent key not found

2012-02-20 01:08:32,301 WARN [main] org.hibernate.util.JDBCExceptionReporter - SQL Error: 2291, SQLState: 23000
2012-02-20 01:08:32,301 ERROR [main] org.hibernate.util.JDBCExceptionReporter - ORA-02291: integrity constraint (SONGSLIB.SONGSDETAIL_ALBUM_FK1) violated - parent key not found

2012-02-20 01:08:32,301 ERROR [main] org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
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 com.gp.songslib.dao.impl.SaveSongsInfoDaoImpl.saveAlbum(SaveSongsInfoDaoImpl.java:35)
at mysonglibrary.MySongLibrary.main(MySongLibrary.java:30)
Caused by: java.sql.BatchUpdateException: ORA-02291: integrity constraint (SONGSLIB.SONGSDETAIL_ALBUM_FK1) violated - parent key not found

at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10070)
at oracle.jdbc.driver.OracleStatementWrapper.executeBatch(OracleStatementWrapper.java:213)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:246)
... 7 more


DB DOMAIN:
[*] ALBUM DB TABLE
Code:
package com.gp.songslib.db.domain;
// Generated Feb 11, 2012 7:57:21 PM by Hibernate Tools 3.2.1.GA

import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;

/**
* Album generated by hbm2java
*/
@Entity
@Table(name = "ALBUM", schema = "SONGSLIB")
public class Album implements java.io.Serializable {

    private String albumid;
    private String name;
    private String year;
    private String ziparchive;
    private Set<Songsdetail> songsdetails = new HashSet<Songsdetail>(0);

    public Album() {
    }

    public Album(String albumid, String name, String year) {
        this.albumid = albumid;
        this.name = name;
        this.year = year;
    }

    public Album(String albumid, String name, String year, String ziparchive, Set<Songsdetail> songsdetails) {
        this.albumid = albumid;
        this.name = name;
        this.year = year;
        this.ziparchive = ziparchive;
        this.songsdetails = songsdetails;
    }

    @Id
    @Column(name = "ALBUMID", unique = true, nullable = false, length = 100)
    public String getAlbumid() {
        return this.albumid;
    }

    public void setAlbumid(String albumid) {
        this.albumid = albumid;
    }

    @Column(name = "NAME", nullable = false, length = 20)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "YEAR", nullable = false, length = 4)
    public String getYear() {
        return this.year;
    }

    public void setYear(String year) {
        this.year = year;
    }

    @Column(name = "ZIPARCHIVE", length = 200)
    public String getZiparchive() {
        return this.ziparchive;
    }

    public void setZiparchive(String ziparchive) {
        this.ziparchive = ziparchive;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "album")
    public Set<Songsdetail> getSongsdetails() {
        return this.songsdetails;
    }

    public void setSongsdetails(Set<Songsdetail> songsdetails) {
        this.songsdetails = songsdetails;
    }

    public void setSongsdetails(Songsdetail songsdetail) {
        this.songsdetails.add(songsdetail);
    }

    @Override
    public String toString() {
        StringBuilder albumValue = new StringBuilder("Album :-\n");
        albumValue.append("Album ID : ").append(albumid).append("\n").append("Name : ").append(name).append("\n").append("Year : ").append(year).append("\n").append("Zip Archive : ").append(ziparchive).append("\n");
        if (songsdetails != null && !songsdetails.isEmpty()) {
            for (int i = 0; i < songsdetails.size(); i++) {
                albumValue.append("SongDetail : ").append(songsdetails).append("\n");
            }
        }
        return albumValue.toString();
    }
}


[*]SONGS DETAIL TABLE
Code:

package com.gp.songslib.db.domain;
// Generated Feb 11, 2012 7:57:21 PM by Hibernate Tools 3.2.1.GA

import java.util.HashSet;
import java.util.Set;
import javax.persistence.*;

/**
* Songsdetail generated by hbm2java
*/
@Entity
@Table(name = "SONGSDETAIL", schema = "SONGSLIB")
public class Songsdetail implements java.io.Serializable {

    private String songsid;
    private Album album;
    private String songstitle;
    private String songslocation;
    private String album_1;
    private Set<Songsingermap> songsingermaps = new HashSet<Songsingermap>(0);

    public Songsdetail() {
    }

    public Songsdetail(String songsid, Album album, String songstitle, String songslocation, String album_1) {
        this.songsid = songsid;
        this.album = album;
        this.songstitle = songstitle;
        this.songslocation = songslocation;
        this.album_1 = album_1;
    }

    public Songsdetail(String songsid, Album album, String songstitle, String songslocation, String album_1, Set<Songsingermap> songsingermaps) {
        this.songsid = songsid;
        this.album = album;
        this.songstitle = songstitle;
        this.songslocation = songslocation;
        this.album_1 = album_1;
        this.songsingermaps = songsingermaps;
    }

    @Id
    @Column(name = "SONGSID", unique = true, nullable = false, length = 100)
    public String getSongsid() {
        return this.songsid;
    }

    public void setSongsid(String songsid) {
        this.songsid = songsid;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "SONGSID", unique = true, nullable = false, insertable = false, updatable = false)
    public Album getAlbum() {
        return this.album;
    }

    public void setAlbum(Album album) {
        this.album = album;
    }

    @Column(name = "SONGSTITLE", nullable = false, length = 100)
    public String getSongstitle() {
        return this.songstitle;
    }

    public void setSongstitle(String songstitle) {
        this.songstitle = songstitle;
    }

    @Column(name = "SONGSLOCATION", nullable = false, length = 200)
    public String getSongslocation() {
        return this.songslocation;
    }

    public void setSongslocation(String songslocation) {
        this.songslocation = songslocation;
    }

    @Column(name = "ALBUM", nullable = false, length = 100)
    public String getAlbum_1() {
        return this.album_1;
    }

    public void setAlbum_1(String album_1) {
        this.album_1 = album_1;
    }

    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "songsdetail")
    public Set<Songsingermap> getSongsingermaps() {
        return this.songsingermaps;
    }

    public void setSongsingermaps(Set<Songsingermap> songsingermaps) {
        this.songsingermaps = songsingermaps;
    }

    @Override
    public String toString() {
        return "Songsdetail{" + "songsid=" + songsid + ", album=" + album + ", songstitle=" + songstitle + ", songslocation=" + songslocation + ", album_1=" + album_1 + ", songsingermaps=" + songsingermaps + '}';
    }
}



I m getting the above mentioned error. The DB domain i mentioned is getting used in the code.
I m inserting the data as below :

Code:
public class SaveSongsInfoDaoImpl extends GenricDaoImpl implements SaveSongsInfoDao {

    @Override
    public boolean saveAlbum(Album album) {
        logger.debug("\nSaveSongsInfoDaoImpl :: saveAlbum : START");
        logger.debug("\nTRANSIENT OBJECT :--\n" + album);
        boolean isAlbumSaved = false;
        Session session = null;
        Transaction transaction = null;
        try {
            session = getSession();
            transaction = session.getTransaction();
            transaction.begin();
            logger.debug("\n--> TRANSACTION BEGIN...!!!");
            logger.debug("--> Album to be Saved : "+album);
            session.save(album);
            logger.debug("\nPERSISTENT OBJECT :--\n" + album);
            session.flush();
            logger.debug("--> SESSION FLUSHED...!!!");
            transaction.commit();
            logger.debug("--> TRANSACTION COMMITED...!!!");
            isAlbumSaved = sessionOver(session);
            logger.debug("\nDETACHED OBJECT :--\n" + album);
        } catch (SessionException se) {
            transaction.rollback();
            se.printStackTrace();
            logger.error("\nEXCETION<SessionException> :: SaveSongsInfoDaoImpl :: saveAlbum : TRANSATION ROLLED BACK : ", se);
            sessionOver(session);
            isAlbumSaved = false;
        } catch (TransactionException te) {
            transaction.rollback();
            te.printStackTrace();
            logger.error("\nEXCETION<TransactionException> :: SaveSongsInfoDaoImpl :: saveAlbum : TRANSATION ROLLED BACK : ", te);
            sessionOver(session);
            isAlbumSaved = false;
        } catch (HibernateException he) {
            transaction.rollback();
            he.printStackTrace();
            logger.error("\nEXCETION<TransactionException> :: SaveSongsInfoDaoImpl :: saveAlbum : TRANSATION ROLLED BACK : ", he);
            sessionOver(session);
            isAlbumSaved = false;
        } catch (Exception e) {
            transaction.rollback();
            e.printStackTrace();
            logger.error("\nEXCETION :: SaveSongsInfoDaoImpl :: saveAlbum : TRANSATION ROLLED BACK : ", e);
            sessionOver(session);
            isAlbumSaved = false;
        }
        logger.debug("SaveSongsInfoDaoImpl :: saveAlbum : < isAlbumSaved : " + isAlbumSaved + " >");
        return isAlbumSaved;
    }

   


Here the album object contains the Set of Songs.
The Album PK is even matching the FK In the song Details.
While debugging i found when i do session.flush() or transaction.comit(); I get the above mentioned error.
I tried many thing but not able to find whats going wrong :(

Thanks & Regards
GAURAV PRASAD


Top
 Profile  
 
 Post subject: Re: java.sql.BatchUpdateException:
PostPosted: Tue Feb 21, 2012 2:10 pm 
Newbie

Joined: Sun Feb 19, 2012 3:42 pm
Posts: 2
I m looking for a solution to my problem kindly help ?


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.