Java Reference
In-Depth Information
<class name="Order"
table="PLACED_ORDER"
detachable="true"
identity-type="application">
<version strategy="version-number" column="VERSION"/>
…
</class>
The
detachable="true"
attribute specifies that instances of the
Order
class can be
detached. The
<version>
element specifies that the
Order
class should maintain the
version number in the
VERSION
column. As described in chapter 5, you can use other
optimistic locking strategies such as
strategy="timestamp"
, which uses a time-
stamp. At the time of this writing, some
JDO
implementations did not support the
JDO 2.0
metadata and required vendor-specific extensions to be used.
Hibernate configuration
In the Hibernate
ORM
metadata, we just need to configure optimistic locking
because Hibernate objects are automatically detached:
<hibernate-mapping>
<class
name="Order"
table="PLACED_ORDER">
bb
<version property="version" column="VERSION" />
…
</hibernate-mapping>
The
<version>
element specifies that the
Order
class uses the
version
field for
optimistic locking and maps it to the
VERSION
column of the
PLACED_ORDER
table. As we saw in chapter 6, you can also use other optimistic locking strategies
such as the
<timestamp>
element to specify a timestamp column.
Now that you know how to configure the
O/R
mapping, we'll show you how to
detach and attach objects.
13.4.3
Detaching and attaching orders
The
AcknowledgeOrderServiceImpl
uses the
OrderAttachmentManager
to detach
and attach orders. This interface, which encapsulates the persistence framework-
specific detached objects
API
s, defines a
detach()
method, which detaches the
order, and an
attach()
method, which attaches an order:
public interface OrderAttachmentManager {
Order detach(Order order);
Search WWH ::
Custom Search