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.  [ 1 post ] 
Author Message
 Post subject: Changing the order of items in an indexed list.
PostPosted: Tue Jun 06, 2006 4:11 am 
Beginner
Beginner

Joined: Fri May 12, 2006 9:58 am
Posts: 32
Hibernate version:
3.1.3

Mapping documents:
Code:
        <list name="subProjects" batch-size="150">
            <key column="project_id"/>
            <list-index column="ordr"/>
            <one-to-many class="foo.SubProject"/>
        </list>



Code between sessionFactory.openSession() and session.close():
Code:
        List subProjects = project.getSubProjects();

        subProjects.add(0, subProjects.remove(1));


Full stack trace of any exception that occurs:
SEVERE: Cannot insert the value NULL into column 'ordr', table 'foo.dbo.subprojects'; column does not allow nulls. UPDATE fails.

Name and version of the database you are using:
SQL Server 2000

The generated SQL (show_sql=true):
Hibernate:
Code:
/* update foo.Project */
   update
            projects
        set
            version=?,
            title=?,
            creator=?
        where
            id=?
            and version=?
Hibernate:
    /* delete one-to-many row foo.Project.subProjects */
   update
            subprojects
        set
            project_id=null,
            ordr=null
        where
            project_id=?
            and id=?
Hibernate:
    /* create one-to-many row foo.Project.subProjects */
   update
        subprojects
    set
        project_id=?,
        ordr=?
    where
        id=?



Hello

I have a Project class which has a List of SubProjects. I want to rearrange items in this indexed list. I get this list of SubProjects and I do:
subProjects.add(0, subProjects.remove(1));
which works but requires that fields 'ordr' (my <list-index>) and 'project_id' (the reference back to the Project) should allow nulls.

Why is this the case? Can't hibernate just update the ordr fields without deleting first?

I also tried updating those fields manually with a query, but then I need the order field as a property of my object SubProject, which I dont want to expose in my object model.

Any thoughts? Is there another way to changing the order of items in indexed-lists?

thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.