博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【Hibernate学习笔记-5】@Formula注解的使用
阅读量:6940 次
发布时间:2019-06-27

本文共 1012 字,大约阅读时间需要 3 分钟。

ORM映射关系:注解方式
 
  1. package org.crazyit.app.domain;
  2. import javax.persistence.*;
  3. import org.hibernate.annotations.Formula;
  4. @Entity(name="news_inf")
  5. public class News
  6. {
  7. // 消息类的标识属性
  8. @Id
  9. @GeneratedValue(strategy=GenerationType.IDENTITY)
  10. private Integer id;
  11. // 消息标题
  12. private String title;
  13. // 消息内容
  14. private String content;
  15. // 消息全部内容,由系统根据公式生成
  16. @Formula("(select concat(nt.title,nt.content)"
  17. + "from news_inf nt where nt.id= id)")
  18. private String fullContent;
  19. // id的setter和getter方法
  20. public void setId(Integer id)
  21. {
  22. this.id = id;
  23. }
  24. public Integer getId()
  25. {
  26. return this.id;
  27. }
  28. // title的setter和getter方法
  29. public void setTitle(String title)
  30. {
  31. this.title = title;
  32. }
  33. public String getTitle()
  34. {
  35. return this.title;
  36. }
  37. // content的setter和getter方法
  38. public void setContent(String content)
  39. {
  40. this.content = content;
  41. }
  42. public String getContent()
  43. {
  44. return this.content;
  45. }
  46. // fullContent的setter和getter方法
  47. public void setFullContent(String fullContent)
  48. {
  49. this.fullContent = fullContent;
  50. }
  51. public String getFullContent()
  52. {
  53. return this.fullContent;
  54. }
  55. }

主函数

转载地址:http://muinl.baihongyu.com/

你可能感兴趣的文章
红黑树(一)之原理和算法的详细分析【转】
查看>>
undefined reference to typeinfo - C++ error message
查看>>
springmvc: 普通list数据输出json
查看>>
8127 timeout!!! 搞死人啊
查看>>
Android开发 设置开机自动启动
查看>>
高德地图iOS SDK限制地图的缩放比例
查看>>
【组件化开发】前端进阶篇之如何编写可维护可升级的代码
查看>>
Node.js node主文件找不到时报出的Error:Cannot find module异常
查看>>
让SQL Server Compact支持 Membership, Role and Profile provider
查看>>
一个编译器的实现2——从文法到LL(1)分析表的概念和算法
查看>>
报表系统结构优化之中间数据外置
查看>>
《JAVA与模式》之门面模式
查看>>
vim/vi的文件内、跨文件复制粘贴操作、替换操作
查看>>
java命令执行jar文件
查看>>
python get class base name
查看>>
论这场云盘大战,以及各网盘的优劣
查看>>
怪异的JavaScript系列(三)
查看>>
辅助模式最终考验的是想象力,先来看看怎么用!| Accessibility
查看>>
TiDB 源码阅读系列文章(九) Hash Join
查看>>
【个人向整理】Promise
查看>>