日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

JPA中的@MappedSuperclass

發(fā)布時(shí)間:2023/12/10 编程问答 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 JPA中的@MappedSuperclass 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

說(shuō)明地址:http://docs.oracle.com/javaee/5/api/javax/persistence/MappedSuperclass.html

用來(lái)申明一個(gè)超類,繼承這個(gè)類的子類映射時(shí)要映射此類中的字段,可以當(dāng)做是對(duì)entity抽取封裝的類。如果子類想重寫(xiě)此類的映射信息,可以使用?AttributeOverride?and?AssociationOverride?annotations

?

Java代碼 ?
  • ?Example:?Concrete?class?as?a?mapped?superclass??
  • @MappedSuperclass??
  • public?class?Employee?{??
  • ??????
  • ????????@Id???
  • ????????protected?Integer?empId;??
  • ????????@Version???
  • ????????protected?Integer?version;??
  • ????????@ManyToOne?@JoinColumn(name="ADDR")??
  • ????????protected?Address?address;??
  • ??????
  • ????????public?Integer?getEmpId()?{?...?}??
  • ????????public?void?setEmpId(Integer?id)?{?...?}??
  • ????????public?Address?getAddress()?{?...?}??
  • ????????public?void?setAddress(Address?addr)?{?...?}??
  • }??
  • ??????
  • //?Default?table?is?FTEMPLOYEE?table??
  • @Entity??
  • public?class?FTEmployee?extends?Employee?{??
  • ??????
  • ????????//?Inherited?empId?field?mapped?to?FTEMPLOYEE.EMPID??
  • ????????//?Inherited?version?field?mapped?to?FTEMPLOYEE.VERSION??
  • ????????//?Inherited?address?field?mapped?to?FTEMPLOYEE.ADDR?fk??
  • ??????????
  • ????//?Defaults?to?FTEMPLOYEE.SALARY??
  • ????protected?Integer?salary;??
  • ??????
  • ????public?FTEmployee()?{}??
  • ??????
  • ????public?Integer?getSalary()?{?...?}??
  • ??????
  • ????public?void?setSalary(Integer?salary)?{?...?}??
  • }??
  • ??????
  • ????@Entity?@Table(name="PT_EMP")??
  • ????@AssociationOverride(name="address",???
  • ????joincolumns=@JoinColumn(name="ADDR_ID"))??
  • ????public?class?PartTimeEmployee?extends?Employee?{??
  • ??????
  • ????????//?Inherited?empId?field?mapped?to?PT_EMP.EMPID??
  • ????????//?Inherited?version?field?mapped?to?PT_EMP.VERSION??
  • ????????//?address?field?mapping?overridden?to?PT_EMP.ADDR_ID?fk??
  • ????????@Column(name="WAGE")??
  • ????????protected?Float?hourlyWage;??
  • ??????
  • ????????public?PartTimeEmployee()?{}??
  • ??????
  • ????????public?Float?getHourlyWage()?{?...?}??
  • ????????public?void?setHourlyWage(Float?wage)?{?...?}??
  • ????}??
  • ??
  • ????Example:?Non-entity?superclass??
  • ??
  • ????public?class?Cart?{??
  • ??????
  • ????????//?This?state?is?transient??
  • ????????Integer?operationCount;??
  • ??????
  • ????????public?Cart()?{?operationCount?=?0;?}??
  • ????????public?Integer?getOperationCount()?{?return?operationCount;?}??
  • ????????public?void?incrementOperationCount()?{?operationCount++;?}??
  • ????}??
  • ??????
  • ????@Entity??
  • ????public?class?ShoppingCart?extends?Cart?{??
  • ??????
  • ????????Collection?items?=?new?Vector();??
  • ??????
  • ????????public?ShoppingCart()?{?super();?}??
  • ??????
  • ??????
  • ????...??
  • ??????
  • ????????@OneToMany??
  • ????????public?Collection?getItems()?{?return?items;?}??
  • ????????public?void?addItem(Item?item)?{??
  • ????????????items.add(item);??
  • ????????????incrementOperationCount();??
  • ????????}??
  • ????}??
  • 分享到:

    轉(zhuǎn)載于:https://www.cnblogs.com/toSeeMyDream/p/4606896.html

    總結(jié)

    以上是生活随笔為你收集整理的JPA中的@MappedSuperclass的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。