legacy-knowledge-base
公開されました Sep. 10, 2025

Liferayサービスの使用時にStaleObjectStateExceptionがスローされる

written-by

Eric Yan

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

legacy-article

learn-legacy-article-disclaimer-text

問題

Liferay DXP 7.2 Service Pack 1またはFix Pack 2をインストールした後、カスタマイズでLiferayサービスを使用してデータを更新または変更すると、StaleObjectStateExceptionが生成されます。

  Caused by: org.hibernate.StaleObjectStateException: Row was updated or deleted
  by another transaction (or unsaved-value mapping was incorrect): [com.liferay.portal.model.impl.ContactImpl#8367818]
  at org.hibernate.event.def.DefaultMergeEventListener.entityIsDetached(DefaultMergeEventListener.java:485)
  at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:255)
  at org.hibernate.event.def.DefaultMergeEventListener.onMerge(DefaultMergeEventListener.java:84)
  at org.hibernate.impl.SessionImpl.fireMerge(SessionImpl.java:867) at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:851)
  at org.hibernate.impl.SessionImpl.merge(SessionImpl.java:855) at com.liferay.portal.dao.orm.hibernate.SessionImpl.merge(SessionImpl.java:241)
  ... 208 more

解決策

StaleObjectStateExceptionは通常、競合する変更が検出された場合など、古いデータが検出されたときにHibernateによってスローされます。

変更の競合を引き起こすコーディングパターンを使用したカスタマイズでは、StaleObjectStateExceptionが発生する場合があります。StaleObjectStateExceptionを回避するには、これらのコードサンプルを使用してカスタマイズを更新してください。

  1. LPS-86385 - StaleObjectStateException when trying to update a Contact
    1. https://github.com/liferay/liferay-portal/commit/e68ddf21b14b0f6ff20abe771b329232c55ada8f
  2. LPS-86695 - StaleObjectStateException when trying to update a Layout
    1. https://github.com/liferay/liferay-portal/commit/4812a795b36134042ce9fee8421b544e1ebd64d4

追加情報

Liferay DXP 7.2 Service Pack 1またはFix Pack 2の時点で、追加のLiferayサービスでMVCCが有効になりました。

LiferayのMVCC実装は、 Hibernateの楽観的ロックシステムに 依存しています。このメカニズムを使用すると、Hibernateが競合として識別する変更が明らかになります。

例として、LiferayのBlogsEntryServiceを使用してブログエントリを更新すると、StaleObjectStateException:BlogsEntryUtil#updateEntryが発生する場合があります。

以下は、MVCCが有効になっている追加のLiferayサービスのリストです。

MVCCが有効な追加のLiferayサービス

 

コンポーネント サービス

Account

AccountEntry
AccountEntryUserRel

Asset

AssetEntryUsage

Asset Auto Tagger

AssetAutoTaggerEntry

Asset Category Property

AssetCategoryProperty

Asset Display Page

AssetDisplayPageEntry

Asset Entry Rel

AssetEntryAssetCategoryRel

Asset List

AssetListEntry
AssetListEntryAssetEntryRel
AssetListEntrySegmentsEntryRel
AssetListEntryUsage

Blogs

BlogsEntry
BlogsStatsUser

Bookmarks

BookmarksEntry
BookmarksFolder

Calendar

Calendar
CalendarBooking
CalendarNotificationTemplate
CalendarResource

Document Library Content

DLContent

Dynamic Data Mapping

DDMContent
DDMDataProviderInstance
DDMDataProviderInstanceLink
DDMFormInstance
DDMFormInstanceRecord
DDMFormInstanceRecordVersion
DDMFormInstanceVersion
DDMStorageLink
DDMStructure
DDMStructureLayout
DDMStructureLink
DDMStructureVersion
DDMTemplate
DDMTemplateLink
DDMTemplateVersion

Fragment

FragmentCollection
FragmentEntry
FragmentEntryLink

Journal

JournalArticle
JournalArticleLocalization
JournalArticleResource
JournalContentSearch
JournalFeed
JournalFolder

Knowledge Base

KBArticle
KBComment
KBFolder
KBTemplate

Layout Page Template

LayoutPageTemplateCollection
LayoutPageTemplateEntry
LayoutPageTemplateStructure
LayoutPageTemplateStructureRel

Mobile Device Rules

MDRAction
MDRRule
MDRRuleGroup
MDRRuleGroupInstance

Segments

SegmentsEntry
SegmentsEntryRel
SegmentsExperience
SegmentsExperiment
SegmentsExperimentRel

Site

SiteFriendlyURL

Site Navigation

SiteNavigationMenu
SiteNavigationMenuItem

Trash

TrashEntry
TrashVersion

Wiki

WikiNode
WikiPage
WikiPageResource

did-this-article-resolve-your-issue

legacy-knowledge-base