-->
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.  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: composite-id fu 3, the case of the timestamp anomaly...
PostPosted: Tue Sep 09, 2003 2:46 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Hey, I'm back again, with another funky problem.

Same situation with the autogenerated composite id (working like a champ thanks to Gavin's Debugging Fu) but I'm having a problem adding a <timestamp> or <version> element to the composite id class. I can add a property of type timestamp just fine, but when I use a <timestamp> or <version> element I get exceptions related to a null SQL statement being sent to the database.

This does not happen when I have a timestamp on a mapped class with a regular id.

Here's the debug trace. I'm using MySQL with the 3.0.8 JDBC driver.

Code:
13:22:19,836 DEBUG NormalizedEntityPersister:676 - Updating entity: [com.foo.bar.data.menu.HeirarchyItem#com.foo.bar.data.sites.CompositeSiteID@4a5c78[]]
13:22:19,838 DEBUG NormalizedEntityPersister:677 - Existing version: Tue Sep 09 13:21:27 CDT 2003 -> New version: 2003-09-09 13:21:43.094
13:22:19,838 DEBUG BatcherImpl:192 - about to open: 0 open PreparedStatements, 0 open ResultSets
13:22:19,839 DEBUG BatcherImpl:226 - prepared statement get: update base_site_data_objects set timestamp=? where generated_id=? and site=? and timestamp=?
Hibernate: update base_site_data_objects set timestamp=? where generated_id=? and site=? and timestamp=?
13:22:19,841 DEBUG BatcherImpl:232 - preparing statement
13:22:19,842 DEBUG BatcherImpl:192 - about to open: 1 open PreparedStatements, 0 open ResultSets
13:22:19,844 DEBUG BatcherImpl:226 - prepared statement get: null
Hibernate: null
13:22:19,845 DEBUG BatcherImpl:232 - preparing statement
13:22:19,854 DEBUG JDBCExceptionReporter:36 - SQL Exception
java.sql.SQLException: SQL String can not be NULL
        at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:115)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1293)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1267)
        at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:233)
        at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:56)
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:687)
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:669)
        at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:38)
        at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2278)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2235)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2178)
        at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)
        at HibernateTest.main(HibernateTest.java:531)
13:22:19,859  WARN JDBCExceptionReporter:38 - SQL Error: 0, SQLState: S1009
13:22:19,862 ERROR JDBCExceptionReporter:46 - SQL String can not be NULL
13:22:19,864 DEBUG JDBCExceptionReporter:36 - SQL Exception
java.sql.SQLException: SQL String can not be NULL
        at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:115)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1293)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1267)
        at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:233)
        at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:56)
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:687)
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:669)
        at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:38)
        at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2278)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2235)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2178)
        at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)
        at HibernateTest.main(HibernateTest.java:531)
13:22:19,867  WARN JDBCExceptionReporter:38 - SQL Error: 0, SQLState: S1009
13:22:19,871 ERROR JDBCExceptionReporter:46 - SQL String can not be NULL
13:22:19,872 DEBUG BatcherImpl:199 - done closing: 1 open PreparedStatements, 0 open ResultSets
13:22:19,873 DEBUG BatcherImpl:245 - closing statement
13:22:19,880 DEBUG JDBCExceptionReporter:36 - SQL Exception
java.sql.SQLException: SQL String can not be NULL
        at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:115)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1293)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1267)
        at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:233)
        at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:56)
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:687)
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:669)
        at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:38)
        at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2278)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2235)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2178)
        at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)
        at HibernateTest.main(HibernateTest.java:531)
13:22:19,881  WARN JDBCExceptionReporter:38 - SQL Error: 0, SQLState: S1009
13:22:19,884 ERROR JDBCExceptionReporter:46 - SQL String can not be NULL
13:22:19,885 ERROR JDBCExceptionReporter:38 - could not delete: [com.foo.bar.data.menu.HeirarchyItem#com.foo.bar.data.sites.CompositeSiteID@4a5c78[]]
java.sql.SQLException: SQL String can not be NULL
        at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:115)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1293)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1267)
        at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:233)
        at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:56)
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:687)
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:669)
        at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:38)
        at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2278)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2235)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2178)
        at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)
        at HibernateTest.main(HibernateTest.java:531)
13:22:19,889 ERROR SessionImpl:2242 - Could not synchronize database state with session
java.sql.SQLException: SQL String can not be NULL
        at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:115)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1293)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1267)
        at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:233)
        at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:56)
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:687)
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:669)
        at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:38)
        at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2278)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2235)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2178)
        at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)
        at HibernateTest.main(HibernateTest.java:531)
rethrown as
net.sf.hibernate.JDBCException: could not delete: [com.foo.bar.data.menu.HeirarchyItem#com.foo.bar.data.sites.CompositeSiteID@4a5c78[]]: SQL String can not be NULL
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:710)
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:669)
        at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:38)
        at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2278)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2235)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2178)
        at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)
        at HibernateTest.main(HibernateTest.java:531)
Caused by: java.sql.SQLException: SQL String can not be NULL
        at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:115)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1293)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1267)
        at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:233)
        at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:56)
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:687)
        ... 7 more
Exception in thread "main" java.sql.SQLException: SQL String can not be NULL
        at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:115)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1293)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1267)
        at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:233)
        at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:56)
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:687)
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:669)
        at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:38)
        at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2278)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2235)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2178)
        at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)
        at HibernateTest.main(HibernateTest.java:531)
rethrown as net.sf.hibernate.JDBCException: could not delete: [com.foo.bar.data.menu.HeirarchyItem#com.foo.bar.data.sites.CompositeSiteID@4a5c78[]]: SQL String can not be NULL
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:710)
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:669)
        at net.sf.hibernate.impl.ScheduledUpdate.execute(ScheduledUpdate.java:38)
        at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2278)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2235)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2178)
        at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:56)
        at HibernateTest.main(HibernateTest.java:531)
Caused by: java.sql.SQLException: SQL String can not be NULL
        at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:115)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1293)
        at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1267)
        at net.sf.hibernate.impl.BatcherImpl.getPreparedStatement(BatcherImpl.java:233)
        at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:56)
        at net.sf.hibernate.persister.NormalizedEntityPersister.update(NormalizedEntityPersister.java:687)
        ... 7 more


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 09, 2003 10:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Could you show your mapping. Looks like a broken mapping; perhaps you put the <timestamp> inside the <composite-id> element?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 10, 2003 1:09 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Nah, I just added a <timestamp> element immediately below it. (not nested within) In fact, it may even be present in the code I uploaded for the JIRA issue. (key HB-311)

I'm also not using <composite-id> anymore as I've gotten my autogenerated CompositeSiteID up and running. The same thing happens when I use a similar <composite-id> that is not autogenerated.

Here's a sample mapping:
Code:
<hibernate-mapping default-cascade="save-update">
   
    <!-- BEGIN SITES -->
   
    <class name="com.foo.bar.data.sites.Site" mutable="true" table="sites">
       
        <id name="id" type="long">
            <generator class="native"/>
        </id>

        <!-- no problem here... -->
        <version name="version"/>

        <property name="name" type="string" column="name" not-null="true" unique="true"/>

    </class> <!-- Site -->

    <!-- END SITES -->
   
    <class name="com.foo.bar.data.base.SiteDataObject" table="site_data_objects">

        <jcs-cache usage="read-write"/>
       
        <id name="id" type="com.foo.bar.data.sites.CompositeSiteIDType">
            <column name="generated_id"/>
            <column name="site"/>
            <generator class="com.foo.bar.data.sites.CompositeSiteIDGenerator"/>
        </id>
       
        <!-- This id mapping also produces the error
        <composite-id unsaved-value="any">
            <key-property name="id" type="long"/>
            <key-many-to-one name="site" class="com.foo.bar.data.sites.Site"/>
        </composite-id>
        -->

        <!-- This line causes the problem -->
        <timestamp name="timestamp"/>

    </class>

</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 10, 2003 4:50 pm 
Newbie

Joined: Fri Sep 05, 2003 1:58 pm
Posts: 2
Location: Atlanta, GA
I'm not sure MySQL (or any other database) allows you to reference a column named "timestamp" without quoting it. Try changing this:

Code:
<timestamp name="timestamp"/>


to this:

Code:
<timestamp name="timestamp" column="`timestamp`"/>


MySQL may actually allow you to reference columns named "timestamp". If this is the case, ignore this post.

Thanks,
-Alan


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 10, 2003 5:56 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Hmmmmm... I've found a line in NormalizedEntityPersister that could be causing the problem.

NormalizedEntityPersister.generateUpdateStrings() (NormalizedEntityPersister line 287)
Code:
result[j] = hasColumns ? update.toStatementString() : null;

A SQL String generated could be null, and there's no null check on the SQL statements before a PreparedStatement is created in the BatcherImpl.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2003 12:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
WTF!!!!??? What are you doing here?


(1) NormalizedEntityPersister is only used for <joined-subclass> mappings! How did you trick Hibernate into using it in this case??

(2) even if I hack it to use NormalizedEntityPersister, I _still_ can't reproduce this failure.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2003 12:19 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Hold on, according to the stack trace, the problem is when trying to delete:

com.foo.bar.data.menu.HeirarchyItem


But you havn't shown the mapping for that class!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2003 1:53 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Sorry. I put an abbreviated mapping, similar to the one in JIRA issue HB-311, but I guess I abbreviated it too much. My bad. :)

Here's a more complete mapping:
Code:
<hibernate-mapping default-cascade="save-update">
   
    <class name="com.foo.bar.data.base.SiteDataObject" table="base_site_data_objects">
       
        <id name="id" type="com.foo.bar.data.sites.CompositeSiteIDType">
            <column name="generated_id"/>
            <column name="site"/>
            <generator class="com.foo.bar.data.sites.CompositeSiteIDGenerator"/>
        </id>
       
        <!-- This id mapping also produces the error
        <composite-id unsaved-value="any">
            <key-property name="id" type="long"/>
            <key-many-to-one name="site" class="com.foo.bar.data.sites.Site"/>
        </composite-id>
        -->
       
        <timestamp name="timestamp"/>
       
        <!-- BEGIN LISTINGS -->
       
        <joined-subclass name="com.foo.bar.data.listing.Listing" table="listings">
       
            <key><column name="generated_id"/><column name="site"/></key>
           
            <!-- TODO: change unique back to true after testing! -->
            <property name="name" type="string" not-null="true" unique="false"/>
           
        </joined-subclass>
       
        <!-- END LISTINGS -->

        <!-- BEGIN MENU -->
       
        <joined-subclass name="com.foo.bar.data.menu.MenuItem" table="menu_items">

            <key><column name="generated_id"/><column name="site"/></key>

            <property name="label" type="string" not-null="true" unique="false">
                <column name="label" unique-key="label-parent"/>
            </property>
           
            <many-to-one name="parent" class="com.foo.bar.data.menu.HeirarchyItem">
                <column name="parent_id" unique-key="label-parent"/>
                <column name="parent_site" unique-key="label-parent"/>
            </many-to-one>
           
            <joined-subclass name="com.foo.bar.data.menu.ActionItem" table="menu_actions">
               
                <key><column name="generated_id"/><column name="site"/></key>
               
                <many-to-one name="listing" outer-join="false" class="com.foo.bar.data.listing.Listing">
                    <column name="listing_id"/><column name="listing_site"/>
                </many-to-one>
               
            </joined-subclass> <!-- ActionItem -->
           
            <joined-subclass name="com.foo.bar.data.menu.HeirarchyItem" table="menu_heirarchy">
               
                <key><column name="generated_id"/><column name="site"/></key>
               
                <set name="children" lazy="true" inverse="true">
                    <key><column name="generated_id"/><column name="site"/></key>
                    <one-to-many class="com.foo.bar.data.menu.MenuItem"/>
                </set>
               
            </joined-subclass> <!-- HeirarchyItem -->
   
        </joined-subclass> <!-- MenuItem -->

        <!-- END MENU -->

    </class>
   
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2003 2:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Well, I dunno, this all seems to work perfectly for me. I can't do much else unless you submit a test to JIRA.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2003 3:07 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Yeah, I'm working on isolating it. Seems theres a few more interactions going on than I thought. It's working fine for me with stripped down versions of my mapped objects, so I'm adding back bells and whistles until it breaks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2003 4:23 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
OK, I found the problem. Seems this was caused by calling session.save() twice on one object. Even still I haven't been able to recreate the problem in isolation, away from my main code, so there still may be something going on under the surface. I'm tired of this problem, though, so I'm through with it. :P


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2003 11:01 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
Seems this was caused by calling session.save() twice on one object



In different sessions?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2003 11:09 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Nope. Same session. It might have also happened calling save() on two objects in the same cascade graph, but I'm not sure.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 11, 2003 11:16 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Calling save() a second time has no effect, so it can't be that.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 12, 2003 2:11 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Not so hasty there...I've isolated it. Want a JIRA?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 21 posts ]  Go to page 1, 2  Next

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.