[Biojava-l] Load, Update Genbank sequence issue

gang wu gwu at molbio.mgh.harvard.edu
Tue May 20 18:37:18 UTC 2008


Hi all,

I'm trying to load Genbank sequence into BioSQL database with
BioJavax/Hibernate. It's Ok to load the first sequence. Then I got the
exception when loading new sequences or reloading the same sequence.
Seems the Hibernate is trying to insert "genbank" namespace again. Can
anybody tell me what I did wrong? Thanks in advance.

Gang

================================================================
public class SequenceLoaderNew {
    public void loadSeq(String fileName, String namespace) throws
FileNotFoundException, BioException {
        System.out.println("Start loading file " + fileName + " at " +
System.currentTimeMillis());
        BufferedReader br = new BufferedReader(new FileReader(fileName));
        Session session = new
Configuration().configure().buildSessionFactory().openSession();
        RichObjectFactory.connectToBioSQL(session);
        RichSequenceDB db = new BioSQLRichSequenceDB(session);
        RichSequenceIterator rsi =
RichSequence.IOTools.readGenbankDNA(br, new SimpleNamespace(namespace));
        while (rsi.hasNext()) {
            Transaction tx = session.beginTransaction();
            RichSequence sequence = rsi.nextRichSequence();
            System.out.println("Loaded sequence" +
sequence.getAccession() + ", identifier: " + sequence.getIdentifier());
            try {
                System.out.println("Delete sequence" +
sequence.getAccession() + " if exists.");
                db.removeSequence(sequence.getAccession());
            } catch (Exception ex) {
            }
            try {
                System.out.println("Save sequence " +
sequence.getAccession());
                session.save("BioEntry", sequence);
                tx.commit();
                session.flush();
                session.clear();
            } catch (HibernateException ex) {
                tx.rollback();
                ex.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws BioException,
FileNotFoundException {
        SequenceLoaderNew sl = new SequenceLoaderNew();
        //sl.loadSeq("/genomeseq/bacteria/NC_005813.gbk", "genbank");
        sl.loadSeq("/genomeseq/bacteria/NC_004349.gbk", "genbank");
    }
}
================================================================
org.hibernate.exception.ConstraintViolationException: could not insert:
[Namespace]
        at
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
        at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
        at
org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
        at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2163)
        at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2643)
        at
org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:51)
        at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
        at
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
        at
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
        at
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
        at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
        at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
        at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
        at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
        at
org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
        at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
        at
org.hibernate.engine.CascadingAction$5.cascade(CascadingAction.java:218)
        at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:268)
        at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:216)
        at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
        at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
        at
org.hibernate.event.def.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:431)
        at
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:265)
        at
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
        at
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
        at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
        at
org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
        at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
        at
org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
        at
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
        at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535)
        at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523)
        at primerdb.SequenceLoaderNew.loadSeq(SequenceLoaderNew.java:38)
        at primerdb.SequenceLoaderNew.main(SequenceLoaderNew.java:52)
Caused by:
com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException:
Duplicate entry 'genbank' for key 'name'
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1011)
        at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
        at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
        at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
        at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
        at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
        at
com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
        at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2019)
        at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1937)
        at
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1922)
        at
org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:73)
        at
org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:33)
        ... 31 more
================================================================





More information about the Biojava-l mailing list