-->
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.  [ 12 posts ] 
Author Message
 Post subject: replicate() with joined-subclass
PostPosted: Mon Jan 05, 2004 4:46 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
I'm trying to call Session.replicate() with persistent objects mapped with joined-subclass and I'm getting a JDBCException.

Code:
net.sf.hibernate.JDBCException: could not retrieve version: [com.foo.bar.data.synch.Synch#com.foo.bar.data.sites.CompositeSiteID@1d97d0d[sequenceId=965,site=com.bpsphone.mpression.data.sites.Site@39d811[id=3]]]
        at net.sf.hibernate.persister.AbstractEntityPersister.getCurrentVersion(AbstractEntityPersister.java:1141)
        at net.sf.hibernate.impl.SessionImpl.replicate(SessionImpl.java:3698)
        at....


Here's the offending SQL:

Code:
select version from synch.synch where sequence_id =? and site =?


Here's the mapping:

Code:
<hibernate-mapping default-cascade="all">
   
    <class name="com.foo.bar.data.base.SiteDataObject" schema="base" table="site_data_objects">

        <composite-id name="id" class="com.foo.bar.data.sites.CompositeSiteID" unsaved-value="any">
            <key-property name="sequenceId" type="java.lang.Long" column="sequence_id"/>
            <key-many-to-one name="site" class="com.foo.bar.data.sites.Site" column="site"/>
        </composite-id>

        <version name="version" type="timestamp" unsaved-value="null"/>

        <joined-subclass name="com.foo.bar.data.synch.Synch" schema="synch" table="synch">
       
            <key><column name="sequence_id"/><column name="site"/></key>
           
        </joined-subclass> <!-- Synch -->

    </class> <!-- SiteDataObject -->

</hibernate-mapping>


The problem is that the column "version" does not exist in the synch table, it exists in the table of Synch's parent object, SiteDataObject. Hibernate isn't joining in the version column from the base.site_data_objects table like it normally would.

In the case of joined-subclasses, can the "version" attribute be in the superclass, or must it be defined in the subclasses? If so, what about multiple level object heirarchies? Also, I've had problems with every persistent object mapped with joined-subclass, not just Synch.

I'm replicating another object that's mapped with a regular <class> mapping. No problems there. I have no classes mapped with <subclass> though, so I haven't tested that.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 2:50 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Ooops. A bug. (And very easy to fix.)

Please submit to JIRA.

TIA


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 1:04 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Cool.

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 06, 2004 2:56 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
JIRA: http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-609


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 07, 2004 10:59 am 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Hi...

Don't mean to be insistent, but if it's an easy fix...can you provide a patch? :) I'm under a bit of a time crunch here...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 7:07 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
I just got around to testing this, and there's a bit of a glitch.

I begin a transaction, call replicate() on an array of objects one at a time, then commit the transaction.

The replicate() calls are executing, (although it turns out that no objects are being persisted to the DB) and afterwards when I flush the session before closing I'm getting a NullPointerException:

Code:
java.lang.NullPointerException
        at net.sf.hibernate.collection.List.entries(List.java:322)
        at net.sf.hibernate.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:526)
        at net.sf.hibernate.impl.ScheduledCollectionRecreate.execute(ScheduledCollectionRecreate.java:23)
        at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2327)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2284)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2181)
        .....


Oddly enough, I flush the session right before committing the transaction and everything's fine.

I have no idea which object is causing the exception. I'm running the latest CVS snapshot. (2004/01/13) Any clues?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 13, 2004 9:01 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Two more things:

I removed all explicit calls to flush, and it's still happening when the transaction calls flush() on commit.

Code:
java.lang.NullPointerException
        at net.sf.hibernate.collection.List.entries(List.java:322)
        at net.sf.hibernate.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:526)
        at net.sf.hibernate.impl.ScheduledCollectionRecreate.execute(ScheduledCollectionRecreate.java:23)
        at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2327)
        at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2284)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2181)
        at net.sf.hibernate.transaction.JTATransaction.commit(JTATransaction.java:52)
        .....


Also, this is again only happening when I'm replicating the POs mapped with joined-subclass. That may be a coincidence, though. The concrete objects contain no lists. (or collections of any type)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 1:45 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Please submit a test case to Jira.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 4:23 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
OK, I had some possible ambiguities with transactions (which I'll ask about in another post or thread) but I've cleared them up and the problem still persists.

You should be able to replicate this problem by modifying the code I previously submitted to JIRA (HB-609) to add a list to the SiteDataSubclass. (I haven't tested this yet.) I'm starting on the new JIRA submission now.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 4:55 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
I'm getting a second, similar exception now with another mapped object that contains a list. The only difference between the two list mappings seems to be that the first one has a normal key and this new one has a composite key.

Here's the exception:
Code:
java.lang.NullPointerException
        at net.sf.hibernate.collection.List.snapshot(List.java:32)
        at net.sf.hibernate.collection.PersistentCollection.getSnapshot(PersistentCollection.java:322)
        at net.sf.hibernate.impl.SessionImpl$CollectionEntry.postFlush(SessionImpl.java:371)
        at net.sf.hibernate.impl.SessionImpl.postFlush(SessionImpl.java:2745)
        at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2182)
        at net.sf.hibernate.transaction.JTATransaction.commit(JTATransaction.java:52)
        ....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 8:18 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Here's a preview of the JIRA issue. I'm getting yet another list related exception, this time from the JDBC driver. I can make it stop, though, and I have a mapping question as a result.

Here's the mapping:

Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
   "-//Hibernate/Hibernate Mapping DTD//EN"
   "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping default-cascade="save-update">
   
    <class name="com.foo.bar.data.base.DataObject" schema="base" table="data_objects">
       
        <id name="id" type="long">
            <generator class="native"/>
        </id>
       
        <version name="version" type="timestamp" unsaved-value="null"/>

        <joined-subclass name="com.foo.bar.data.base.DataSubclass" schema="base" table="data_subclasses">
       
            <key><column name="id"/></key>
           
            <property name="name" type="string" not-null="true" unique="true">
                <meta attribute="use-in-tostring">true</meta>
            </property>
           
            <list name="items" lazy="false" inverse="false">
                <key column="parent"/>
                <index column="collection_order"/>
                <one-to-many class="com.foo.bar.data.base.CollectionData"/>
            </list>
                   
        </joined-subclass> <!-- DataSubclass -->
       
        <joined-subclass name="com.foo.bar.data.base.CollectionData" schema="base" table="collection_data">
       
            <key><column name="id"/></key>
       
            <property name="collectionOrder" type="integer" column="collection_order" not-null="true" unique="false">
                <meta attribute="use-in-tostring">true</meta>
            </property>
           
            <many-to-one name="parent" class="com.foo.bar.data.base.DataSubclass">
                <meta attribute="use-in-tostring">true</meta>
            </many-to-one>
           
            <property name="data" type="string" not-null="false" unique="false">
                <meta attribute="use-in-tostring">true</meta>
            </property>
           
        </joined-subclass> <!-- ListData -->
       
    </class> <!-- DataObject -->

</hibernate-mapping>


When I try to replicate DataSubclass objects with a list of CollectionData objects I get the following exception:
Code:
[java] 17:14:43,882 DEBUG BatcherImpl:203 - done closing: 0 open PreparedStatements, 0 open ResultSets
     [java] 17:14:43,883 DEBUG BatcherImpl:261 - closing statement
     [java] 17:14:43,897 DEBUG JDBCExceptionReporter:36 - SQL Exception
     [java] org.postgresql.util.PSQLException: ERROR: null value in column "collection_order" violates not-null constraint

     [java]     at org.postgresql.util.PSQLException.parseServerError(PSQLException.java:139)
     [java]     at org.postgresql.core.QueryExecutor.executeV3(QueryExecutor.java:154)
     [java]     at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:101)
     [java]     at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:43)
     [java]     at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:515)
     [java]     at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:50)
     [java]     at org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:271)
     [java]     at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
     [java]     at net.sf.hibernate.collection.AbstractCollectionPersister.remove(AbstractCollectionPersister.java:500)
     [java]     at net.sf.hibernate.impl.ScheduledCollectionRemove.execute(ScheduledCollectionRemove.java:22)
     [java]     at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2327)
     [java]     at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2282)
     [java]     at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2181)
     [java]     at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
     [java]     at com.foo.bar.test.Test.main(Test.java:47)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     [java]     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
     [java]     at java.lang.reflect.Method.invoke(Method.java:324)
     [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:208)
     [java]     at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:150)
     [java]     at org.apache.tools.ant.taskdefs.Java.run(Java.java:443)
     [java]     at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:163)
     [java]     at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108)
     [java]     at org.apache.tools.ant.Task.perform(Task.java:341)
     [java]     at org.apache.tools.ant.Target.execute(Target.java:309)
     [java]     at org.apache.tools.ant.Target.performTasks(Target.java:336)
     [java]     at org.apache.tools.ant.Project.executeTarget(Project.java:1339)
     [java]     at org.apache.tools.ant.Project.executeTargets(Project.java:1255)
     [java]     at org.apache.tools.ant.Main.runBuild(Main.java:609)
     [java]     at org.apache.tools.ant.Main.start(Main.java:196)
     [java]     at org.apache.tools.ant.Main.main(Main.java:235)


My question is about the collectionOrder property in CollectionData. If I either set not-null="false" or eliminate the property entirely the exception goes away. (The replicated object has the proper data, as well.) I can create objects with the non-null property in the source database just fine. The problem happens when I replicate to the destination db.

Is it non-standard or odd to explicitly define the index property in list objects? Is it bad-evil-bad? :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2004 8:32 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Sorry, I forgot to add that setting not-null="false" in the list index properties did not get rid of the NullPointerException problems. :( So far I've only encountered that JDBC Exception while preparing the JIRA submission.


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