0

나는 이것이 왜 최대 절전 모드 오류를 디버깅하는 데 어려움을 겪고 있는지 파악하려고 노력 중이고 타 고객의 타스크 하위 집합을 가질 고객 개체를 저장하려고 할 때 트리거 동작을 제한했습니다. 내가 다른에서 (부분 집합 수가 1보다 커야합니다) 일부를 가지고 tarifs의 세트로 고객을 유지하려고 할 때

**<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> 

트리거링 동작입니다 : 아래는 클래스와 HBM 매핑을 제거됩니다 고객의 tarif. 예를 들어 고객 1 3 # 4, 고객 # 2 6 # 7 아니라이 # 1 # 2 # 5 #을 tarif # 1 # 5 # tarifs를 가질 수 tarif # 1 # 2 # 갖는 6으로서 # 1 # 2# 1 # 2 # 3 # 4의 서브 세트입니다. 나는 이것이 현재 왜 있는지에 관해서 정말로 확신하지 못한다.왜 Hibernate NonUniqueObject 예외가 발생합니까?

**<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); 
      } 
     } 

Stack trace here

+0

예외 추적을 붙여 넣으십시오. – SiB

+0

addTarifToCustomer를 호출하기 전에 Customer 클래스의 인스턴스가 두 개 없으며 하나의 인스턴스가 분리 된 상태에 있습니까? NonUniqueException이 발생할 수 있습니다. ide 디버거를 사용하여 session.saveOrUpdate()로 line을 호출하기 전에 가지고있는 객체를 확인하십시오. –

답변

0

@Luckasz 나는 이미, 그것은이가 그것을 파악하기가 매우 어렵습니다 상속 프로젝트가 다른 인스턴스가로드되어 있지만 경우로이 같은 것을 스택 추적에서 알고 어디 결국 나는 DAO 레이어를 거치지 않고 액션 레이어 (컨트롤러)에서 객체를 유지/업데이트함으로써이 문제를 해결해야했습니다.
이 문제를 해결할 수 있도록 도와 준 irc 채널의 sebersole에게 많은 감사를드립니다.

+0

당신은 환영합니다 :) –

+0

예 상속 된 DAO 물건 꽤 엉망이었다. 실제로 DAO 클래스가 종종 O/RM * 작업을 더 어렵게 만드는 주요한 예입니다. –

관련 문제