hibernate组件



一、xml方式配置

持久化类1

public class Contact implements Serializable {
    private long id;
    private String recipient;
    private String phone;
    private String addredd;

持久化类2

public class Orders implements Serializable {
    private long id;
    private Contact weeddaycontact;
xml配置文件
<hibernate-mapping>
   <class name="zujian.Orders">
       <id name="id">
           <generator class="increment"></generator>
       </id>
      <component name="weeddaycontact" class="zujian.Contact">
          <property name="phone"></property>
          <property name="addredd"></property>
          <property name="recipient"></property>

      </component>

   </class>
</hibernate-mapping>

二、注解方式组件

持久化类

@Embeddable
public class Contact implements Serializable {
    @Column(name = "Contact_id")
    private long id;
    @Column(name = "recipient_")
    private String recipient;
    @Column(name = "phone_")
    private String phone;
    @Column(name = "addr_")
    private String addredd;

持久化类2

@Entity
public class Orders implements Serializable{
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id_")
    private long id;
    @Embedded
    private Contact weekdayContact;//组件