0

我试图弄清楚为什么我很难调试休眠错误,并且我已将触发行为缩小到当我尝试保存将在另一个客户中具有一个 taris 子集的客户对象时。以下是精简的类和 hbm 映射:

**<POJOs>**

public class Tarif {
  private Long idTarifRailingLTD;
  private String name;
  private Set<Customer> customers=new HashSet<Customer>();
}

public class Customer extends Society {
    private Company company;
    private boolean actif;
    private String tvaNumber;
    private Set<Tarif> tarifRailings = new HashSet<Tarif>();
}


**<HBMs>**    
  
<class name="comp.model.accounting.Tarif" table="Tarif" lazy="false">
    <id name="idTarif" type="long">
        <generator class="native"/>
    </id>
        
    <property name="name" length="50" not-null="true"/>
        
    <set name="customers"  table="customer_tarifrailing" inverse="true" lazy="false" fetch="select" cascade="all">
        <key column="idTarif"/>
        <many-to-many class="comp.model.customer.Customer" column="idCustomer"/>
    </set>
        
</class>

<joined-subclass name="comp.model.customer.Customer" table="customer" lazy="false">
    <key column="idSociety"/>
    <property name="actif" type="boolean"/>
    <property name="tvaNumber" length="80"/>
                
    <many-to-one name="company" class="comp.model.company.Company" column="idCompany" 
                             not-null="true"/>  
                
    <set name="tarifRailings"  table="customer_tarif" inverse="false" lazy="false" fetch="select" cascade="all">
        <key column="idCustomer"/>
        <many-to-many class="comp.model.accounting.Tarif" column="idTarif"/>
    </set>
                
</joined-subclass>

触发行为是,当我尝试使用一组费率来坚持客户时,该客户在另一个客户的费率中具有子集(子集的数量必须大于 1)。例如客户 1tarif #1 #2 #3 #4客户 #2可以有 tarifs #1 #5 #6 #7,但不是 tarif #1 #2 #5 #6因为#1 #2#1 #2 #3 #4。我现在不确定为什么会这样。

    **<The Function>**
    public static void addTarifToCustomer(Customer customer, Tarif tarif) throws UserServiceException, Exception {
    
                // Begin unit of work
            Session session = HibernateUtil.getSessionFactory().getCurrentSession();
                session.beginTransaction();
                    
                customer.addTarifRailing(tarifRailing);
                    session.saveOrUpdate(customer);
                entKeys = session.getStatistics().getEntityKeys();
                // End unit of work
                session.getTransaction().commit();
                
            } catch (ObjectNotFoundException ex) {
                HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().rollback();
                throw new NotFoundDAOException("L'object d'identifiant " + customer.getIdSociety()
                        + " n'existe pas dans la base", ex);
            } catch (ConstraintViolationException ex) {
                HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().rollback();
                throw new AlreadyExistDAOException("Nouvel identifiant déja existant en base", ex);
            } catch (Exception ex) {
                ex.printStackTrace();
                HibernateUtil.getSessionFactory().getCurrentSession().getTransaction().rollback();
                throw new Exception(ex);
            }
        }

堆栈跟踪在这里

4

1 回答 1

0

@Luckasz我已经从堆栈跟踪中知道它是这样的,但是由于这是一个继承的项目,因此很难确定是否加载了另一个实例以及最终我不得不通过持久化/更新来解决这个问题动作层(控制器)中的对象,而不是通过 DAO 层。
非常感谢 irc 频道的 sebersole 帮助我找到解决方法。

于 2012-09-02T13:01:53.373 回答