• Hibernate注解配置1n,n1示例


    package com.entity;

    import java.util.HashSet;
    import java.util.Set;

    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;

    import org.hibernate.annotations.Cache;
    import org.hibernate.annotations.CacheConcurrencyStrategy;

    @Entity
    @Table(name="role")

    public class RoleInfo {

     private Integer roleId;
     private String roleName;
     private Set<UserInfo> users=new HashSet<UserInfo>();
     
     @Id
     @GeneratedValue(strategy=GenerationType.IDENTITY)
     public Integer getRoleId() {
      return roleId;
     }
     public void setRoleId(Integer roleId) {
      this.roleId = roleId;
     }
     public String getRoleName() {
      return roleName;
     }
     public void setRoleName(String roleName) {
      this.roleName = roleName;
     }
     
     
     @OneToMany(mappedBy="role")
     public Set<UserInfo> getUsers() {
      return users;
     }
     public void setUsers(Set<UserInfo> users) {
      this.users = users;
     }
     
    }

    package com.entity;

    import java.util.Date;

    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.NamedNativeQuery;
    import javax.persistence.NamedQuery;
    import javax.persistence.Table;

    @Entity
    @Table(name="user")
    public class UserInfo {

     private Integer userId;
     private String username;
     private String password;
     private String realName;
     private Date birthday;
     private RoleInfo role;
     
     @Id
     @GeneratedValue(strategy=GenerationType.IDENTITY)
     public Integer getUserId() {
      return userId;
     }
     public void setUserId(Integer userId) {
      this.userId = userId;
     }
     public String getUsername() {
      return username;
     }
     public void setUsername(String username) {
      this.username = username;
     }
     public String getPassword() {
      return password;
     }
     public void setPassword(String password) {
      this.password = password;
     }
     public String getRealName() {
      return realName;
     }
     public void setRealName(String realName) {
      this.realName = realName;
     }
     public Date getBirthday() {
      return birthday;
     }
     public void setBirthday(Date birthday) {
      this.birthday = birthday;
     }
     
     @ManyToOne
     @JoinColumn(name="roleId")
     public RoleInfo getRole() {
      return role;
     }
     public void setRole(RoleInfo role) {
      this.role = role;
     }
     @Override
     public String toString() {
      return "UserInfo [userId=" + userId + ", username=" + username
        + ", password=" + password + ", realName=" + realName
        + ", birthday=" + birthday + ", role=" + role + "]";
     }
     public UserInfo() {
      
     }
     public UserInfo(String username, String password) {
      super();
      this.username = username;
      this.password = password;
     }
     
    }

  • 相关阅读:
    js-快速选择日期区间
    关于状态更新时间字段取值的问题
    MySql 前缀索引
    Java springMVC 多数据源的实现和使用
    哈哈哈,终于找到一个安稳的“家”了
    POJ 1724: Roads
    POJ 1221: UNIMODAL PALINDROMIC DECOMPOSITIONS
    createjs 用户画线 粗细bug Graphics setStrokeStyle() 粗细BUG
    GAudio是一个音频播放SDK
    新做的一个基于OPENGL的gui库
  • 原文地址:https://www.cnblogs.com/yang-32/p/5684341.html
Copyright © 2020-2023  润新知