Hibernate exception

Help
Koyn
2005-05-03
2013-04-25
  • Koyn
    Koyn
    2005-05-03

    Hi,

    I am new to Informa. I have a piece of code like this(to take a rss feed file from BBC news as input and persist into mysql server):

    Transaction tx = null;
    try {
    SessionHandler handler = SessionHandler.getInstance();
    Session session = handler.getSession();
    ChannelBuilder builder = new ChannelBuilder(session);
    File inpFile = new File("bbc_me_rss.xml");
            ChannelIF myChannel = FeedParser.parse(builder, inpFile);
    tx = session.beginTransaction();
    tx.commit();
    } catch (exception e) {
    ...
    tx.rollback;
    }

    ..and got an exception like this:

    Hibernate: insert into ITEMS (CHANNEL_ID, TITLE, DESCRIPTION, UNREAD, LINK, CREA
    TOR, SUBJECT, DATE, FOUND, GUID, COMMENTS, SOURCE, ENCLOSURE) values (?, ?, ?, ?
    , ?, ?, ?, ?, ?, ?, ?, ?, ?)
    Hibernate: insert into IMAGES (TITLE, DESCRIPTION, LOCATION, LINK, WIDTH, HEIGHT
    ) values (?, ?, ?, ?, ?, ?)
    Hibernate: update CHANNELS set TITLE=?, DESCRIPTION=?, LOCSTRING=?, SITE=?, CREA
    TOR=?, PUBLISHER=?, LANGUAGE=?, FORMAT=?, IMAGE_ID=?, TEXTINPUT_ID=?, COPYRIGHT=
    ?, RATING=?, CLOUD_ID=?, GENERATOR=?, DOCS=?, TTL=?, LAST_UPDATED=?, LAST_BUILD_
    DATE=?, PUB_DATE=?, UPDATE_PERIOD=?, UPDATE_FREQUENCY=?, UPDATE_BASE=? where CHA
    NNEL_ID=?
    Hibernate: update ITEMS set CHANNEL_ID=?, TITLE=?, DESCRIPTION=?, UNREAD=?, LINK
    =?, CREATOR=?, SUBJECT=?, DATE=?, FOUND=?, GUID=?, COMMENTS=?, SOURCE=?, ENCLOSU
    RE=? where ITEM_ID=?
    (util.JDBCExceptionReporter          38  ) SQL Error: 1216, SQLState: 23000
    (util.JDBCExceptionReporter          46  ) Cannot add or update a child row: a f
    oreign key constraint fails
    (util.JDBCExceptionReporter          38  ) SQL Error: 1216, SQLState: 23000
    (util.JDBCExceptionReporter          46  ) Cannot add or update a child row: a f
    oreign key constraint fails
    (util.JDBCExceptionReporter          38  ) could not update: [de.nava.informa.im
    pl.hibernate.Item#15]
    java.sql.BatchUpdateException: Cannot add or update a child row: a foreign key c
    onstraint fails
            at com.mysql.jdbc.ServerPreparedStatement.executeBatch(ServerPreparedSta
    tement.java:822)
            at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.
    java:54)

    I feel insert data is ok, but what does the update come from? I wrote some code to create a simple channel and persist it into mysql and works fine, so the configuration should be all right.

    i am using the latest version of informa, hibernate within the informa package and latest version of mysql.

    Appreciate any help!