使用 hSQLDB
CREATE TABLE HIBERNATE_SEQUENCES
(
SEQUENCE_NAME VARCHAR(255) NOT
NULL,
SEQUENCE_NEXT_HI_VALUE BIGINT NOT NULL
);
@GeneratedValue(strategy = GenerationType.TABLE)
默写要建立缺省表
1 package com.hantongchao.entity; 2 3 import javax.persistence.*; 4 import java.util.HashSet; 5 import java.util.Set; 6 7 /** 8 * Created by han on 14-3-6. 9 */ 10 @Entity 11 @Table(name = "USER", schema = "PUBLIC", catalog = "PUBLIC") 12 public class UserEntity { 13 private int user_id; 14 private String name; 15 private String surname; 16 private Set<AccountEntity> accountEntities = new HashSet<AccountEntity>(); 17 18 19 20 @Id 21 @Column(name = "User_ID", nullable = false, insertable = true, updatable = true, length = 32, precision = 0) 22 /* @GeneratedValue(strategy = GenerationType.TABLE,generator="userIdGen") 23 @TableGenerator(name="userIdGen",table = "Tb_Generator",catalog = "PUBLIC", 24 schema = "PUBLIC",pkColumnName = "gen_name", valueColumnName = "gen_value", 25 pkColumnValue = "user_pk" ,allocationSize = 1) 26 */ 27 @GeneratedValue(strategy = GenerationType.TABLE) 28 public int getUser_id() { 29 return user_id; 30 } 31 32 public void setUser_id(int user_id) { 33 this.user_id = user_id; 34 } 35 @Basic 36 @Column(name = "NAME", nullable = false, insertable = true, updatable = true, length = 45, precision = 0) 37 public String getName() { 38 return name; 39 } 40 41 public void setName(String name) { 42 this.name = name; 43 } 44 45 @Basic 46 @Column(name = "SURNAME", nullable = false, insertable = true, updatable = true, length = 45, precision = 0) 47 public String getSurname() { 48 return surname; 49 } 50 51 public void setSurname(String surname) { 52 this.surname = surname; 53 } 54 55 56 57 @OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER ,mappedBy = "user") 58 public Set<AccountEntity> getAccountEntities() { 59 return accountEntities; 60 } 61 62 public void setAccountEntities(Set<AccountEntity> accountEntities) { 63 this.accountEntities = accountEntities; 64 } 65 66 public UserEntity addAccount(AccountEntity accountEntity){ 67 accountEntity.setUser(this); 68 this.getAccountEntities().add(accountEntity); 69 return this; 70 } 71 72 }