1. 程式人生 > >JPA註解:根據實體生成資料表和欄位的註釋(正向工程)

JPA註解:根據實體生成資料表和欄位的註釋(正向工程)

1.JPA常見註解 2.JPA註解:表註釋
  1. @org.hibernate.annotations.Table(appliesTo = "TableName",comment="表註釋")
  1. /*
  2. * Hibernate, Relational Persistence for Idiomatic Java
  3. *
  4. * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
  5. * See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
  6. */
  7. package org.hibernate.annotations;
  8. import java.lang.annotation.Retention;
  9. import java.lang.annotation.Target;
  10. importstatic java.lang.annotation.ElementType.TYPE;
  11. importstatic java.lang.annotation.RetentionPolicy.RUNTIME;
  12. /**
  13. * Complementary information to a table either primary or secondary.
  14. *
  15. * @author Emmanuel Bernard
  16. */
  17. @Target({TYPE})
  18. @Retention(RUNTIME)
  19. public@interfaceTable{
  20. /**
  21. * name of the targeted table.
  22. */
  23. String appliesTo();
  24. /**
  25. * Indexes.
  26. */
  27. Index[] indexes()default{};
  28. /**
  29. * define a table comment.
  30. */
  31. String comment()default"";
  32. /**
  33. * Defines the Foreign Key name of a secondary table pointing back to the primary table.
  34. */
  35. ForeignKey foreignKey()default@ForeignKey( name="");
  36. /**
  37. * If set to JOIN, the default, Hibernate will use an inner join to retrieve a
  38. * secondary table defined by a class or its superclasses and an outer join for a
  39. * secondary table defined by a subclass.
  40. * If set to select then Hibernate will use a
  41. * sequential select for a secondary table defined on a subclass, which will be issued only if a row
  42. * turns out to represent an instance of the subclass. Inner joins will still be used to retrieve a
  43. * secondary defined by the class and its superclasses.
  44. *
  45. * <b>Only applies to secondary tables</b>
  46. */
  47. FetchMode fetch()defaultFetchMode.JOIN;
  48. /**
  49. * If true, Hibernate will not try to insert or update the properties defined by this join.
  50. *
  51. * <b>Only applies to secondary tables</b>
  52. */
  53. boolean inverse()defaultfalse;
  54. /**
  55. * If enabled, Hibernate will insert a row only if the properties defined by this join are non-null
  56. * and will always use an outer join to retrieve the properties.
  57. *
  58. * <b>Only applies to secondary tables</b>
  59. */
  60. boolean optional()defaulttrue;
  61. /**
  62. * Defines a custom SQL insert statement.
  63. *
  64. * <b>Only applies to secondary tables</b>
  65. */
  66. SQLInsert sqlInsert()default@SQLInsert(sql="");
  67. /**
  68. * Defines a custom SQL update statement.
  69. *
  70. * <b>Only applies to secondary tables</b>
  71. */
  72. SQLUpdate sqlUpdate()default@SQLUpdate(sql="");
  73. /**
  74. * Defines a custom SQL delete statement.
  75. *
  76. * <b>Only applies to secondary tables</b>
  77. */
  78. SQLDelete sqlDelete()default@SQLDelete(sql="");
  79. }
3.JPA註解:欄位註釋
  1. @Column(name="columnComment",columnDefinition="varchar(200) COMMENT '欄位註釋'")
  1. /*
  2. * Copyright (c) 2008, 2009, 2011 Oracle, Inc. All rights reserved.
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
  6. * which accompanies this distribution. The Eclipse Public License is available
  7. * at http://www.eclipse.org/legal/epl-v10.html and the Eclipse Distribution License
  8. * is available at http://www.eclipse.org/org/documents/edl-v10.php.
  9. */
  10. package javax.persistence;
  11. import java.lang.annotation.Retention;
  12. import java.lang.annotation.Target;
  13. importstatic java.lang.annotation.ElementType.FIELD;
  14. importstatic java.lang.annotation.ElementType.METHOD;
  15. importstatic java.lang.annotation.RetentionPolicy.RUNTIME;
  16. /**
  17. * Is used to specify the mapped column for a persistent property or field.
  18. * If no <code>Column</code> annotation is specified, the default values apply.
  19. *
  20. * <blockquote><pre>
  21. * Example 1:
  22. *
  23. * &#064;Column(name="DESC", nullable=false, length=512)
  24. * public String getDescription() { return description; }
  25. *
  26. * Example 2:
  27. *
  28. * &#064;Column(name="DESC",
  29. * columnDefinition="CLOB NOT NULL",
  30. * table="EMP_DETAIL")
  31. * &#064;Lob
  32. * public String getDescription() { return description; }
  33. *
  34. * Example 3:
  35. *
  36. * &#064;Column(name="ORDER_COST", updatable=false, precision=12, scale=2)
  37. * public BigDecimal getCost() { return cost; }
  38. *
  39. * </pre></blockquote>
  40. *
  41. *
  42. * @since Java Persistence 1.0
  43. */
  44. @Target({METHOD, FIELD})
  45. @Retention(RUNTIME)
  46. public@interfaceColumn{
  47. /**
  48. * (Optional) The name of the column. Defaults to
  49. * the property or field name.
  50. */
  51. String name()default"";
  52. /**
  53. * (Optional) Whether the column is a unique key. This is a
  54. * shortcut for the <code>UniqueConstraint</code> annotation at the table
  55. * level and is useful for when the unique key constraint
  56. * corresponds to only a single column. This constraint applies
mysql中為使用者設定資料庫,資料(列)的訪問許可權

1、mysql中對指定使用者,授予某些資料庫,資料表或者欄位訪問許可權 語法: GRANT PRIVILEGES ON DATA.TABLE TO USERS; 溫馨提示: 授權後可以使用2中命令進行使用者許可權許可權,也可以直接重啟mysql程序方式進行許可權重新整理。 A

MySQL資料的查詢詳解SELECT語法

上一篇講了比較簡單的單表查詢以及MySQL的組函式,這一篇給大家分享一點比較難得知識了,關於多表查詢,子查詢,左連線,外連線等等。希望大家能都得到幫助! 在開始之前因為要多表查詢,所以搭建好環境:   1)建立資料表suppliers   前面已經有一張表是book表,我們

MySQL中大資料增加,增加索引實現

最近遇到的一個問題,需要在一張1800萬資料量的表中新增加一個欄位並新增索引,但是直接新增會導致mysql崩潰或者鎖表時間太長影響使用者操作,所以需要利用其他的方法進行新增,這篇文章主要給大家介紹了MySQL中大資料表增加欄位,增加索引的實現過程,需要的朋友可以參考借鑑。

Oracle查詢資料結構//型別/大小

Oracle資料庫字典在Oracle的絕大多數資料字典檢視中都有象DBA_TABLES,ALL_TABLES和USER_TABLES這樣的檢視家族。Oracle中有超過100個檢視家族,下表列出了最重要和最常用的檢視家族,需要注意的是每個檢視家族都有一個DBA_,一個ALL_

如果資料名是SQL關鍵字怎麼辦

比如最常見的USER作為表名,用SQL語句“select * from USER”查詢就會出現如下錯誤:在關鍵字 'USER' 附近有語法錯誤  可以用[ ]避免出現這樣的錯誤,即:將SQL語句改正這樣“select * from [USER]”

獲取資料註釋

1、oracle:                 SELECT t1.COLUMN_NAME,                  t2.COMMENTS                  FROM user_tab_columns t1,                  user_col_comment

sql server2008給資料,新增修改註釋

 1、sqlserver用語句給表註釋 EXECUTE sp_addextendedproperty N'MS_Description', N'表註釋', N'user', N'dbo', N'table', N'表名', NULL, NULL 2、sqlserver用語句給表的“欄位”註釋 EXECUT

TP中可通過對映隱藏資料

在ThinkPhP中,我們可以通過TP提供的一個關鍵字$_map來達到隱藏我們資料庫中表的欄位名的效果。 假設我們的User表裡面有username和email欄位,我們需要對映成另外的欄位,定義方式如下: 例子如下: namespace Home\Model;use Th

安卓註解使用,實體類指定須使用, Google Gson 過濾

  實體類複用,專案中往往會遇到這樣一些問題,有一個欄位很多的實體類,然後向服務端提交資料的時候卻不需要這個實體類的全部欄位。所以我們通常的方法就是再新建一個只有需要欄位的實體類。還有一種方法就是本文要說到的註解,給某個操作時需要用到的欄位加上註解: 1.新介面Submi

在oracle中操作註釋

1、查詢表註釋 SELECT * FROM USER_TAB_COMMENTS;三列:TABLE_NAME,TABLE_TYPE,COMMENTS 2、查詢欄位註釋 SELECT * FROM USER_COL_COMMENTS;三列:TABLE_NAME,COLUMN_NAME,COM

mysql 初體驗 -----資料的增刪改查

上篇隨筆說到了如何去安裝和 DOS命令 一些最簡單的操作,以及如何去鍵一個數據庫和如何建表。   這次接著來談mysql 裡資料和欄位的增刪改查 有增刪改查就會有資料型別以及資料型別的屬性 mysql資料型別和資料屬性有很多,先接觸一些最基本和最實用的的。   mysql 資料

fastadmin 的註釋註釋

在安裝好 fastdamin 之後,看官方的文件,說是建立表的時候,要寫表註釋和欄位註釋; 不瞭解資料庫,只知道簡單的表和欄位的概念,這個註釋是什麼還真的不瞭解,於是,學習一下: 表註釋:在建立表的時候給表增加的說明文字; 看下fastadmin 的資料庫是怎麼樣的

檢視文章 mysql:註釋註釋

1 建立表的時候寫註釋 create table test1 (     field_name int comment '欄位的註釋' )comment='表的註釋'; 2 修改表的註釋 alter table test1 comment '修改後的表的註釋'