java – Hibernate / JPA是否考虑了transiant修饰符(而不是注释)

前端之家收集整理的这篇文章主要介绍了java – Hibernate / JPA是否考虑了transiant修饰符(而不是注释)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我想避免序列化(在JMS / AMF中),但仍然使用JPA / Hibernate保持字段.

瞬态修饰符是我的朋友吗? @Transient注释和瞬态修饰符是否相关?

java规范精确地指出,瞬态字段不会被系统服务保存到持久存储中.但是hibernate是一个系统服务吗? (我不这么认为)
http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#78119

并且java.io.Serialisable接缝指示调用out.writeObject和in.readObject进行序列化
http://download.oracle.com/javase/1.4.2/docs/api/java/io/Serializable.html

任何见解?

也许我应该写一个快速测试,但我会对一个规范更有信心.

谢谢 !

解决方法

Is the transient modifier my friend ? Are @Transient annotation and the transient modifier related or not a all ?

他们并没有真正相关,但我担心他们不会成为你的朋友,Hibernate / JPA不会保留瞬态属性. JPA规范如下:

2.1.1 Persistent Fields and Properties

The persistent state of an entity is
accessed by the persistence provider
runtime either via JavaBeans style
property accessors or via instance
variables. A single access type (field
or property access) applies to an
entity hierarchy. When annotations are
used,the placement of the mapping
annotations on either the persistent
fields or persistent properties of the
entity class specifies the access type
as being either field – or property –
based access respectively.

  • If the entity has field-based access,the persistence provider
    runtime accesses instance variables
    directly. All non-transient
    instance variables that are not
    annotated with the Transient

    annotation are persistent. When
    field-based access is used,the
    object/relational mapping annotations
    for the entity class annotate the
    instance variables.
  • If the entity has property-based access,the persistence provider
    runtime accesses persistent state via
    the property accessor methods. All
    properties not annotated with the
    Transient annotation are persistent.
    The property accessor methods must be
    public or protected. When
    property-based access is used,the
    object/relational mapping annotations
    for the entity class annotate the
    getter property accessors.
  • Mapping annotations cannot be applied to fields or properties that
    are transient or Transient
    .
  • The behavior is unspecified if mapping annotations are applied to
    both persistent fields and properties
    or if the XML descriptor specifies use
    of different access types within a
    class hierarchy.

参考

> JPA 1.0规范

>第2.1.1节持久字段

> Hibernate核心参考指南

> 2.2.2. Mapping simple properties

相关问题

> Why does JPA have a @Transient annotation?

原文链接:https://www.f2er.com/java/120597.html

猜你在找的Java相关文章