-->
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.  [ 4 posts ] 
Author Message
 Post subject: Serializable - completely confused
PostPosted: Wed Dec 01, 2004 7:47 am 
Newbie

Joined: Fri Aug 20, 2004 8:26 am
Posts: 5
Location: Karlsruhe, Germany
Hello,
I'm totally lost. I succeeded in reproducing the strange behaviour occurring in my (quite big) app with simple classes. Please, if anybody could help me - why is this happening?

I have the following code in my main()-method (hibernate-version 2.1.4):
Code:
      Session session = sf.openSession();
      Transaction tx = session.beginTransaction();

      KlasseC c1 = new KlasseC();
      c1.setAttr2(1);
      c1.setName("C1");

      KlasseC c2 = new KlasseC();
      c2.setAttr2(2);
      c2.setName("C2");

      KlasseC c3 = new KlasseC();
      c3.setAttr2(3);
      c3.setName("C3");

      KlasseC c11 = new KlasseC();
      c11.setAttr2(11);
      c11.setName("C11");

      KlasseC c12 = new KlasseC();
      c12.setAttr2(12);
      c12.setName("C12");

      KlasseC c13 = new KlasseC();
      c13.setAttr2(13);
      c13.setName("C13");

      Set s = new HashSet();
      s.add(c11);
      s.add(c12);
      s.add(c13);

      KlasseD d = new KlasseD();
      d.setMatr(new KlasseC[][] {{c1, c2}, {c2, c3}});
      d.setSet(s);
      d.setRef(c1);

      KlasseE e = new KlasseE();
      e.setDRef(d);

      System.out.println("before save");
      session.save(e);
      System.out.println("after save, before commit");
      tx.commit();
      System.out.println("after commit");

      tx = session.beginTransaction();

      System.out.println("before find");
      List ergList = session.find("from hibtest.KlasseE");
      System.out.println("after find");

      System.out.println(session.isDirty());

      System.out.println("before commit");
      tx.commit();
      System.out.println("after commit");

      session.close();

and the hibernate-mapping:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping default-cascade="save-update">
   <class name="hibtest.KlasseC" table="KLASSEC">
      <id type="integer" column="ID" unsaved-value="0">
         <generator class="native"/>
      </id>
      <property name="myName" column="NAME" type="string" access="field"/>
      <property name="myAttr2" column="ATTR2" type="long" access="field"/>
   </class>
   <class name="hibtest.KlasseD" table="KLASSED">
      <id type="integer" column="ID" unsaved-value="0">
         <generator class="native"/>
      </id>
      <many-to-one name="myRef" column="REF" class="hibtest.KlasseC" access="field"/>
      <property name="myMatr" column="MATR" type="serializable" access="field"/>
      <property name="mySet" column="MYSET" type="serializable" access="field"/>
   </class>
   <class name="hibtest.KlasseE" table="KLASSEE">
      <id type="integer" column="ID" unsaved-value="0">
         <generator class="native"/>
      </id>
      <property name="myDRef" column="DREF" type="serializable" access="field"/>
   </class>
</hibernate-mapping>

the output if I run the app:

[java] before save
[java] Hibernate: insert into KLASSEE (DREF) values (?)
[java] Hibernate: SELECT LAST_INSERT_ID()
[java] after save, before commit
[java] Hibernate: update KLASSEE set DREF=? where ID=?
[java] after commit
[java] before find
[java] Hibernate: update KLASSEE set DREF=? where ID=?
[java] Hibernate: select klassee0_.ID as ID, klassee0_.DREF as DREF from KLASSEE klassee0_
[java] after find
[java] true
[java] before commit
[java] Hibernate: update KLASSEE set DREF=? where ID=?
[java] after commit

Why is there an update on KlasseE although I only read from the database? It becomes even more strange, if I only add 2 elements to the Set: no update is made to KlasseE.
I'm totally stuck - where is the problem? Does anybody has any idea? Thanks!
Code:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 9:12 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if you enable hibernate debug log it should tell you why it wants to update something.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 9:13 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
btw. the subject is totally confusing - what does Serializable have to do with this ? (besides you mention it in the hbm.xml file)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 11:01 am 
Newbie

Joined: Fri Aug 20, 2004 8:26 am
Posts: 5
Location: Karlsruhe, Germany
Well, this only happens when I'm mappping properties as Serializable. For the simple example it doesn't make much sense, but in the big app, there are collections that themselves contain collections. Without a redesign I have to use this kind of mapping.

I set the log level to DEBUG and ran the app once again:

Code:
     [java] 15:45:03,374 DEBUG SessionImpl:555 - opened session
     [java] 15:45:03,384 DEBUG JDBCTransaction:37 - begin
     [java] 15:45:03,384 DEBUG DriverManagerConnectionProvider:84 - total checked-out connections: 0
     [java] 15:45:03,384 DEBUG DriverManagerConnectionProvider:90 - using pooled JDBC connection, pool size: 0
     [java] 15:45:03,384 DEBUG JDBCTransaction:41 - current autocommit status:false
     [java] before save
     [java] 15:45:03,394 DEBUG SessionImpl:825 - saving [hibtest.KlasseE#<null>]
     [java] 15:45:03,394 DEBUG SessionImpl:2305 - executing insertions
     [java] 15:45:03,394 DEBUG Cascades:497 - processing cascades for: hibtest.KlasseE
     [java] 15:45:03,404 DEBUG Cascades:506 - done processing cascades for: hibtest.KlasseE
     [java] 15:45:03,444 DEBUG EntityPersister:490 - Inserting entity: hibtest.KlasseE (native id)
     [java] 15:45:03,444 DEBUG BatcherImpl:196 - about to open: 0 open PreparedStatements, 0 open ResultSets
     [java] 15:45:03,444 DEBUG SQL:237 - insert into KLASSEE (DREF) values (?)
     [java] Hibernate: insert into KLASSEE (DREF) values (?)
     [java] 15:45:03,444 DEBUG BatcherImpl:241 - preparing statement
     [java] 15:45:03,474 DEBUG EntityPersister:388 - Dehydrating entity: [hibtest.KlasseE#<null>]
     [java] 15:45:03,474 DEBUG BatcherImpl:203 - done closing: 0 open PreparedStatements, 0 open ResultSets
     [java] 15:45:03,474 DEBUG BatcherImpl:261 - closing statement
     [java] 15:45:03,474 DEBUG BatcherImpl:196 - about to open: 0 open PreparedStatements, 0 open ResultSets
     [java] 15:45:03,484 DEBUG SQL:237 - SELECT LAST_INSERT_ID()
     [java] Hibernate: SELECT LAST_INSERT_ID()
     [java] 15:45:03,484 DEBUG BatcherImpl:241 - preparing statement
     [java] 15:45:03,484 DEBUG AbstractEntityPersister:1229 - Natively generated identity: 13
     [java] 15:45:03,494 DEBUG BatcherImpl:203 - done closing: 0 open PreparedStatements, 0 open ResultSets
     [java] 15:45:03,494 DEBUG BatcherImpl:261 - closing statement
     [java] 15:45:03,494 DEBUG Cascades:497 - processing cascades for: hibtest.KlasseE
     [java] 15:45:03,494 DEBUG Cascades:506 - done processing cascades for: hibtest.KlasseE
     [java] after save, before commit
     [java] 15:45:03,504 DEBUG JDBCTransaction:59 - commit
     [java] 15:45:03,504 DEBUG SessionImpl:2242 - flushing session
     [java] 15:45:03,504 DEBUG Cascades:497 - processing cascades for: hibtest.KlasseE
     [java] 15:45:03,504 DEBUG Cascades:506 - done processing cascades for: hibtest.KlasseE
     [java] 15:45:03,514 DEBUG SessionImpl:2435 - Flushing entities and processing referenced collections
     [java] 15:45:03,514 DEBUG AbstractEntityPersister:274 - hibtest.KlasseE.myDRef is dirty
     [java] 15:45:03,514 DEBUG SessionImpl:2529 - Updating entity: [hibtest.KlasseE#13]
     [java] 15:45:03,524 DEBUG SessionImpl:2776 - Processing unreferenced collections
     [java] 15:45:03,524 DEBUG SessionImpl:2790 - Scheduling collection removes/(re)creates/updates
     [java] 15:45:03,534 DEBUG SessionImpl:2266 - Flushed: 0 insertions, 1 updates, 0 deletions to 1 objects
     [java] 15:45:03,534 DEBUG SessionImpl:2271 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
     [java] 15:45:03,534 DEBUG Printer:75 - listing entities:
     [java] 15:45:03,544 DEBUG Printer:82 - hibtest.KlasseE{myDRef=...} //omitted to keep this readable
     [java] 15:45:03,544 DEBUG SessionImpl:2355 - executing flush
     [java] 15:45:03,554 DEBUG EntityPersister:648 - Updating entity: [hibtest.KlasseE#13]
     [java] 15:45:03,554 DEBUG BatcherImpl:196 - about to open: 0 open PreparedStatements, 0 open ResultSets
     [java] 15:45:03,554 DEBUG SQL:237 - update KLASSEE set DREF=? where ID=?
     [java] Hibernate: update KLASSEE set DREF=? where ID=?
     [java] 15:45:03,554 DEBUG BatcherImpl:241 - preparing statement
     [java] 15:45:03,554 DEBUG EntityPersister:388 - Dehydrating entity: [hibtest.KlasseE#13]
     [java] 15:45:03,564 DEBUG BatcherImpl:203 - done closing: 0 open PreparedStatements, 0 open ResultSets
     [java] 15:45:03,564 DEBUG BatcherImpl:261 - closing statement
     [java] 15:45:03,564 DEBUG SessionImpl:2820 - post flush
     [java] 15:45:03,584 DEBUG SessionImpl:585 - transaction completion
     [java] after commit
     [java] 15:45:03,584 DEBUG JDBCTransaction:37 - begin
     [java] 15:45:03,584 DEBUG JDBCTransaction:41 - current autocommit status:false
     [java] before find
     [java] 15:45:03,594 DEBUG SessionImpl:1526 - find: from hibtest.KlasseE
     [java] 15:45:03,614 DEBUG QueryTranslator:147 - compiling query
     [java] 15:45:03,634 DEBUG SessionImpl:2242 - flushing session
     [java] 15:45:03,644 DEBUG Cascades:497 - processing cascades for: hibtest.KlasseE
     [java] 15:45:03,644 DEBUG Cascades:506 - done processing cascades for: hibtest.KlasseE
     [java] 15:45:03,644 DEBUG SessionImpl:2435 - Flushing entities and processing referenced collections
     [java] 15:45:03,644 DEBUG SessionImpl:2776 - Processing unreferenced collections
     [java] 15:45:03,644 DEBUG SessionImpl:2790 - Scheduling collection removes/(re)creates/updates
     [java] 15:45:03,644 DEBUG SessionImpl:2266 - Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
     [java] 15:45:03,644 DEBUG SessionImpl:2271 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
     [java] 15:45:03,644 DEBUG Printer:75 - listing entities:
     [java] 15:45:03,644 DEBUG Printer:82 - hibtest.KlasseE{myDRef=...} //omitted to keep this readable
     [java] 15:45:03,654 DEBUG SessionImpl:1814 - Dont need to execute flush
     [java] 15:45:03,654 DEBUG QueryTranslator:199 - HQL: from hibtest.KlasseE
     [java] 15:45:03,654 DEBUG QueryTranslator:200 - SQL: select klassee0_.ID as ID, klassee0_.DREF as DREF from KLASSEE klassee0_
     [java] 15:45:03,654 DEBUG BatcherImpl:196 - about to open: 0 open PreparedStatements, 0 open ResultSets
     [java] 15:45:03,654 DEBUG SQL:237 - select klassee0_.ID as ID, klassee0_.DREF as DREF from KLASSEE klassee0_
     [java] Hibernate: select klassee0_.ID as ID, klassee0_.DREF as DREF from KLASSEE klassee0_
     [java] 15:45:03,654 DEBUG BatcherImpl:241 - preparing statement
     [java] 15:45:03,925 DEBUG Loader:197 - processing result set
     [java] 15:45:03,925 DEBUG Loader:405 - result row: 13
     [java] 15:45:03,925 DEBUG Loader:226 - done processing result set (1 rows)
     [java] 15:45:03,925 DEBUG BatcherImpl:203 - done closing: 0 open PreparedStatements, 0 open ResultSets
     [java] 15:45:03,925 DEBUG BatcherImpl:261 - closing statement
     [java] 15:45:03,925 DEBUG Loader:239 - total objects hydrated: 0
     [java] 15:45:03,925 DEBUG SessionImpl:3112 - initializing non-lazy collections
     [java] after find
     [java] 15:45:03,925 DEBUG SessionImpl:2310 - checking session dirtiness
     [java] 15:45:03,925 DEBUG SessionImpl:2242 - flushing session
     [java] 15:45:03,925 DEBUG Cascades:497 - processing cascades for: hibtest.KlasseE
     [java] 15:45:03,925 DEBUG Cascades:506 - done processing cascades for: hibtest.KlasseE
     [java] 15:45:03,965 DEBUG SessionImpl:2435 - Flushing entities and processing referenced collections
     [java] 15:45:03,975 DEBUG SessionImpl:2776 - Processing unreferenced collections
     [java] 15:45:03,975 DEBUG SessionImpl:2790 - Scheduling collection removes/(re)creates/updates
     [java] 15:45:03,975 DEBUG SessionImpl:2266 - Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
     [java] 15:45:03,975 DEBUG SessionImpl:2271 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
     [java] 15:45:04,005 DEBUG Printer:75 - listing entities:
     [java] 15:45:04,005 DEBUG Printer:82 - hibtest.KlasseE{myDRef=...} //omitted to keep this readable
     [java] 15:45:04,045 DEBUG SessionImpl:2325 - session not dirty
     [java] false
     [java] before commit
     [java] 15:45:04,045 DEBUG JDBCTransaction:59 - commit
     [java] 15:45:04,045 DEBUG SessionImpl:2242 - flushing session
     [java] 15:45:04,045 DEBUG Cascades:497 - processing cascades for: hibtest.KlasseE
     [java] 15:45:04,045 DEBUG Cascades:506 - done processing cascades for: hibtest.KlasseE
     [java] 15:45:04,115 DEBUG SessionImpl:2435 - Flushing entities and processing referenced collections
     [java] 15:45:04,115 DEBUG SessionImpl:2776 - Processing unreferenced collections
     [java] 15:45:04,115 DEBUG SessionImpl:2790 - Scheduling collection removes/(re)creates/updates
     [java] 15:45:04,115 DEBUG SessionImpl:2266 - Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
     [java] 15:45:04,115 DEBUG SessionImpl:2271 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
     [java] 15:45:04,145 DEBUG Printer:75 - listing entities:
     [java] 15:45:04,145 DEBUG Printer:82 - hibtest.KlasseE{myDRef=...} //omitted to keep this readable
     [java] 15:45:04,195 DEBUG SessionImpl:2355 - executing flush
     [java] 15:45:04,195 DEBUG SessionImpl:2820 - post flush
     [java] 15:45:04,195 DEBUG SessionImpl:585 - transaction completion
     [java] after commit
     [java] 15:45:04,195 DEBUG SessionImpl:573 - closing session
     [java] 15:45:04,195 DEBUG SessionImpl:3332 - disconnecting session
     [java] 15:45:04,195 DEBUG DriverManagerConnectionProvider:120 - returning connection to pool, pool size: 1
     [java] 15:45:04,215 DEBUG SessionImpl:585 - transaction completion

Now I think I'm crazy: the debug output doesn't print out any updates. It's AN OTHER output - I swear, I didn't change anything except the log level (I changed it back again and the output shown in the first post appeared). Something's going the wrong way in my app, but where???


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.