[Biojava-l] BioJAVA-X + BioSQL + no update
Christian Köberle
koeberle at mpiib-berlin.mpg.de
Thu Mar 16 10:03:26 UTC 2006
Hi Mark,
it works but the code has to look like that:
...
session.getTransaction().begin();
session.saveOrUpdate("Sequence",seq);
session.getTransaction().commit();
it also works with:
session.update("Sequence",seq);
Thanks,
Christian
mark.schreiber at novartis.com wrote:
> With BioJavaX if you want any changes to a RichSequence object to persist
> to the database you need to "save or add it" with Hibernate.
>
>
> SessionFactory sessionFactory = new
> Configuration().configure().buildSessionFactory();
> Session session = sessionFactory.openSession();
> RichObjectFactory.connectToBioSQL(session);
>
> RichSequence rs = ...; // some sequence you've made or
> modified
> session.saveOrUpdate("Sequence",rs); // persist the sequence
>
> ***
> Another way is to do everything inside a transaction (this example is from
> the BioJavaX docbook in CVS)
>
> SessionFactory sessionFactory = new
> Configuration().configure().buildSessionFactory();
> Session session = sessionFactory.openSession();
> RichObjectFactory.connectToBioSQL(session);
>
> Transaction tx = session.beginTransaction();
> try {
>
> // print out all the namespaces in the database
>
> Query q = session.createQuery("from Namespace");
> List namespaces = q.list(); // retrieve all the
> namespaces from the db
> for (Iterator i = namespaces.iterator(); i.hasNext(); ) {
> Namespace ns = (Namespace)i.next();
> System.out.println(ns.getName()); // print out the name of the
> namespace
>
> // print out all the sequences in the namespace
> Query sq = session.createQuery("from BioEntry where namespace=
> :nsp");
> // set the named parameter "nsp" to ns
> sq.setParameter("nsp",ns);
> List sequences = sq.list();
>
> for (Iterator j = sequences.iterator(); j.hasNext(); ) {
> BioEntry be = (BioEntry)j.next(); // RichSequences are
> BioEntrys too
> System.out.println(" "+be.getName()); // print out the name
> of the sequence
>
> // if the sequence is called bloggs, change its description to
> XYZ
>
> if (be.getName().equals("bloggs")) {
> be.setDescription("XYZ");
> }
> }
>
> }
>
> // commit and tidy up
> tx.commit();
> System.out.println("Changes committed.");
>
> // all sequences called bloggs now have a description of "XYZ" in the
> database
>
> } catch (Exception e) {
> tx.rollback();
> System.out.println("Changes rolled back.");
> e.printStackTrace();
> }
>
> session.close();
>
>
>
>
>
>
> Christian Köberle <koeberle at mpiib-berlin.mpg.de>
> Sent by: biojava-l-bounces at lists.open-bio.org
> 03/14/2006 10:06 PM
>
>
> To: bio java mailing list <biojava-l at biojava.org>
> cc: (bcc: Mark Schreiber/GP/Novartis)
> Subject: [Biojava-l] BioJAVA-X + BioSQL + no update
>
>
> Hi,
> I have following problem.
> I put a RichSequence-Object into a BioSQL-DB, using the new Classes from
> BioJAVA-X.
> Later I get these Sequence-Object from the BioSQL-DB (also with
> BioJAVA-X) and create new Faeture-Objects and Note-Objects and add
> these to the Sequence-Object.
> In the case of BioJAVA 1.4 all Features and Annotations are written into
> the BioSQL-DB. In case of BioJAVA-X there are no changes ind the DB.
> Includes BioJAVA-X a method to update the BioSQL-DB or how can I add the
> changes into the DB.
>
> Thanks,
> Christian
>
>
--
Christian Köberle
Max Planck Institute for Infection Biology
Department: Immunology
Schumannstr. 21/22
10117 Berlin
Tel: +49 30 28 460 562
e-mail: koeberle at mpiib-berlin.mpg.de
More information about the Biojava-l
mailing list