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