-->
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: Subclass mapping vs. not null constraint?
PostPosted: Mon Feb 02, 2004 7:28 pm 
Expert
Expert

Joined: Thu Jan 08, 2004 6:17 pm
Posts: 278
I have a simple subclass mapping:
Code:
    <class name="com.nimblefish.core.data.Task">

        <id name="id" type="long" unsaved-value="null" >
            <generator class="native"/>
        </id>

        <discriminator/>

        <!-- some properties elided -->

        <subclass name="com.nimblefish.core.data.TaskImport"
            extends="com.nimblefish.core.data.Task"
            discriminator-value="IMP">

            <many-to-one name="sourceList" column="sourcelist_id" not-null="true"
                class="com.nimblefish.core.data.SourceList"/>

        </subclass>

    </class>

If I try to create an instance of Task, which *has* no sourceList property, I get:
Code:
    <error message="could not insert: [com.nimblefish.core.data.Task]" type="net.sf.hibernate.JDBCException">net.sf.hibernate.JDBCException: could not insert: [com.nimblefish.core.data.Task]
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:541)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:433)
   at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:876)
   at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:817)
   at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:737)
   at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:717)
   at com.nimblefish.core.test.persist.PersistenceManagerTest.testTask(PersistenceManagerTest.java:210)
...
Caused by: java.sql.SQLException: General error,  message from server: &quot;Cannot add or update a child row: a foreign key constraint fails&quot;

I assume this means that if you are using a table-per-class-hierarchy mapping, you can't have not-null subclass properties, since instances of other classes in the hierarchy *will* have null values for those properties? (Removing the not-null on the "sourceList" subclass property makes the problem stop happening.)

This is with Hibernate 2.1.1.

Thanks for any confirmation :-)
Cheers!
Rob


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 02, 2004 7:30 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Well if you use SchemaExport, you are right, I suppose.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 03, 2004 9:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
That's correct

_________________
Emmanuel


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.