-->
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: Problem mapping class with depended class in it...
PostPosted: Wed Mar 29, 2006 2:46 pm 
Newbie

Joined: Tue Mar 28, 2006 10:27 am
Posts: 2
Hello,

I'm trying to store the following class:
Code:
        public class AlignJob {
           private int id;
           private String user,jobName;
           private long totalCost;
           private Container container;
   
           ...All needed setters, getters & constructors
        } 


Here the class container looks like this:
Code:
        public class Container {
           private int maxFullMatches;

           private List fullMatches;   

           ...setters,getters & constructors...
       }


As you can see it just has an integers, combined with a list of another self-made class:
Code:
       public class FullMatch implements Match{
           private int id;
           private String sequenceName1,sequenceName2;
           private int score;

           ...setters,getters & constructors...
      }




The mapping for the class FullMatch is quit simple:
Code:
       <?xml version="1.0"?>
       <!DOCTYPE hibernate-mapping PUBLIC
               "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
               "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

       <hibernate-mapping>
           <class name="be.ugent.aligner.FullMatch" table="FullMATCH">
               <id name="id" column="FULLMATCH_ID">
                   <generator class="increment"/>
               </id>
         <property name="sequenceName1"/>
         <property name="sequenceName2"/>
                   <property name="score"/>
           </class>
       </hibernate-mapping>




The mapping for AlignLib (=the upper-class) is a bit more complicated:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="be.ugent.aligner.server.AlignJob" table="INCOMPLETEJOBS"
             entity-name="IncompleteAlignJob"
    >
        <id name="id" column="ALIGNJOB_ID" >
            <generator class="increment"/>
        </id>
            <property name="user"/>
            <property name="jobName"/>
            <property name="totalCost"/>
           
            <component name="container" class="be.ugent.aligner.Container">
                        <property name="maxFullMatches"/>
                        <list name="fullMatches" cascade="all">
                                    <key column="ALIGNJOB_ID"/>
                                    <index column="FULLMATCH_INDEX" />
                                    <one-to-many class="be.ugent.aligner.FullMatch"/>
                        </list>         
            </component>
    </class>




When I try to store the AlignJob:

Code:
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
     session.saveOrUpdate("IncompleteAlignJob",job);
tx.commit();
session.close();



I get the following output:
Code:

Hibernate: select max(ALIGNJOB_ID) from INCOMPLETEJOBS
Hibernate: select max(FULLMATCH_ID) from FULLMATCH
Hibernate: insert into INCOMPLETEJOBS (user, jobName, totalCost, indexDatabase1, indexDatabase2, matrixName, open, extend, databaseName1, databaseName2, maxFullMatches, maxSimpleMatches, ALIGNJOB_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into FULLMATCH (sequenceName1, allignedSequence1, start1, sequenceName2, allignedSequence2, start2, identity, similarity, gaps, score, FULLMATCH_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into FULLMATCH (sequenceName1, allignedSequence1, start1, sequenceName2, allignedSequence2, start2, identity, similarity, gaps, score, FULLMATCH_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into FULLMATCH (sequenceName1, allignedSequence1, start1, sequenceName2, allignedSequence2, start2, identity, similarity, gaps, score, FULLMATCH_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into FULLMATCH (sequenceName1, allignedSequence1, start1, sequenceName2, allignedSequence2, start2, identity, similarity, gaps, score, FULLMATCH_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into FULLMATCH (sequenceName1, allignedSequence1, start1, sequenceName2, allignedSequence2, start2, identity, similarity, gaps, score, FULLMATCH_ID) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: update FULLMATCH set ALIGNJOB_ID=?, FULLMATCH_INDEX=? where FULLMATCH_ID=?
Hibernate: update FULLMATCH set ALIGNJOB_ID=?, FULLMATCH_INDEX=? where FULLMATCH_ID=?
Hibernate: update FULLMATCH set ALIGNJOB_ID=?, FULLMATCH_INDEX=? where FULLMATCH_ID=?
Hibernate: update FULLMATCH set ALIGNJOB_ID=?, FULLMATCH_INDEX=? where FULLMATCH_ID=?
Hibernate: update FULLMATCH set ALIGNJOB_ID=?, FULLMATCH_INDEX=? where FULLMATCH_ID=?
20:07:41,656  WARN JDBCExceptionReporter:71 - SQL Error: 0, SQLState: null
20:07:41,656 ERROR JDBCExceptionReporter:72 - failed batch
20:07:41,671 ERROR AbstractFlushingEventListener:299 - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:144)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:356)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   at be.ugent.aligner.server.DBMS.SaveJob(DBMS.java:268)
   at be.ugent.aligner.server.AlignJob.finishAlign(AlignJob.java:133)
   at be.ugent.aligner.server.DBMS.main(DBMS.java:54)
Caused by: java.sql.BatchUpdateException: failed batch
   at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
   at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
   ... 10 more

(the following is the real error as it is thrown)
Code:
Exception in thread "main" org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:91)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:79)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:202)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:230)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:144)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:296)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1009)
   at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:356)
   at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
   at be.ugent.aligner.server.DBMS.SaveJob(DBMS.java:268)
   at be.ugent.aligner.server.AlignJob.finishAlign(AlignJob.java:133)
   at be.ugent.aligner.server.DBMS.main(DBMS.java:54)
Caused by: java.sql.BatchUpdateException: failed batch
   at org.hsqldb.jdbc.jdbcStatement.executeBatch(Unknown Source)
   at org.hsqldb.jdbc.jdbcPreparedStatement.executeBatch(Unknown Source)
   at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:58)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:195)
   ... 10 more





If I don't let Hibernate map the List, everything works fine (so my AlignLib.hbm.xml looks then like this):
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="be.ugent.aligner.server.AlignJob" table="INCOMPLETEJOBS"
             entity-name="IncompleteAlignJob"
    >
        <id name="id" column="ALIGNJOB_ID" >
            <generator class="increment"/>
        </id>
            <property name="user"/>
            <property name="jobName"/>
            <property name="totalCost"/>
           
            <component name="container" class="be.ugent.aligner.Container">
                        <property name="maxFullMatches"/>
     
            </component>
    </class>


So I guess it's the list that's causing the exception...


Can anyone help me here???

I'm using the newest Hibernate stable build (version 3.1.3 I think), and as database I use HSQL (newest version, 1.8.0).




Tnx in advance,
Jeroen


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 3:49 am 
Newbie

Joined: Tue Mar 28, 2006 10:27 am
Posts: 2
Oke, I found a lead to the solution myself.

The problem is situated by the key-attribute of the list. I use there the key from the table (ALIGNLIB_ID). If I change this to CONTAINER_ID, there are no errors while storing (so alignlib.hbm.xml looks like this)

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="be.ugent.aligner.server.AlignJob" table="INCOMPLETEJOBS"
             entity-name="IncompleteAlignJob"
    >
        <id name="id" column="ALIGNJOB_ID" >
            <generator class="increment"/>
        </id>
            <property name="user"/>
            <property name="jobName"/>
            <property name="totalCost"/>
           
            <component name="container" class="be.ugent.aligner.Container">
                        <property name="id" column="CONTAINER_ID"/>
                        <property name="maxFullMatches"/>
                        <list name="fullMatches" cascade="all">
                                    <key column="CONTAINER_ID"/>
                                    <index column="FULLMATCH_INDEX" />
                                    <one-to-many class="be.ugent.aligner.FullMatch"/>
                        </list>         
            </component>
    </class>




Only problem is that CONTAINER_ID is null, because it is not being used.
So, when trying to retreave the AlignJob from the Database, I get an error when trying to acces the FullMatches...

Can anybody tell me how I can use ALIGNLIB_ID as key for the list, or another working solution?

Tnx,
Jeroen


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.