我有一个类ShopOrder
,其中包含2个xml映射,只有不同的实体名称:
<class name="...ShopOrder" [...] entity-name="shopOrder">...
<class name="...ShopOrder" [...] entity-name="shopOrderArchival">...
我想要实现的是从包含entity-name = shopOrder
的类的表中读取对象并将其保存到另一个表(entity-name = shopOrderArchival
)。我的代码看起来像这样:
public void archive(long orderNumber, Model model) {
final ShopOrder order = shopOrderQueries.getShopOrderByOrderNumber(orderNumber);
shopOrderQueries.flushAndClearCurrentSession();
shopOrderRepository.save("shopOrderArchival", order);
}
可悲的是,我得到了例外Don't change the reference to a collection with delete-orphan enabled : shopOrder.collectionName
我怎样才能以正确的方式做到这一点?
完整堆栈跟踪:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.hibernate4.HibernateSystemException: Don't change the reference to a collection with delete-orphan enabled : shopOrder.orderedLimitedServiceAvailabilities; nested exception is org.hibernate.HibernateException: Don't change the reference to a collection with delete-orphan enabled : shopOrder.orderedLimitedServiceAvailabilities
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:948)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
xxx.terracotta.websessions.ReloadSessionsObjectsFilter.doFilterInternal(ReloadSessionsObjectsFilter.java:55)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
xxx.logic.orders.cart.RequestDataFilter.doFilterInternal(RequestDataFilter.java:40)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
xxx.util.RequestCacheControlFilter.doFilterInternal(RequestCacheControlFilter.java:44)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
xxx.logic.httpfilters.RequestPartnerModeFilter.doFilterInternal(RequestPartnerModeFilter.java:44)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
xxx.logic.wc.RequestWcSettingsFilter.doFilterInternal(RequestWcSettingsFilter.java:81)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
xxx.logic.configurations.RedirectToEmptyFilter.doFilterInternal(RedirectToEmptyFilter.java:56)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
xxx.httpfilters.SessionLog.doFilter(SessionLog.java:39)
org.webdroid.catnip.filter.BadInputFilter.doFilter(BadInputFilter.java:398)
org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186)
org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
xxx.logic.mobile.MobileVersionByDomainFilter.doFilterInternal(MobileVersionByDomainFilter.java:61)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
xxx.httpfilters.ThreadFriendlyNameFilter.doFilterInternal(ThreadFriendlyNameFilter.java:42)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
xxx.httpfilters.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:133)
Hbm映射(对于存档是相同的,只有更改在实体名称中)
<class name="xxx.orders.impl.ShopOrder" table="xxx" discriminator-value="S" entity-name="shopOrder">
<id name="id" column="id" type="long" unsaved-value="0">
<generator class="native"/>
</id>
<discriminator column="class" type="char"/>
<property name="operatorSource">
<column name="operator_source" sql-type="varchar"/>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">xxx.orders.OperatorSource</param>
<param name="type">12</param><!-- to jest java.sql.Types.VARCHAR -->
</type>
</property>
<property name="orderNumber" column="order_number" not-null="true"/>
<property name="dateCreate" column="date_create" not-null="true"/>
<property name="orderFinalizeDate" column="order_finalize_date"/>
<property name="from" column="customer_from"/>
<property name="partner"/>
<property name="invoiceNeeded" column="invoice_needed"/>
<property name="deliveryEqualsHome" column="delivery_equals_home"/>
<property name="peselNeeded" column="pesel_needed"/>
<property name="phone"/>
<property name="phoneType" column="phone_type"/>
<property name="smsNotify" column="sms_notify"/>
<property name="instalmentOnlySmallCaseSwitch" column="instalment_only_small_case_switch"/>
<property name="blockedForUserEdit" column="blocked_for_user_edit"/>
<property name="tdUrl" column="td_url"/>
<property name="tdSuccess" column="td_success" not-null="true"/>
<property name="canceledByUser" column="canceled_by_user"/>
<property name="pesel"/>
<property name="visitId" column="visit_id"/>
<property name="userId" column="user_id"/>
<property name="sygmaCreditMotionId" column="sygma_credit_motion_id"/>
<property name="sygmaCreditMotionUpdateAttempts" column="sygma_credit_motion_update_attempts"/>
<property name="statusCodesThatEmailNotificationWasSend" column="status_codes_that_email_notification_was_send" />
<property name="statusCodesThatSmsNotificationWasSend" column="status_codes_that_sms_notification_was_send" />
<property name="reserveAndCollectMode" column="reserve_and_collect_mode"/>
<property name="ePaymentTransactionId" column="e_payment_transaction_id"/>
<property name="historicalEPaymentTranactionIds" column="historical_e_payment_tranaction_ids"/>
<property name="lastUpdateDate" column="last_update_date"/>
<property name="ePaymentStatusChangeDate" column="e_payment_status_change_date"/>
<property name="warrantyRegulationsReaded" column="warranty_regulations_readed"/>
<property name="userInstalmentNumber" column="user_instalment_number"/>
<property name="paperInvoice" column="paper_invoice"/>
<property name="proforma" column="proforma"/>
<component name="abTestsVariables">
<property name="simpleOrderPath" column="simple_order_path"/>
<property name="gridDeliveryPricesIncludesItemsPayments" column="grid_delivery_prices_includes_items_payments" />
<property name="displayServiceCalculator" column="display_service_calculator" />
<property name="hideInstalmentOptions" column="hide_instalment_options"/>
</component>
<component name="aliorData" access="field">
<property name="status">
<column name="alior_status" sql-type="varchar"/>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">xxx.orders.impl.AliorStatus</param>
<param name="type">12</param>
</type>
</property>
<property name="applicationNumber" column="alior_application_number" />
<property name="instalmentCodeSequence" column="alior_instalment_code_sequence" />
<property name="creditApplicationStatusCode" column="alior_credit_application_status_code" />
<property name="confirmLoanAgreementSend" column="alior_confirm_loan_agreement_send" />
</component>
<component name="platnosciData" access="field">
<property name="status">
<column name="platnosci_status" sql-type="varchar"/>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">xxx.orders.impl.PlatnosciTransactionsStatus</param>
<param name="type">12</param>
</type>
</property>
<property name="amount" column="platnosci_amount" />
</component>
<property name="confirmationStatus">
<column name="confirmation_status" sql-type="varchar"/>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">xxx.orders.impl.ConfirmationStatus</param>
<param name="type">12</param><!-- to jest java.sql.Types.VARCHAR -->
</type>
</property>
<property name="sygmaCreditMotionStatus">
<column name="sygma_credit_motion_status" sql-type="varchar"/>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">xxx.orders.sygma.SygmaCreditMotionStatus</param>
<param name="type">12</param><!-- to jest java.sql.Types.VARCHAR -->
</type>
</property>
<property name="state" not-null="true">
<column name="state" sql-type="varchar"/>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">xxx.orders.impl.ShopOrderState</param>
<param name="type">12</param><!-- to jest java.sql.Types.VARCHAR -->
</type>
</property>
<property name="appVersion" not-null="true">
<column name="app_version" sql-type="varchar"/>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">xxx.app.AppVersion</param>
<param name="type">12</param><!-- to jest java.sql.Types.VARCHAR -->
</type>
</property>
<property name="sf1Status">
<column name="sf1_status" sql-type="varchar"/>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">xxx.orders.sf1.Sf1Status</param>
<param name="type">12</param><!-- to jest java.sql.Types.VARCHAR -->
</type>
</property>
<component name="insuranceData">
<property name="insuranceNumber" column="insurance_number"/>
<property name="insuranceDamageNumber" column="insurance_damage_number"/>
<property name="productReturnRequired" column="product_return_required"/>
<property name="additionalCharge" column="additional_charge"/>
<property name="insurerPayment" column="insurer_payment"/>
<property name="customerPayment" column="customer_payment"/>
<property name="insuranceType">
<column name="insurance_type" sql-type="varchar"/>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">xxx.orders.euro.InsuranceType</param>
<param name="type">12</param><!-- to jest java.sql.Types.VARCHAR -->
</type>
</property>
</component>
<component name="googleCookie">
<property name="utmcsr" not-null="true"/>
<property name="utmccn" not-null="true"/>
<property name="utmcmd" not-null="true"/>
<property name="utmcct" not-null="true"/>
<property name="utmctr" not-null="true"/>
<property name="utmgclid" not-null="true"/>
<property name="utmx" not-null="false"/>
<property name="utmxx" not-null="false"/>
<property name="cookieHeader" column="cookie_header" not-null="true"/>
</component>
<component name="transportData">
<parent name="shopOrder"/>
<property name="transportDate" column="transport_date"/>
<property name="actualDeliveryDate" column="actual_delivery_date"/>
<property name="transportInterval" column="transport_interval"/>
<property name="transportIntervalIndex" column="transport_interval_index"/>
<property name="additionalTransportPrice" column="additional_transport_price"/>
<property name="realTransportInterval" column="real_transport_interval" />
<property name="realTransportIntervalIndex" column="real_transport_interval_index" />
<property name="transportCode" column="transport_code" />
<property name="sellDocumentResponseCode" column="sell_document_response_code"/>
<property name="deliveryPaymentPriceType">
<column name="delivery_payment_price_type" sql-type="varchar"/>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">xxx.orders.impl.DeliveryPaymentPriceType</param>
<param name="type">12</param><!-- to jest java.sql.Types.VARCHAR -->
</type>
</property>
<property name="type">
<column name="transport_data_type" sql-type="varchar"/>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">xxx.orders.impl.TransportDataType</param>
<param name="type">12</param><!-- to jest java.sql.Types.VARCHAR -->
</type>
</property>
<many-to-one
name="instalmentOption"
column="transport_data_instalment_option_id"
not-null="false"
cascade="none"
foreign-key="b24_instalment_option_transport_data_fkey"
class="xxx.products.impl.InstalmentOption"
/>
</component>
<component name="actionData">
<property name="actionStateCode" column="action_state_code"/>
<property name="actionReservationId" column="action_reservation_id"/>
<property name="actionReservationLabel" column="action_reservation_label"/>
<property name="actionReservationMessage" column="action_reservation_message"/>
<property name="actionToRelease" column="action_to_release" not-null="true"/>
<property name="actionOrderId" column="action_order_id"/>
</component>
<component name="sf1Data">
<property name="checkCounter" column="check_counter" not-null="true"/>
<property name="uid" column="uid" not-null="true"/>
<property name="amount" column="sf1_amount" not-null="true"/>
</component>
<component name="abData">
<property name="abOrderId" column="ab_order_id"/>
<property name="abErrorCode" column="ab_error_code"/>
<property name="abErrorDescription" column="ab_error_description"/>
<property name="abStatusCode" column="ab_status_code"/>
<property name="abStatusDescription" column="ab_status_description"/>
<property name="abToRelease" column="ab_to_release" not-null="true"/>
<property name="abOrderState">
<column name="ab_order_state" sql-type="varchar"/>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">xxx.orders.impl.AbOrderState</param>
<param name="type">12</param>
</type>
</property>
</component>
<many-to-one access="field"
name="kredytLineData"
column="kredyt_line_data_id"
not-null="false"
cascade="all"
foreign-key="b24_shop_orders_kredyt_line_data_fk"
unique="true"
class="xxx.orders.impl.ShopOrderKredytLineData"
entity-name="shopOrderKredytLineData"
/>
<set name="orderedLimitedServiceAvailabilities" lazy="true" cascade="all-delete-orphan">
<key column="order_id" foreign-key="b24_order_to_li_se_av_fkey" not-null="true"/>
<one-to-many class="xxx.orders.impl.OrderedLimitedServiceAvailability" entity-name="orderedLimitedServiceAvailability"/>
</set>
<list name="orderItems" lazy="true" inverse="false" cascade="all-delete-orphan">
<key column="order_id" foreign-key="b24_order_to_item_fkey" not-null="true"/>
<list-index column="index" />
<one-to-many class="xxx.orders.impl.OrderItem" entity-name="orderItem"/>
</list>
<list name="orderedSuites" lazy="true" inverse="false" cascade="all-delete-orphan">
<key column="order_id" foreign-key="b24_ordered_suite_to_order_fkey" not-null="true"/>
<list-index column="index" />
<one-to-many class="xxx.orders.impl.OrderedSuite" entity-name="orderedSuite"/>
</list>
<list name="headDeliveryPayments" lazy="true" inverse="false" cascade="all-delete-orphan">
<key column="order_id" foreign-key="b24_order_to_delivery_payment_instance_fkey"/>
<list-index column="index" />
<one-to-many class="xxx.orders.impl.DeliveryPaymentInstance" entity-name="deliveryPaymentInstance"/>
</list>
<set name="smses" cascade="none" inverse="true">
<key column="shop_order_id" foreign-key="b24_sms_to_shop_order_fkey" not-null="false"/>
<one-to-many class="xxx.orders.impl.Sms"/>
</set>
<set name="euroOrders" cascade="none" inverse="true" order-by="time_stamp">
<key column="shop_order_id" foreign-key="b24_euro_order_to_shop_order_fkey" not-null="false"/>
<one-to-many class="xxx.orders.euro.EuroOrder" />
</set>
<many-to-one
name="ePaymentBank"
column="e_payment_bank_id"
not-null="false"
cascade="none"
foreign-key="b24_order_to_e_payment_bank_fkey"
class="xxx.banks.EPaymentBank"
/>
<many-to-one
name="frontUser"
class="xxx.customers.IFrontUser"
column="front_user_id"
cascade="none"
not-null="true"
unique="false"
foreign-key="b24_order_to_front_user_fkey"
/>
<many-to-one
name="orderInvoice"
class="xxx.orders.IOrderInvoice"
column="order_invoice_id"
cascade="all"
not-null="true"
unique="true"
foreign-key="b24_order_to_oinvoice_fkey"
entity-name="iOrderInvoice"
/>
<many-to-one
name="delivery"
class="xxx.orders.IDelivery"
column="delivery_id"
cascade="all"
not-null="true"
unique="true"
foreign-key="b24_order_to_delivery_fkey"
entity-name="iDelivery"
/>
<many-to-one
name="payment"
class="xxx.orders.IPayment"
column="payment_id"
cascade="all"
not-null="true"
unique="true"
foreign-key="b24_order_to_payment_fkey"
entity-name="iPayment"
/>
<many-to-one
name="operator"
class="xxx.users.IOperator"
column="operator_id"
cascade="none"
not-null="false"
unique="false"
foreign-key="b24_order_to_operator_fkey"
/>
<many-to-one
name="toDepository"
class="xxx.dictionaries.IDictionaryItem"
column="to_depository_id"
cascade="none"
not-null="false"
unique="false"
lazy="false"
foreign-key="b24_order_to_td_di_fkey"
/>
<many-to-one
name="holidayPromotionStatus"
class="xxx.products.impl.HolidayPromotionStatus"
column="holiday_promotion_status_id"
not-null="false"
unique="false"
foreign-key="b24_order_to_hps_fkey"
/>
<many-to-one
name="smsNotificationService"
class="xxx.orders.impl.OrderedService"
column="sms_notification_service_id"
cascade="all"
not-null="false"
unique="false"
foreign-key="b24_order_to_sms_service_fkey"
entity-name="orderedService"
/>
<many-to-one
name="instalmentOption"
column="instalment_option_id"
not-null="false"
cascade="none"
foreign-key="b24_instalment_option_shop_order_fkey"
class="xxx.products.impl.InstalmentOption"
/>
<many-to-one
name="userInstalmentOption"
column="user_instalment_option_id"
not-null="false"
cascade="none"
foreign-key="b24_user_instalment_option_shop_order_fkey"
class="xxx.products.impl.InstalmentOption"
/>
<many-to-one
name="synchronizedData"
class="xxx.orders.ShopOrderSynchronizedData"
column="shop_order_synchronized_data_id"
cascade="all"
not-null="true"
unique="true"
access="field"
foreign-key="b24_shop_order_to_euro_order_date_fkey"
entity-name="shopOrderSynchronizedData"
/>
<component name="voucherData">
<many-to-one
name="voucher"
class="xxx.vouchers.Voucher"
column="voucher_id"
cascade="none"
not-null="false"
foreign-key="b24_voucher_voucher_to_product_id_fkey"
/>
<many-to-one
name="alias"
class="xxx.vouchers.VoucherAlias"
column="voucher_alias_id"
cascade="none"
not-null="false"
foreign-key="b24_order_to_voucher_alias_id_fkey"
/>
<property name="discountValueSplit" column="voucher_data_discount_value_split"/>
<property name="usageUpdated" column="voucher_data_usage_updated"/>
<property name="deliveryPaymentDiscountType" not-null="true">
<column name="voucher_delivery_payment_discount_type" sql-type="varchar"/>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">xxx.vouchers.VoucherDeliveryPaymentDiscountType</param>
<param name="type">12</param><!-- to jest java.sql.Types.VARCHAR -->
</type>
</property>
</component>
<component name="consolidateData" access="field" >
<many-to-one
name="order"
class="xxx.orders.impl.ShopOrder"
column="consolidate_data_order_id"
cascade="all"
not-null="false"
foreign-key="b24_consolidate_order_id_fkey"
entity-name="shopOrder"
/>
</component>
<property name="IPAddress" column="ip_address"/>
<property name="ecardStatus">
<column name="ecard_status" sql-type="varchar"/>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">xxx.orders.impl.ECardStatus</param>
<param name="type">12</param><!-- to jest java.sql.Types.VARCHAR -->
</type>
</property>
<property name="ePaymentToErpStatus">
<column name="e_payment_to_erp_status" sql-type="varchar"/>
<type name="org.hibernate.type.EnumType">
<param name="enumClass">xxx.orders.impl.EPaymentToErpStatus</param>
<param name="type">12</param><!-- to jest java.sql.Types.VARCHAR -->
</type>
</property>
<many-to-one
name="partnerClient"
class="xxx.orders.impl.PartnerClient"
column="partner_client_id"
cascade="all"
not-null="false"
unique="false"
foreign-key="b24_partner_client_id_fkey"
/>
<many-to-one
name="euroPartner"
class="xxx.users.impl.Partner"
column="euro_partner_id"
cascade="none"
not-null="false"
unique="false"
foreign-key="b24_partner_id_fkey"
/>
<many-to-one
name="partnerOperator"
class="xxx.users.IOperator"
column="partner_operator_id"
cascade="none"
not-null="false"
unique="false"
foreign-key="b24_partner_operator_id_fkey"
/>
<one-to-one
name="consoleData"
access="field"
class="xxx.orders.impl.ShopOrderConsoleData"
cascade="save-update, delete"
lazy="false"
entity-name="shopOrderConsoleData"
/>
<one-to-one
name="status"
access="field"
class="xxx.orders.impl.ShopOrderStatus"
cascade="save-update, delete"
lazy="false"
entity-name="shopOrderStatus"
/>
</class>
答案 0 :(得分:0)
在我看来,像你一样,用另一个替换了Collection的整个引用。但如果&#34; shopOrderArchival&#34;如果不为null,则应清除集合并添加所有新元素。
看看这个:Click