`
wangzl2222
  • 浏览: 150967 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

Embedded Objects

    博客分类:
  • EJB
阅读更多

@Embedded Objects

Java 持久化规范允许你插入非实体的Java对象在实体组件中并且映射的嵌入对象属性值到实本表中的栏位.这些对象没有任何标识并且被包含的实体组件类所专有.@EmbeddedId主键的规则非常的简单如同前面的例子.我们首先定义一个内部对象:

package com.titan.domain;

 

import javax.persistence.*;

 

@Embeddable

public class Address implements java.io.Serializable {

   private String street;

   private String city;

   private String state;

 

   public String getStreet( ) { return street; }

   public void setStreet(String street) { this.street = street; }

 

   public String getCity( ) { return city; }

   public void setCity(String city) { this.city = city; }

 

   public String getState( ) { return state; }

   public void setState(String state) { this.state = state; }

}

内部的Address类有@Column映射定义在里面.其次,使用@javax.persistence.Embedded注释在Customer组件类内的嵌入实例Address,类:

package javax.persistence;

 

public @interface Embedded {}

同样的@EmbeddedId,@Embedded注释能够被联合同@AttributeOverrides注释一同使用如果你想覆盖指定嵌入类的信息.下面的例子显示如果覆盖.如果你不想覆.省去@AttributeOverrides注释.

package com.titan.domain;

 

import javax.persistence.*;

 

@Entity

@Table(name="CUSTOMER_TABLE")

 

public class Customer implements java.io.Serializable {

   private long id;

   private String firstName;

   private String lastName;

   private Address address;

 

...

@Embedded

   @AttributeOverrides({

      @AttributeOverride

(name="street",

column=@Column(name="CUST_STREET")),

      @AttributeOverride(name="city", column=@Column(name="CUST_CITY")),

      @AttributeOverride(name="state", column=@Column(name="CUST_STATE"))

   })

   public Address getAddress( ) {

      return address;

   }

...

}

在本例中,我们映射Address类属性到Customer_table表中的栏位.如果你不想指定@Embedded注释和Address类是序列化的,那么持久化提供者假定它是@Lob类型与序列化的字节流到Customer_table 表中的栏位.

看一下XML映射文件:

<entity-mappings>

<embeddable class="com.titan.domain.Address" access-type="PROPERTY"/>

   <entity class="com.titan.domain.Customer" access="PROPERTY">

      <attributes>

         <id name="id"/>

         <embedded name="address">

         <attribute-override name="street">

               <column name="CUST_STREET"/>

            </attribute-override>

            <attribute-override name="city">

               <column name="CUST_CITY"/>

            </attribute-override>

            <attribute-override name="state">

               <column name="CUST_STATE"/>

            </attribute-override>

         </embedded>

      </attributes>

   </entity>

</entity-mappings>

这个看起来非常准确的<embedded-id>映射,除了映射一个指定的属性使用<embedded>元素,其它的都相同.

 

简而言之,都是关于基本的属性映射.在下一章中,我们将讨论怎样映射复杂的关在多个实体组件之间.

 

from:http://hi.baidu.com/vsandjava/blog/item/9e6da7ecd0dc1d3d2797916d.html

分享到:
评论

相关推荐

    JavaScript 圣经第5版-Javascript编程宝典--黄金版 .rar

    Chapter 32: Embedded Objects. Chapter 33: XML Objects. Part IV: JavaScript Core Language Reference. Chapter 34: The String Object. Chapter 35: The Math, Number, and Boolean Objects. Chapter 36: ...

    protel99e PCB文件格式

    - **Embedded Objects**:可能包括特殊类型的嵌入式对象。 - **Arc Objects**:表示弧线或圆角的对象。 - **Pad Objects**:定义了焊盘的位置和尺寸。 - **Via Objects**:描述了通孔的信息。 - **Track Objects**:...

    ppt压缩*(PPTminimizer)

    convert such embedded objects to just simple pictures. In most cases, the conversion process can reduce the size of your presentation significantly. - CHANGED: Speed improvement by up to 500%. ...

    VC-12.rar_VC OLE_ole

    1. **嵌入对象(Embedded Objects)**:在文档中可以直接嵌入另一个应用程序的对象,如Excel表格嵌入到Word文档中,编辑时会调用原应用程序进行处理。 2. **链接对象(Linked Objects)**:与嵌入不同,链接对象仅...

    PPT 2010 播放软件 (PPT兼容包) PowerPoint Viewer 2010

    •Running macros, programs, or opening linked or embedded objects. System requirements Supported Operating Systems: Windows 7, Windows Server 2003 R2 (32-Bit x86), Windows Server 2003 R2 x64 ...

    Web Caching and Replication

    Hyperlinks and Embedded Objects Section 4.6. Summary Chapter 5. HTTP Support for Caching and Replication Section 5.1. Conditional Requests Section 5.2. Age and Expiration of Cached Objects ...

    jpa2.0jar包

    7. **嵌入式对象(Embedded Objects)**: 可以将一个对象嵌入到另一个对象中,作为一个整体处理。 8. **增强的注解支持**: 提供了更多的注解,如`@GeneratedValue`(自动生成主键)、`@Temporal`(处理日期和时间...

    Professional.MFC.with.VC6

    About Embedded Objects What's the Registry for? A New CDocument In-place Editing Activation Patterns Painting in an OLE Container Positioning, Moving and Sizing Your Object A COleRose is a ...

    win 3.x microsoft video组件

    - A slight memory leak that occurred with embedded objects was corrected. INSTALLING VIDEO 1.1E FOR WINDOWS RUN-TIME EDITION -------------------------------------------------- 1. If you received a...

    hibernate中文官方文档3.6

    - **Embedded objects**:嵌入式对象的映射。 - **Inheritance strategy**:不同继承模式的选择和配置。 - **Mapping one-to-one and one-to-many associations**:一对一和一对多关联的映射方法。 - **自然ID...

    hibernate doc 中文版

    - **Embedded objects:** - 如何映射嵌套对象或复合属性。 - **Inheritance strategy:** - 实现类继承时的不同映射策略。 - **Mapping one-to-one and one-to-many associations:** - 映射一对一和一对多关联...

    Knowledge-Embedded Routing Network for Scene Graph Generation.pdf

    To understand a scene in depth not only involves locating/recognizing individual objects, but also requires to infer the relationships and interactions among them. However, sincethedistributionofreal-...

    unity内嵌浏览器Embedded Browser V2.1.0

    unity内嵌浏览器Embedded Browser V2.1.0(适用于PC端) 所支持的Unity版本:5.6.3 及以上版本 Render a webpage to a texture and fully interact with it! Expedite your inventory manager, simplify your ...

    Making Things Smart Easy Embedded JavaScript Programming for Making epub

    Making Things Smart Easy Embedded JavaScript Programming for Making Everyday Objects into Intelligent Machines 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有...

    嵌入式Linux系统Qt_Embedded中文字体移植.pdf

    Makefile的HEADERS、SOURCES和OBJECTS部分分别用于管理头文件、源代码和编译后的目标文件。值得注意的是,tmake生成的Makefile可以根据文件扩展名自动选择合适的编译器。 要建立Qt开发和运行环境,首先需要下载Qt-...

Global site tag (gtag.js) - Google Analytics