-->
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.  [ 3 posts ] 
Author Message
 Post subject: Unexpected delete clause in JUnit test
PostPosted: Wed Aug 11, 2004 8:09 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Hi all.

I've been looking for this but... so I take my chances and post.

MySQL 4.0.17, Spring framework RC 1.1, Hibernate 2.1.6, JUnit 3.8.1, ANT 1.6

AvikUser object holding a (composite) List of UserFunctionNode s referencing Function object, i.e basic relational object with a few extra fields.

Problem: JUnit testing a Spring-managed DAO results in a very unexpected, and extremely unwanted Hibernate-generated delete clause.

Here's the stack trace:
Code:
    [junit] ======================testGetFunction======================
    [junit] Hibernate: select avikuser0_.id as id0_, avikuser0_.fname as fname0_, avikuser0_.lname as lname0_, avikuser0
_.descr as descr0_, avikuser0_.email as email0_, avikuser0_.uname as uname0_, avikuser0_.pword as pword0_, avikuser0_.us
errole as userrole0_, avikuser0_.active as active0_, avikuser0_.listable as listable0_ from MASTERUSER avikuser0_ where
avikuser0_.id=?
    [junit] Hibernate: select functions0_.user_fk as user_fk__, functions0_.func_fk as func_fk__, functions0_.fromdate a
s fromdate__, functions0_.todate as todate__, functions0_.iscurrent as iscurrent__, function1_.id as id0_, function1_.fu
ncdesc as funcdesc0_, function1_.active as active0_ from user2function functions0_ left outer join function function1_ o
n functions0_.func_fk=function1_.id where functions0_.user_fk=?
    [junit] Hibernate: select delegated0_.user_fk as user_fk__, delegated0_.event_fk as event_fk__, delegated0_.delegate
_fk as delegate3___, delegated0_.validuntil as validuntil__, delegated0_.deleglevel as deleglevel__, event1_.id as id0_,
event1_.eventtype as eventtype0_, event1_.eventstatus as eventsta3_0_, event1_.created as created0_, event1_.changed as
changed0_, event1_.eventvisible as eventvis6_0_, event1_.diarynb as diarynb0_, event1_.evdate as evdate0_, event1_.evti
me as evtime0_, event1_.evdept as evdept0_, event1_.evloc as evloc0_, event1_.evdet as evdet0_, event1_.discdate as disc
date0_, event1_.disctime as disctime0_, event1_.discdept as discdept0_, event1_.discloc as discloc0_, event1_.discdet as
discdet0_, event1_.repdept as repdept0_, event1_.reppos as reppos0_, event1_.repname as repname0_, event1_.repdate as r
epdate0_, event1_.owner as owner0_, event1_.patname as patname0_, event1_.patnr as patnr0_, event1_.patinfo as patinfo0_
, event1_.patcomment as patcomment0_, event1_.bossentry as bossentry0_, event1_.bossread as bossread0_, event1_.reviewed
as reviewed0_, event1_.closed as closed0_, event1_.bossdate as bossdate0_, event1_.ev_descr as ev_descr0_, event1_.ev_w
hy as ev_why0_, event1_.ev_conseq as ev_conseq0_, event1_.ev_prevent as ev_prevent0_, event1_.ev_aux as ev_aux0_, depart
ment2_.id as id1_, department2_.itemcode as itemcode1_, department2_.itemorder as itemorder1_, department2_.itemval as i
temval1_, department2_.active as active1_, location3_.id as id2_, location3_.itemcode as itemcode2_, location3_.itemorde
r as itemorder2_, location3_.itemval as itemval2_, location3_.active as active2_, department4_.id as id3_, department4_.
itemcode as itemcode3_, department4_.itemorder as itemorder3_, department4_.itemval as itemval3_, department4_.active as
active3_, location5_.id as id4_, location5_.itemcode as itemcode4_, location5_.itemorder as itemorder4_, location5_.ite
mval as itemval4_, location5_.active as active4_, department6_.id as id5_, department6_.itemcode as itemcode5_, departme
nt6_.itemorder as itemorder5_, department6_.itemval as itemval5_, department6_.active as active5_, position7_.id as id6_
, position7_.itemcode as itemcode6_, position7_.itemorder as itemorder6_, position7_.itemval as itemval6_, position7_.ac
tive as active6_, function8_.id as id7_, function8_.funcdesc as funcdesc7_, function8_.active as active7_, function9_.id
as id8_, function9_.funcdesc as funcdesc8_, function9_.active as active8_ from delegation delegated0_ left outer join e
vent event1_ on delegated0_.event_fk=event1_.id left outer join Department department2_ on event1_.evdept=department2_.i
d left outer join Location location3_ on event1_.evloc=location3_.id left outer join Department department4_ on event1_.
discdept=department4_.id left outer join Location location5_ on event1_.discloc=location5_.id left outer join Department
department6_ on event1_.repdept=department6_.id left outer join Position position7_ on event1_.reppos=position7_.id lef
t outer join function function8_ on event1_.owner=function8_.id left outer join function function9_ on delegated0_.deleg
ate_fk=function9_.id where delegated0_.user_fk=?
    [junit] Hibernate: select function2_.id as id, function2_.funcdesc as funcdesc, function2_.active as active, functio
ns1_.user_fk as user_fk__, functions1_.func_fk as func_fk__, functions1_.fromdate as fromdate__, functions1_.todate as t
odate__, functions1_.iscurrent as iscurrent__ from MASTERUSER avikuser0_ left outer join user2function functions1_ on av
ikuser0_.id=functions1_.user_fk, function function2_ where functions1_.func_fk=function2_.id and ((functions1_.iscurrent
=1 )and(avikuser0_.id=? ))
    [junit] Hibernate: select delegated0_.user_fk as user_fk__, delegated0_.event_fk as event_fk__, delegated0_.delegate
_fk as delegate3___, delegated0_.validuntil as validuntil__, delegated0_.deleglevel as deleglevel__, event1_.id as id0_,
event1_.eventtype as eventtype0_, event1_.eventstatus as eventsta3_0_, event1_.created as created0_, event1_.changed as
changed0_, event1_.eventvisible as eventvis6_0_, event1_.diarynb as diarynb0_, event1_.evdate as evdate0_, event1_.evti
me as evtime0_, event1_.evdept as evdept0_, event1_.evloc as evloc0_, event1_.evdet as evdet0_, event1_.discdate as disc
date0_, event1_.disctime as disctime0_, event1_.discdept as discdept0_, event1_.discloc as discloc0_, event1_.discdet as
discdet0_, event1_.repdept as repdept0_, event1_.reppos as reppos0_, event1_.repname as repname0_, event1_.repdate as r
epdate0_, event1_.owner as owner0_, event1_.patname as patname0_, event1_.patnr as patnr0_, event1_.patinfo as patinfo0_
, event1_.patcomment as patcomment0_, event1_.bossentry as bossentry0_, event1_.bossread as bossread0_, event1_.reviewed
as reviewed0_, event1_.closed as closed0_, event1_.bossdate as bossdate0_, event1_.ev_descr as ev_descr0_, event1_.ev_w
hy as ev_why0_, event1_.ev_conseq as ev_conseq0_, event1_.ev_prevent as ev_prevent0_, event1_.ev_aux as ev_aux0_, depart
ment2_.id as id1_, department2_.itemcode as itemcode1_, department2_.itemorder as itemorder1_, department2_.itemval as i
temval1_, department2_.active as active1_, location3_.id as id2_, location3_.itemcode as itemcode2_, location3_.itemorde
r as itemorder2_, location3_.itemval as itemval2_, location3_.active as active2_, department4_.id as id3_, department4_.
itemcode as itemcode3_, department4_.itemorder as itemorder3_, department4_.itemval as itemval3_, department4_.active as
active3_, location5_.id as id4_, location5_.itemcode as itemcode4_, location5_.itemorder as itemorder4_, location5_.ite
mval as itemval4_, location5_.active as active4_, department6_.id as id5_, department6_.itemcode as itemcode5_, departme
nt6_.itemorder as itemorder5_, department6_.itemval as itemval5_, department6_.active as active5_, position7_.id as id6_
, position7_.itemcode as itemcode6_, position7_.itemorder as itemorder6_, position7_.itemval as itemval6_, position7_.ac
tive as active6_, function8_.id as id7_, function8_.funcdesc as funcdesc7_, function8_.active as active7_, function9_.id
as id8_, function9_.funcdesc as funcdesc8_, function9_.active as active8_ from delegation delegated0_ left outer join e
vent event1_ on delegated0_.event_fk=event1_.id left outer join Department department2_ on event1_.evdept=department2_.i
d left outer join Location location3_ on event1_.evloc=location3_.id left outer join Department department4_ on event1_.
discdept=department4_.id left outer join Location location5_ on event1_.discloc=location5_.id left outer join Department
department6_ on event1_.repdept=department6_.id left outer join Position position7_ on event1_.reppos=position7_.id lef
t outer join function function8_ on event1_.owner=function8_.id left outer join function function9_ on delegated0_.deleg
ate_fk=function9_.id where delegated0_.user_fk=?
    [junit] [color=red]Hibernate: delete from user2function where user_fk=?[/color]
    [junit] ======================testGetFunction======================


Mapping (part of) for AvikUser:

Code:
<hibernate-mapping>
    <class
        name="ks.rah.avik2.domain.AvikUser"
        table="MASTERUSER"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="id"
            type="java.lang.Long"
            unsaved-value="null"
        >
            <generator class="native">
            </generator>
        </id>

        <property
            name="fname"
            type="java.lang.String"
            update="true"
            insert="true"
            column="fname"
        />

   etc
   etc
   etc


        <bag
            name="functions"
            table="user2function"
            lazy="false"
            inverse="false"
            cascade="save-update"
        >

              <key
                  column="user_fk"
              />

              <composite-element
                  class="ks.rah.avik2.domain.support.UserFunctionNode"
              >

        <many-to-one
            name="function"
            class="ks.rah.avik2.domain.Function"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="func_fk"
        />

        <property
            name="from"
            type="date"
            update="true"
            insert="true"
            column="fromdate"
        />

        <property
            name="until"
            type="date"
            update="true"
            insert="true"
            column="todate"
        />

        <property
            name="current"
            type="java.lang.Boolean"
            update="true"
            insert="true"
            column="iscurrent"
        />

              </composite-element>

        </bag>

    </class>


Mapping for Function:

Code:
<hibernate-mapping>
    <class
        name="ks.rah.avik2.domain.Function"
        table="function"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="id"
            type="java.lang.Long"
            unsaved-value="null"
        >
            <generator class="native">
            </generator>
        </id>

        <property
            name="description"
            type="java.lang.String"
            update="true"
            insert="true"
            column="funcdesc"
        />

        <property
            name="active"
            type="boolean"
            update="true"
            insert="true"
            column="active"
        />

        <bag
            name="delegated"
            table="delegation"
            lazy="false"
            inverse="false"
            cascade="save-update"
        >

              <key
                  column="user_fk"
              />

              <composite-element
                  class="ks.rah.avik2.domain.Delegation"
              >

        <many-to-one
            name="event"
            class="ks.rah.avik2.domain.Event"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="event_fk"
        />

        <many-to-one
            name="delegate"
            class="ks.rah.avik2.domain.Function"
            cascade="none"
            outer-join="auto"
            update="true"
            insert="true"
            column="delegate_fk"
        />

              </composite-element>

        </bag>

    </class>

</hibernate-mapping>


Calling JUnit testcase method:

Code:
   public void testGetFunction() throws HibernateException
   {
   System.out.println("======================testGetFunction======================");
      user = logic.loadUser(42);
      this.assertNotNull("user is NULL", user);
      Function f = logic.getCurrentFunction(user);
      this.assertNotNull("f is NULL", f);
      this.assertEquals(f.getDescription(), "Test");
         System.out.println("======================testGetFunction======================");
   }



The call to
Code:
user = logic.loadUser(42);

does not generate any delete clauses. I tested it separately.


Invoked method in DAO:

Code:
   public Function getCurrentFunction(final AvikUser user) throws DataAccessException{
      List out = getHibernateTemplate().find(
         "select n.function from AvikUser u left join fetch " +
         "u.functions n where n.current = 1 and u.id = ?",
         new Object[] {user.getId()},
         new Type[] {Hibernate.LONG});
         
         if( out == null ) return null;
         else return (Function) out.get(0);
   }

How is it possible that this generates a delete clause!?
Anyone see what I'm doing wrong here or missing?

Thanks!

/C


Top
 Profile  
 
 Post subject: Addendum
PostPosted: Wed Aug 11, 2004 8:12 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Forgot...

Predesesses the above stack trace

Code:
    [junit] 13:30:57,843  INFO Binder:229 - Mapping class: ks.rah.avik2.domain.AvikUser -> MASTERUSER
    [junit] 13:30:57,843  INFO Binder:571 - Mapping collection: ks.rah.avik2.domain.AvikUser.functions -> user2function
    [junit] 13:30:57,875  INFO Binder:229 - Mapping class: ks.rah.avik2.domain.Department -> Department
    [junit] 13:30:57,921  INFO Binder:229 - Mapping class: ks.rah.avik2.domain.Event -> event
    [junit] 13:30:57,921  INFO Binder:571 - Mapping collection: ks.rah.avik2.domain.Event.entries -> event2field2option
    [junit] 13:30:57,953  INFO Binder:229 - Mapping class: ks.rah.avik2.domain.Location -> Location
    [junit] 13:30:57,984  INFO Binder:229 - Mapping class: ks.rah.avik2.domain.Position -> Position
    [junit] 13:30:58,015  INFO Binder:229 - Mapping class: ks.rah.avik2.domain.Function -> function
    [junit] 13:30:58,015  INFO Binder:571 - Mapping collection: ks.rah.avik2.domain.Function.delegated -> delegation
    [junit] 13:30:58,046  INFO Binder:229 - Mapping class: ks.rah.avik2.domain.support.TextEntry -> textentry
    [junit] 13:30:58,093  INFO Binder:229 - Mapping class: ks.rah.avik2.domain.ui.AvikPage -> uipage
    [junit] 13:30:58,093  INFO Binder:571 - Mapping collection: ks.rah.avik2.domain.ui.AvikPage.fields -> uipage2uifield

    [junit] 13:30:58,125  INFO Binder:229 - Mapping class: ks.rah.avik2.domain.ui.PageField -> uifield
    [junit] 13:30:58,125  INFO Binder:571 - Mapping collection: ks.rah.avik2.domain.ui.PageField.options -> uifield2uiop
tion
    [junit] 13:30:58,156  INFO Binder:229 - Mapping class: ks.rah.avik2.domain.ui.FieldOption -> uioption
    [junit] 13:30:58,187  INFO Binder:229 - Mapping class: ks.rah.avik2.domain.ui.HelpText -> uihelp
    [junit] 13:30:58,187  INFO Configuration:627 - processing one-to-many association mappings
    [junit] 13:30:58,187  INFO Binder:1181 - Mapping collection: ks.rah.avik2.domain.Event.textEntries -> textentry
    [junit] 13:30:58,203  INFO Configuration:636 - processing one-to-one association property references
    [junit] 13:30:58,218  INFO Configuration:661 - processing foreign key constraints
    [junit] 13:30:58,218  INFO Dialect:82 - Using dialect: net.sf.hibernate.dialect.MySQLDialect
    [junit] 13:30:58,218  INFO SettingsFactory:59 - Maximim outer join fetch depth: 2
    [junit] 13:30:58,234  INFO SettingsFactory:63 - Use outer join fetching: true
    [junit] 13:30:58,234  INFO ConnectionProviderFactory:53 - Initializing connection provider: org.springframework.orm.
hibernate.LocalDataSourceConnectionProvider
    [junit] 13:30:58,234  INFO TransactionManagerLookupFactory:33 - No TransactionManagerLookup configured (in JTA envir
onment, use of process level read-write cache is not recommended)
    [junit] 13:30:58,234  INFO SettingsFactory:103 - Use scrollable result sets: true
    [junit] 13:30:58,250  INFO SettingsFactory:106 - Use JDBC3 getGeneratedKeys(): true
    [junit] 13:30:58,250  INFO SettingsFactory:109 - Optimize cache for minimal puts: false
    [junit] 13:30:58,250  INFO SettingsFactory:115 - echoing all SQL to stdout
    [junit] 13:30:58,250  INFO SettingsFactory:118 - Query language substitutions: {}
    [junit] 13:30:58,281  INFO SettingsFactory:129 - cache provider: net.sf.hibernate.cache.EhCacheProvider
    [junit] 13:30:58,281  INFO Configuration:1116 - instantiating and configuring caches
    [junit] 13:30:58,296  INFO SessionFactoryImpl:118 - building session factory
    [junit] 13:30:58,390  INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
    [junit] ======================testGetFunction======================


etc.

/C


Top
 Profile  
 
 Post subject: Working
PostPosted: Wed Aug 11, 2004 11:58 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Now it's working as expected, but I don't know why.
Closed every command window down, altered property 'cglib.use_reflection_optimizer' to true, decreased number of pooled statements in c3p0, and now it works.

I'm happy, but it's odd, isn't it?

But I'll sure as h--l be back, don't worry.......

/C


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