我想避免序列化(在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?

java – Hibernate / JPA是否考虑了transiant修饰符(而不是注释)的更多相关文章

  1. Spring Data JPA系列JpaSpecificationExecutor用法详解

    这篇文章主要为大家介绍了Spring Data JPA系列JpaSpecificationExecutor用法详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

  2. Hibernate 主清单文件配制的详细介绍

    这篇文章主要介绍了Hibernate 主清单文件配制的详细介绍的相关资料,希望通过本文能帮助到大家,需要的朋友可以参考下

  3. Hibernate 查询方式总结

    get() and load() HQL 等查询方式

  4. jsp hibernate的分页代码第1/3页

    在查询分页代码中使用Hibernate的一大好处是,既兼顾了查询分页的性能,同时又保证了代码在不同的数据库之间的可移植性。

  5. Spring Boot 整合持久层之Spring Data JPA

    在介绍Spring Data JPA的时候,我们首先认识下Hibernate。Hibernate是数据访问解决技术的绝对霸主,使用O/R映射技术实现数据访问,O/R映射即将领域模型类和数据库的表进行映射,通过程序操作对象而实现表数据操作的能力,让数据访问操作无须关注数据库相关的技术

  6. 使用JPA插入枚举类型字段

    这篇文章主要介绍了使用JPA插入枚举类型字段,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

  7. 使用JPA单项一对多外键关联

    这篇文章主要介绍了使用JPA单项一对多外键关联,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

  8. JSP 开发之hibernate配置二级缓存的方法

    这篇文章主要介绍了JSP 开发之hibernate配置二级缓存的方法的相关资料,这里提供两种配置二级缓存的方法,需要的朋友可以参考下

  9. 使用spring jpa 如何给外键赋值

    这篇文章主要介绍了使用spring jpa 如何给外键赋值,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

  10. jsp hibernate 数据保存操作的原理

    当执行到session.save()方法时,Hibernate并不会马上生成insert SQL语句来进行数据的保存,而是当稍后清理session的缓存时才有可能执行insert SQL语句,那么session.save()方法到底会执行哪些步骤呢?

随机推荐

  1. 基于EJB技术的商务预订系统的开发

    用EJB结构开发的应用程序是可伸缩的、事务型的、多用户安全的。总的来说,EJB是一个组件事务监控的标准服务器端的组件模型。基于EJB技术的系统结构模型EJB结构是一个服务端组件结构,是一个层次性结构,其结构模型如图1所示。图2:商务预订系统的构架EntityBean是为了现实世界的对象建造的模型,这些对象通常是数据库的一些持久记录。

  2. Java利用POI实现导入导出Excel表格

    这篇文章主要为大家详细介绍了Java利用POI实现导入导出Excel表格,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

  3. Mybatis分页插件PageHelper手写实现示例

    这篇文章主要为大家介绍了Mybatis分页插件PageHelper手写实现示例,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

  4. (jsp/html)网页上嵌入播放器(常用播放器代码整理)

    网页上嵌入播放器,只要在HTML上添加以上代码就OK了,下面整理了一些常用的播放器代码,总有一款适合你,感兴趣的朋友可以参考下哈,希望对你有所帮助

  5. Java 阻塞队列BlockingQueue详解

    本文详细介绍了BlockingQueue家庭中的所有成员,包括他们各自的功能以及常见使用场景,通过实例代码介绍了Java 阻塞队列BlockingQueue的相关知识,需要的朋友可以参考下

  6. Java异常Exception详细讲解

    异常就是不正常,比如当我们身体出现了异常我们会根据身体情况选择喝开水、吃药、看病、等 异常处理方法。 java异常处理机制是我们java语言使用异常处理机制为程序提供了错误处理的能力,程序出现的错误,程序可以安全的退出,以保证程序正常的运行等

  7. Java Bean 作用域及它的几种类型介绍

    这篇文章主要介绍了Java Bean作用域及它的几种类型介绍,Spring框架作为一个管理Bean的IoC容器,那么Bean自然是Spring中的重要资源了,那Bean的作用域又是什么,接下来我们一起进入文章详细学习吧

  8. 面试突击之跨域问题的解决方案详解

    跨域问题本质是浏览器的一种保护机制,它的初衷是为了保证用户的安全,防止恶意网站窃取数据。那怎么解决这个问题呢?接下来我们一起来看

  9. Mybatis-Plus接口BaseMapper与Services使用详解

    这篇文章主要为大家介绍了Mybatis-Plus接口BaseMapper与Services使用详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪

  10. mybatis-plus雪花算法增强idworker的实现

    今天聊聊在mybatis-plus中引入分布式ID生成框架idworker,进一步增强实现生成分布式唯一ID,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

返回
顶部