1

我有一个项目,其中包含一组列,其中包含一组包含一组 TaskAssigness 的任务。

我正在尝试更新列标题而无需加载其任务集,但出现以下错误:

[AssertionFailure] - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
    org.hibernate.AssertionFailure: collection [com.example.tasks.Task.taskAssignees] was not processed by flush() 

我有以下 hbm.xml :

项目.hbm.xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "classpath://org/hibernate/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="com.exemple.tasks.project.Project" table="P_TASKS_PROJECT">
    <cache usage="read-write" />
    <id name="rowId" column="rowId">
      <generator class="native"/>
    </id>
    ...
    <set name="columns" table="P_TASK_PROJECT_COLUMN" inverse="true" cascade="all" sort="com.exemple.tasks.project.ColumnIndexComparator">
      <cache usage="read-write" />
      <key column="projectId" not-null="true" />
      <one-to-many class="com.exemple.tasks.project.Column" />
    </set>

  </class>
</hibernate-mapping>

列.hbm.xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "classpath://org/hibernate/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="com.example.tasks.project.Column" table="P_TASK_PROJECT_COLUMN">
    <cache usage="read-write" />
    <id name="rowId" column="rowId">
      <generator class="native"/>
    </id>
    ...
    <property name="title" />
    <many-to-one name="project" class="com.example.tasks.project.Project">
      <column name="projectId" not-null="false" />
    </many-to-one>

    <set name="tasks" table="P_TASKS_JOIN_COLUMNS">
      <cache usage="read-write" />
      <key column="columnId" not-null="true" />
      <many-to-many column="taskId" class="com.example.tasks.Task" unique="false" />
    </set>
  </class>
</hibernate-mapping>

任务.hbm.xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "classpath://org/hibernate/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="com.example.tasks.Task" table="P_TASK">
    <cache usage="read-write" />
    <id name="rowId" column="rowId">
      <generator class="native"/>
    </id>
    ...
    <set name="taskAssignees" table="P_TASK_ASSIGNEE" cascade="all-delete-orphan">
      <cache usage="read-write" />
      <key column="taskId" not-null="true" />
      <one-to-many class="com.example.tasks.TaskAssignee" />
    </set>

  </class>
</hibernate-mapping>

TaskAsignee.hbm.xml:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
        "classpath://org/hibernate/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="com.example.tasks.TaskAssignee" table="P_TASK_ASSIGNEE">
    <cache usage="read-write" />
    <id name="rowId" column="rowId">
      <generator class="native"/>
    </id>
    ...
    <many-to-one name="task" class="com.example.tasks.Task" insert="false" update="false">
      <column name="taskId" not-null="true" />
    </many-to-one>

  </class>
</hibernate-mapping>

我正在尝试以这种方式更新列的标题:

//Updating column title
Column column = project.getColumn(index); // return a column from the project. Project contains a SortedSet of Column
column.setTitle("NewTitle");
session.saveOrUpdate(project);

如果该列不包含任何任务,这可以正常工作。如果我尝试更新包含任务的列,则会收到以下错误消息:

[AssertionFailure] - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: collection [com.example.tasks.Task.taskAssignees] was not processed by flush() 

如果我在更新项目之前获得任务和任务分配,我没有错误:

Set<Task> tasks = col.getTasks();
  if (tasks != null) {
    for (Task task : tasks) {
      task.getTaskAssignees();
     }
   }
session.saveOrUpdate(project);

有没有办法更改我的列标题,然后更新项目而无需获取任务和任务分配者?我可以告诉休眠只是更新列而不是尝试更进一步。

4

0 回答 0