[Biojava-l] Biojavax and hibernate problems
bertrand beckert
bertrand.beckert at gmail.com
Fri Apr 20 08:38:33 UTC 2007
Dear all,
I am newbie to java and biojavax... I have installed the BioSQL database
and I have tried to connect to this base an put some data... In oder to do
this I have installed Biojavax, and also hibernate (and the different .jar
required). So I have tried to put some data but it didn't work... here is my
code and the error in the output.
Could you help me please. Thanks
---------
package fr.ustrasbg.ibmc.bbeckert;
import org.biojavax.bio.seq.io.RichSequenceBuilderFactory;
import org.biojavax.bio.seq.io.RichSequenceFormat;
import org.biojavax.bio.seq.io.RichStreamReader;
import org.biojavax.bio.seq.io.GenbankFormat;
import org.biojavax.bio.seq.RichSequence;
import org.biojavax.bio.seq.RichFeature;
import org.biojavax.bio.db.RichSequenceDB;
import org.biojavax.bio.db.biosql.BioSQLRichSequenceDB;
import org.biojavax.RichObjectFactory;
import org.biojava.bio.BioException;
import org.biojava.bio.seq.db.IllegalIDException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.HibernateException;
import org.hibernate.cfg.Configuration;
import java.io.File;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Iterator;
public class HibernatLoadingData {
public RichSequence gbkRichSeq (File f) {
[....]
return sequence;
}
public static void loadingData (RichSequence gbkSeq){
SessionFactory sessionFactory = new
Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();
RichObjectFactory.connectToBioSQL(session);
RichSequenceDB db = new BioSQLRichSequenceDB(session);
Transaction t=null;
try{
t = session.beginTransaction();
//test to kown is the database is active->true
System.out.println(t.isActive());
db.addRichSequence(gbkSeq); //it should work...
t.commit();
} catch (HibernateException e) {
e.printStackTrace();
if (t != null && t.isActive())
t.rollback();
} catch (BioException e) {
e.printStackTrace();
}
session.close();
}
public static void main(String[] args) {
File f = new
File("/home/bertrand/IdeaProjects/ncRNAs/data/test.gbk");
HibernatLoadingData hl= new HibernatLoadingData();
RichSequence sequence=hl.gbkRichSeq(f);
loadingData(sequence);
}
}
output:
RichSequence gbkRichSeq:
sequence name:CAK20891 AC:CAK20891
Division:BCT
length:688
Protein start:1 end:688 Strand:POSITIVE
MSKDFLLEIGLEEMPAQYVTSSVAQLEKRVSDWLNENQITFEKIKTYSTPRRLTVLVEAM
AEEQANRVEEAKGPAKKIALDDEGNWSKAALGFARSQKVEPADLTFREIKGVEYIYIKKE
VIGEKTTALLPSLEKVVTSMTFPVSMHWGSNDLRYIRPIKWLIAMFGEEIIPFEITGVST
SNTSRGHRFLGKTATIKQPSDYPNALLEQFVVVNAEERKQAIVEQLRELESMENWQIKED
EDLLEEVTNLVEYPTVLAGNFEKEYLELPEEVLITTMKEHQRYFPVFSKDEELLPHFVTV
RNGNHENLDTVARGNEKVLRARLSDADFFYQEDLKITIDEAVAKLQNIVFHEKLGTLTEK
MKRVQKVALMLADYLDWQEEDKQDIIRLTNIYKFDLVTNIVGEFPELQGLMGEKYALLQG
EKPAIAIAIREHYLPSSAEGALPQTDLGSIIAIADKLETLVGFFCVNIVPTGSADPFGLR
RSAFGAMRIIQANGWDIPVLELLSRIVDMERAEGAVELPSDDVKKEVQTFLKNRLRVVLQ
NHHIRHDIIDAVIGGDPNTIPQLVDRAQILNKHVESDWFRPTVEALTRVMNISKKHEGNV
EVDPSLFENKYEQALFDEIEKLKYDYANLTIVDRLRAFAALRTTIDDYFDNTLVMSENIE
LKNNRLALLFELASFIKEFAQMDEINVK
(log4j.properties)
10:14:06,582 INFO Environment:509 - Hibernate 3.2.3
10:14:06,589 INFO Environment:542 - hibernate.properties not found
10:14:06,596 INFO Environment:676 - Bytecode provider name : cglib
10:14:06,600 INFO Environment:593 - using JDK 1.4 java.sql.Timestamphandling
10:14:06,685 INFO Configuration:1426 - configuring from resource:
/hibernate.cfg.xml
10:14:06,686 INFO Configuration:1403 - Configuration resource:
/hibernate.cfg.xml
10:14:06,783 INFO Configuration:553 - Reading mappings from resource :
Namespace.hbm.xml
10:14:06,966 INFO HbmBinder:300 - Mapping class: Namespace -> biodatabase
[...]
Exception in thread "main" java.lang.RuntimeException: Error while trying to
save RichSequence with id: CAK20891
at org.biojavax.bio.db.biosql.BioSQLRichSequenceDB._addRichSequence(
BioSQLRichSequenceDB.java:300)
at org.biojavax.bio.db.biosql.BioSQLRichSequenceDB.addRichSequence(
BioSQLRichSequenceDB.java:277)
at fr.ustrasbg.ibmc.bbeckert.HibernatLoadingData.loadingData(
HibernatLoadingData.java:101)
at fr.ustrasbg.ibmc.bbeckert.HibernatLoadingData.main(
HibernatLoadingData.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:90)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.biojavax.bio.db.biosql.BioSQLRichSequenceDB._addRichSequence(
BioSQLRichSequenceDB.java:297)
... 8 more
Caused by: org.hibernate.TransientObjectException: object references an
unsaved transient instance - save the transient instance before flushing:
Term
at org.hibernate.engine.ForeignKeys.getEntityIdentifierIfNotUnsaved(
ForeignKeys.java:219)
at org.hibernate.collection.AbstractPersistentCollection.getOrphans(
AbstractPersistentCollection.java:889)
at org.hibernate.collection.PersistentSet.getOrphans(PersistentSet.java
:90)
at org.hibernate.engine.CollectionEntry.getOrphans(CollectionEntry.java
:350)
at org.hibernate.engine.Cascade.deleteOrphans(Cascade.java:340)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java
:324)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(
AbstractSaveEventListener.java:456)
at
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(
AbstractSaveEventListener.java:334)
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$1.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.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$1.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.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$1.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.cascadeCollectionElements(Cascade.java
:296)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:242)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:219)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:169)
at org.hibernate.engine.Cascade.cascade(Cascade.java:130)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(
AbstractSaveEventListener.java:456)
at
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(
AbstractSaveEventListener.java:334)
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)
... 13 more
--
Bertrand BECKERT
PhD student
IBMC - UPR 9002 du CNRS - ARN
15, rue Rene Descartes
F-67084 STRASBOURG Cedex
b.beckert at ibmc.u-strasbg.fr
bertrand.beckert at gmail.com
More information about the Biojava-l
mailing list