我們有一個基於Hibernate的(33)Web應用程序,並且正在查找與交換由唯一索引限制的數據值對有關的問題。在我們flightticket HBM我們如何互換由唯一索引限制的值對
<many-to-one name="participants" class="net.umbrella.entity.ParticipantModel" fetch="select">
<column name="PARTICIPANTID" not-null="false" />
</many-to-one>
<many-to-one name="flights" class="net.umbrella.entity.FlightModel" fetch="select">
<column name="FLIGHTID" not-null="true" />
</many-to-one>
它在功能上可能採取與分配給參與者P1加票乙分配給參與者P2票據的數據對和交換兩個參與者。門票A最終分配給參與者P2,門票B將分配給參與者P1。但是,FLIGHTID + PARTICIPANTID有一個獨特的約束。
當Hibernate發出的第一次更新來改變參與者P1至P2的票,一個GenericJDBCException拋出
Attempt to insert duplicate key row in object 'FLIGHTTICKET' with unique index 'IDX_FLIGHTTICKET_UQ'
有沒有人有這樣一個共同的解決方案?
感謝 西蒙
你使用什麼數據庫? – a1ex07