hibernate以Annotation方式oracle以及mysql数据库相结合的实体配置

 

oracle配置:

package com.test.hibernate;

import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.SequenceGenerator;

@Entity @SequenceGenerator(name="categorySEQ",sequenceName="seq_for_category") public class Category {  private int id;  private String name;  @Id  @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="categorySEQ")  public int getId() {   return id;  }  public void setId(int id) {   this.id = id;  }  public String getName() {   return name;  }  public void setName(String name) {   this.name = name;  }

}

 

mySql配置:

package com.test.hibernate;

import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id;

@Entity public class Category {  private int id;  private String name;  /**   * @return   * 这里注意如果设置为GeneratedValue那么在自动生成表的过程中   * 这个列就会被设置为自动增长的列,并且这个列是主键,如果不写   * 那么它只是主键而不是自动增长。   */  @Id  @GeneratedValue  public int getId() {   return id;  }  public void setId(int id) {   this.id = id;  }  public String getName() {   return name;  }  public void setName(String name) {   this.name = name;  }

}

你可能感兴趣的:(oracle,数据库,Hibernate,String,Class,generator)