大魚

          EJB3.x:關于@UniqueConstraint標記中的columnNames屬性

          EJB3.x:關于@UniqueConstraint標記中的columnNames屬性

          例如以下代碼:

          1. package net.model.entity;   
          2.   
          3. import java.io.Serializable;   
          4.   
          5. import javax.persistence.Column;   
          6. import javax.persistence.Entity;   
          7. import javax.persistence.GeneratedValue;   
          8. import javax.persistence.GenerationType;   
          9. import javax.persistence.Id;   
          10. import javax.persistence.Table;   
          11. import javax.persistence.UniqueConstraint;   
          12.   
          13. @Entity  
          14. @Table(   
          15.         name="ROLE" ,   
          16.         uniqueConstraints={@UniqueConstraint(columnNames={"ROLE_NAME"})}                   
          17. )   
          18. public class Role implements Serializable   
          19. {   
          20.     private Integer id ;   
          21.        
          22.     private String roleName;   
          23.        
          24.     private int roleValue ;   
          25.        
          26.   
          27.   
          28.     @Id  
          29.     @GeneratedValue(strategy=GenerationType.AUTO)   
          30.     @Column(name="ROLE_ID")   
          31.     public Integer getId() {   
          32.         return id;   
          33.     }   
          34.   
          35.     public void setId(Integer id) {   
          36.         this.id = id;   
          37.     }   
          38.   
          39.        
          40.        
          41.     @Column(name="ROLE_NAME" , nullable=false ,length=50)   
          42.     public String getRoleName() {   
          43.         return roleName;   
          44.     }   
          45.   
          46.     public void setRoleName(String roleName) {   
          47.         this.roleName = roleName;   
          48.     }   
          49.   
          50.     @Column(name="ROLE_VALUE" , nullable=false)   
          51.     public int getRoleValue() {   
          52.         return roleValue;   
          53.     }   
          54.   
          55.     public void setRoleValue(int roleValue) {   
          56.         this.roleValue = roleValue;   
          57.     }   
          58.   
          59. }  
            

           

           

          注意uniqueConstraints={@UniqueConstraint(columnNames={"ROLE_NAME"})} 中的columnNames屬性值為數據庫表中的字段名,而不是Role類中的類成員名roleName。

          posted on 2009-03-16 22:16 大魚 閱讀(670) 評論(0)  編輯  收藏 所屬分類: EJB

          主站蜘蛛池模板: 小金县| 汕尾市| 莱芜市| 海原县| 美姑县| 长春市| 武城县| 安图县| 阿鲁科尔沁旗| 武川县| 扎兰屯市| 烟台市| 东明县| 孟州市| 潜山县| 望江县| 五河县| 兴和县| 西吉县| 乐至县| 长寿区| 松潘县| 仙居县| 临洮县| 上蔡县| 海兴县| 长沙市| 金平| 资源县| 滦南县| 雅江县| 彰化县| 芜湖县| 许昌市| 香格里拉县| 永定县| 慈溪市| 新蔡县| 祁门县| 沈阳市| 武乡县|