ManyToMany(基于注解)使用之进阶(中级版)

2024-09-07 01:08

本文主要是介绍ManyToMany(基于注解)使用之进阶(中级版),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

社团和成员就是多对多的关系,一个成员有多个社团,一个社团也有多个成员,这里的多对多映射采用中间表连接的映射策略,建立中间表的映射策略,建立中间表分别引入俩边的主键作为外键。通过中间表映射俩个表之间的关系。

下面就以社团类和成员类为例介绍多对多的映射关系的实例

Club实体类

package com.cn.entity;import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;import com.fasterxml.jackson.annotation.JsonIgnoreProperties;/*** @ClassName: Club* @Description: 社团的实体类* @author: Administrator* @date: 2016年7月6日 下午3:27:43*/
@Entity //实体类
@Table(name="iyo_club",catalog="iyo") //哪个数据库那张表
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE) //二级缓存
public class Club implements Serializable{/*** @fieldName: serialVersionUID* @fieldType: long* @Description: */private static final long serialVersionUID = -1576706279212597880L;private Integer clubId;//社团IDprivate String clubIntroction;//社团简介private String ClubName;//社团名称private Integer clubLevel;//社团等级private Integer clubNumber;//社团人数private Date clubCreateTime;//创建时间private User user;//创始人private College college;//所属学院private Set<Member> member = new HashSet<Member>();public Club() {//super();}public Club(String clubIntroction, String clubName, Integer clubLevel, Integer clubNumber, Date clubCreateTime,User user, College college) {//super();this.clubIntroction = clubIntroction;ClubName = clubName;this.clubLevel = clubLevel;this.clubNumber = clubNumber;this.clubCreateTime = clubCreateTime;this.user = user;this.college = college;}@Id //主键@GeneratedValue(strategy = GenerationType.IDENTITY) //数据库自增public Integer getClubId() {return clubId;}public void setClubId(Integer clubId) {this.clubId = clubId;}public String getClubIntroction() {return clubIntroction;}public void setClubIntroction(String clubIntroction) {this.clubIntroction = clubIntroction;}public String getClubName() {return ClubName;}public void setClubName(String clubName) {ClubName = clubName;}public Integer getClubLevel() {return clubLevel;}public void setClubLevel(Integer clubLevel) {this.clubLevel = clubLevel;}public Integer getClubNumber() {return clubNumber;}public void setClubNumber(Integer clubNumber) {this.clubNumber = clubNumber;}public Date getClubCreateTime() {return clubCreateTime;}public 

这篇关于ManyToMany(基于注解)使用之进阶(中级版)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1143625

相关文章

Python数据验证神器Pydantic库的使用和实践中的避坑指南

《Python数据验证神器Pydantic库的使用和实践中的避坑指南》Pydantic是一个用于数据验证和设置的库,可以显著简化API接口开发,文章通过一个实际案例,展示了Pydantic如何在生产环... 目录1️⃣ 崩溃时刻:当你的API接口又双叒崩了!2️⃣ 神兵天降:3行代码解决验证难题3️⃣ 深度

Linux内核定时器使用及说明

《Linux内核定时器使用及说明》文章详细介绍了Linux内核定时器的特性、核心数据结构、时间相关转换函数以及操作API,通过示例展示了如何编写和使用定时器,包括按键消抖的应用... 目录1.linux内核定时器特征2.Linux内核定时器核心数据结构3.Linux内核时间相关转换函数4.Linux内核定时

python中的flask_sqlalchemy的使用及示例详解

《python中的flask_sqlalchemy的使用及示例详解》文章主要介绍了在使用SQLAlchemy创建模型实例时,通过元类动态创建实例的方式,并说明了如何在实例化时执行__init__方法,... 目录@orm.reconstructorSQLAlchemy的回滚关联其他模型数据库基本操作将数据添

Spring配置扩展之JavaConfig的使用小结

《Spring配置扩展之JavaConfig的使用小结》JavaConfig是Spring框架中基于纯Java代码的配置方式,用于替代传统的XML配置,通过注解(如@Bean)定义Spring容器的组... 目录JavaConfig 的概念什么是JavaConfig?为什么使用 JavaConfig?Jav

Java使用Spire.Doc for Java实现Word自动化插入图片

《Java使用Spire.DocforJava实现Word自动化插入图片》在日常工作中,Word文档是不可或缺的工具,而图片作为信息传达的重要载体,其在文档中的插入与布局显得尤为关键,下面我们就来... 目录1. Spire.Doc for Java库介绍与安装2. 使用特定的环绕方式插入图片3. 在指定位

Springboot3 ResponseEntity 完全使用案例

《Springboot3ResponseEntity完全使用案例》ResponseEntity是SpringBoot中控制HTTP响应的核心工具——它能让你精准定义响应状态码、响应头、响应体,相比... 目录Spring Boot 3 ResponseEntity 完全使用教程前置准备1. 项目基础依赖(M

Java使用Spire.Barcode for Java实现条形码生成与识别

《Java使用Spire.BarcodeforJava实现条形码生成与识别》在现代商业和技术领域,条形码无处不在,本教程将引导您深入了解如何在您的Java项目中利用Spire.Barcodefor... 目录1. Spire.Barcode for Java 简介与环境配置2. 使用 Spire.Barco

Android使用java实现网络连通性检查详解

《Android使用java实现网络连通性检查详解》这篇文章主要为大家详细介绍了Android使用java实现网络连通性检查的相关知识,文中的示例代码讲解详细,感兴趣的小伙伴可以跟随小编一起学习一下... 目录NetCheck.Java(可直接拷贝)使用示例(Activity/Fragment 内)权限要求

C# 预处理指令(# 指令)的具体使用

《C#预处理指令(#指令)的具体使用》本文主要介绍了C#预处理指令(#指令)的具体使用,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学... 目录1、预处理指令的本质2、条件编译指令2.1 #define 和 #undef2.2 #if, #el

C#中Trace.Assert的使用小结

《C#中Trace.Assert的使用小结》Trace.Assert是.NET中的运行时断言检查工具,用于验证代码中的关键条件,下面就来详细的介绍一下Trace.Assert的使用,具有一定的参考价值... 目录1、 什么是 Trace.Assert?1.1 最简单的比喻1.2 基本语法2、⚡ 工作原理3