jpa返回值對映 JPA基本資料型別對映

2021-10-13 03:31:04 字數 2339 閱讀 9569

*  employ

* @author administrator

@entity

@table(name = "t_employ")

// @sequencegenerator(name = "seq", sequencename = "seq_sys_func_menu",

// initialvalue = 0, allocationsize = 1)   oracle中序列方式生成主鍵

public class employ {

//@id

// @generatedvalue(strategy = generationtype.sequence, generator ="seq")

//oracle序列方式生成/主鍵

@id@generatedvalue(strategy = generationtype.identity)   //mysql,sqlserver自增長方式

@column(name = "id", nullable = false)

private integer id; // 主鍵,非空,主鍵生成方式自動

@column(name = "name", nullable = false, length = 32)

private string name; // 長度32,非空

@temporal(temporaltype.date)

@column(name = "birthday", nullable = true, length = 32)

private date birthday; // 日期型別,格式:yyyy-mm-dd

@temporal(temporaltype.timestamp)

private date enterdate; // 日期型別,格式:yyyy-mm-dd hh:mm:ss

@enumerated(enumtype.ordinal)

@column(name = "firstseason")

private season firstseason = season.spring;// 季節列舉型別,顯示索引值

@enumerated(enumtype.string)

@column(name = "secondseason", nullable = false, length = 6)

private season secondseason = season.autumn;// 季節列舉型別,顯示字串

@lob

private string bigtext; // 文字大字段型別

@lob

@basic(fetch = fetchtype.lazy)

private byte filedata; // 二進位制位元組流,啟用延遲載入方式

@transient

private string filepath;// 虛擬列,不生成表字段

public string tostring() {

return "[ id:" + id + ",name:" + name + ",birthday:" + birthday

+ ",enterdate:" + enterdate + ",firstseason:" + firstseason.ordinal()

+ ",secondseason:" + secondseason + ",bigtext:" + bigtext

+ ",filepath:=" + filepath + "]";

//getter/setter ... ...

//測試方法

* @param args

public static void main(string args) {

// todo auto-generated method stub

entitymanage***ctory factory = persistence.createentitymanage***ctory("sample");

entitymanager em = factory.createentitymanager();

em.gettransaction().begin();

employ employ = new employ();

employ.setname("employ1");

employ.setfirstseason(season.spring);

employ.setsecondseason(season.autumn);

em.persist(employ);

em.gettransaction().commit();

em.close();

factory.close();

jpa 資料庫對映註解介紹

1 entity name entityname 必須,name為可選,對應資料庫中一的個表 2 table name catalog schema 可選,通常和 entity配合使用,只能標註在實體的class定義處,表示實體對應的資料庫表的資訊 name 可選,表示表的名稱.預設地,表名和實體名...

資料庫 JPA關係資料對映

jpa提供四種標準用法為 table,sequence,identity,auto auto 主鍵自動增長,由應用程式控制 jpa預設策略就是auto identity 主鍵由資料庫自動生成 主要就是自動增長 sequence 根據底層資料庫的序列來生成主鍵,條件就是資料庫支援序列。table 使用...

spring的jpa通過實體對映生成資料庫中表

資料的配置主要有 在hibernate連線資料庫中 update 自動修改資料庫中的表 create自動建立資料庫中的表 hibernate.hbm2ddl.auto引數的作用主要用於 自動建立 更新 驗證資料庫表結構。create 每次載入hibernate時都會刪除上一次的生成的表,然後根據你的...