나는 이것이 왜 최대 절전 모드 오류를 디버깅하는 데 어려움을 겪고 있는지 파악하려고 노력 중이고 타 고객의 타스크 하위 집합을 가질 고객 개체를 저장하려고 할 때 트리거 동작을 제한했습니다. 내가 다른에서 (부분 집합 수가 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);
}
}
예외 추적을 붙여 넣으십시오. – SiB
addTarifToCustomer를 호출하기 전에 Customer 클래스의 인스턴스가 두 개 없으며 하나의 인스턴스가 분리 된 상태에 있습니까? NonUniqueException이 발생할 수 있습니다. ide 디버거를 사용하여 session.saveOrUpdate()로 line을 호출하기 전에 가지고있는 객체를 확인하십시오. –