成功捷径,贵在坚持
人为善,福虽未至祸已远离; 人为恶,祸虽未至福已远离
package  com.e104cn.pda.data.anno;

import  java.io.Serializable;
import  java.util.Date;

import  javax.persistence.CascadeType;
import  javax.persistence.Entity;
import  javax.persistence.GeneratedValue;
import  javax.persistence.GenerationType;
import  javax.persistence.Id;
import  javax.persistence.JoinColumn;
import  javax.persistence.OneToOne;
import  javax.persistence.Table;
import  javax.persistence.Temporal;
import  javax.persistence.TemporalType;

import  org.hibernate.annotations.Cache;
import  org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 *  <p>@Description:</p>
 *  <p>@Company:    104人力银行</p>
 *  <p>@CreateDate: 2008-5-19</p>
 *     
@author :    locey.zhang 
 *       
@version :   1.0     
 
*/

@SuppressWarnings(
" serial " )
@Entity
@Table(name 
=   " AUTHOR " )
@Cache(usage 
=  CacheConcurrencyStrategy.READ_WRITE)
public   class  Author  implements  Serializable {

    
private   static   final   long  serialVersionUID  =   7131973910486229579L ;
    
    
private   int  id;
    
    
private  String firstName;
    
    
private  String lastName;
    
    
private   boolean  male;
    
    
private  Date birthday;

    
private  Book book;

    @Id
    @GeneratedValue(strategy
= GenerationType.SEQUENCE)
    
public   int  getId()  {
        
return  id;
    }


    
public   void  setId( int  oid)  {
        
this .id  =  oid;
    }


    
public  String getFirstName()  {
        
return  firstName;
    }


    
public   void  setFirstName(String firstName)  {
        
this .firstName  =  firstName;
    }


    
public  String getLastName()  {
        
return  lastName;
    }


    
public   void  setLastName(String lastName)  {
        
this .lastName  =  lastName;
    }


    
public   boolean  isMale()  {
        
return  male;
    }


    
public   void  setMale( boolean  male)  {
        
this .male  =  male;
    }


    @Temporal(value
= TemporalType.TIMESTAMP)
    
public  Date getBirthday()  {
        
return  birthday;
    }


    
public   void  setBirthday(Date birthday)  {
        
this .birthday  =  birthday;
    }


    @OneToOne(cascade
= CascadeType.ALL)
    @JoinColumn(name
= " book_oid " )
    
public  Book getBook()  {
        
return  book;
    }


public   void  setBook(Book book)  {
        
this .book  =  book;
    }

 
    
}


Book.java
package com.e104cn.pda.data.anno;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

/**
 *  <p>@Description:</p>
 *  <p>@Company:    104人力银行</p>
 *  <p>@CreateDate: 2008-5-19</p>
 *     
@author:    locey.zhang 
 *       
@version:   1.0     
 
*/

@SuppressWarnings(
"serial")
@Entity
@Table(name 
= "BOOK")
@Cache(usage 
= CacheConcurrencyStrategy.READ_WRITE)
public class Book implements Serializable{

    
private static final long serialVersionUID = -2700610405985954588L;
    
    
private int oid;
    
    
private String name;
    
    
private String description;
    
    
private Date publish;
    

    @Id
    @GeneratedValue(strategy
=GenerationType.SEQUENCE)
    
public int getOid() {
        
return oid;
    }


    
public void setOid(int oid) {
        
this.oid = oid;
    }


    
public String getName() {
        
return name;
    }


    
public void setName(String name) {
        
this.name = name;
    }


    
public String getDescription() {
        
return description;
    }


    
public void setDescription(String description) {
        
this.description = description;
    }


    @Temporal(value
=TemporalType.TIMESTAMP)
    
public Date getPublish() {
        
return publish;
    }


    
public void setPublish(Date publish) {
        
this.publish = publish;
    }
  
    
}


@JoinColumn注释优点与缺点
     1、优点  @Id可以使用主键生成策略 oracle为例@GeneratedValue(strategy=GenerationType.SEQUENCE)
     2、缺点 AUTHOR表中会成额外的数据列(字段BOOK_OID)
@PrimaryKeyJoinColumn与@JoinColumn相反
     1、优点  AUTHOR表中不会生成额外的数据列
     2、缺点 不可以使用主键生成策略
posted on 2008-05-21 08:19 选宝网an9 阅读(4459) 评论(0)  编辑  收藏 所属分类: 学习资料

只有注册用户登录后才能发表评论。


网站导航: