`
yun342173024
  • 浏览: 73844 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

hibernate和jpa注解关联总结

 
阅读更多
用hibernate和jpa annotation 大概一年多了,今天闲来无事,对他们关联关系元数据写法做一个总结。
1.一对一主键关联
这个在实际项目中用的比较少,大部分是通过用外键做关联的,这里用用户和手机号举个例子,用户和手机号是一对一的关系,代码如下:
User实体
  package com.own.model;

import java.io.Serializable;

public class Users implements Serializable{

      private static final long serialVersionUID = 1381652232198529039L;
	private int id;
	private String username;
	private String password;
	private CellphoneNumber phoneNumber;
	public CellphoneNumber getPhoneNumber() {
		return phoneNumber;
	}
	public void setPhoneNumber(CellphoneNumber phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	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;
	}

	
}



手机号实体
  package com.own.model;

import java.io.Serializable;

public class CellphoneNumber implements Serializable {
    
	private static final long serialVersionUID = -1029364968566042141L;
	
	private Integer cellPhoneId;
	private String number;
	private String attribution;//手机归属地
	private String cellphonoeType;//移动或者联通
	private Users user ;
	public Users getUser() {
		return user;
	}
	public void setUser(Users user) {
		this.user = user;
	}
	public Integer getCellPhoneId() {
		return cellPhoneId;
	}
	public void setCellPhoneId(Integer cellPhoneId) {
		this.cellPhoneId = cellPhoneId;
	}
	public String getNumber() {
		return number;
	}
	public void setNumber(String number) {
		this.number = number;
	}
	public String getAttribution() {
		return attribution;
	}
	public void setAttribution(String attribution) {
		this.attribution = attribution;
	}
	public String getCellphonoeType() {
		return cellphonoeType;
	}
	public void setCellphonoeType(String cellphonoeType) {
		this.cellphonoeType = cellphonoeType;
	}
	
	@Override
	public boolean equals(Object anotherObject){
		if(anotherObject == null || anotherObject.getClass() != this.getClass()){
			return false;
		}
		if(this == anotherObject){
			return true;
		}
		
		CellphoneNumber another = (CellphoneNumber) anotherObject;
		if(another.cellPhoneId.equals(this.cellPhoneId)){
			return true  ;
		}
		
		return false;
	}
	
	public int hashCode(){
		
		return cellPhoneId.hashCode();
	}
	
	
}


users映射文件
   <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping >

        <class name="com.own.model.Users"  table="users"  dynamic-update="true"  dynamic-insert="true"     >
          
           <id name="id"  column="id" >
              <generator class="native"></generator>
           </id>
           
            <property name="username"  column="username"   ></property>  
            <property name="password"  column="password" type="string"  ></property>  
            
            <!-- 这里是一对一映射 级联为所有 -->
            <one-to-one name="phoneNumber" class="com.own.model.CellphoneNumber" cascade="all"  >
            
            </one-to-one>    
            
        </class>
</hibernate-mapping>

cellPhone映射文件
   <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping >

        <class name="com.own.model.CellphoneNumber"  table="cellphone"  dynamic-update="true"  dynamic-insert="true"   >
           <!-- 这里设置外键关联 -->
           <id name="cellPhoneId"  column="id" >
              <generator class="foreign">
                  <!-- 这里设置用引用user实体的主键  -->
                <param name="property">user</param>
              </generator>
           </id>
            <property name="number"  column="cellphoneNumber" ></property>  
            <property name="attribution"  column="attribution"   ></property>  
            <property name="cellphonoeType"  column="numberType"   ></property>  
            <!-- 加上外键约束  ,使Cellphone的主键引用user表行的主键 -->
            <one-to-one name="user" constrained="true"  class="com.own.model.Users"  ></one-to-one>
        </class>
</hibernate-mapping>

在调用时,要设置关联关系
  Users u = new Users();  
			u.setPassword("admin@1973");
			u.setUsername("floatSnow");
			CellphoneNumber cellphone = new CellphoneNumber();
			cellphone.setAttribution("北京");
			cellphone.setCellphonoeType("中国移动");
			cellphone.setNumber("13476534589");
			//设置双向关联关系
			u.setPhoneNumber(cellphone);
			cellphone.setUser(u);


jpa中使用@PrimaryKeyJoinColumn 

  package com.own.model;


import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name="users")
public class Users implements Serializable{
	private static final long serialVersionUID = 1381652232198529039L;
	private int id;
	private String username;
	private String password;
	private CellphoneNumber cellphone;
	
	@OneToOne(cascade={CascadeType.ALL})
	@PrimaryKeyJoinColumn
	public CellphoneNumber getCellphone() {
		return cellphone;
	}
	public void setCellphone(CellphoneNumber cellphone) {
		this.cellphone = cellphone;
	}
	@Id
	@GeneratedValue
	@Column(name="id")
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	@Column(name="username")
	public String getUsername() {
		return username;
	}
	
	public void setUsername(String username) {
		this.username = username;
	}
	
	@Column(name="password")
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}

	
}



2.一对一外键关联
hibernate xml文件映射,在这里使用manyToOne而不是我们想像的oneToOne,还有在  user表中加一个外键,引用另一个表的主键,这里设置双向关系,在项目中根据情况而定是否设置双向关系
映射文件
  <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping >
        <class name="com.own.model.Users"  table="users"  dynamic-update="true"  dynamic-insert="true" >
           <id name="id"  column="id" >
              <generator class="native"></generator>
           </id>
            <property name="username"  column="username"   ></property>  
            <property name="password"  column="password" type="string"  ></property> 
            <!-- 加上唯一约束,使这个关系成为真正的一对一 --> 
            <many-to-one name="phoneNumber" cascade="all" class="com.own.model.CellphoneNumber"  column="cell_id"  
              unique="true"  >
            </many-to-one>
        </class>
</hibernate-mapping>

 


jpa 映射使用oneToone,@joinColumn有两个属性 name 和 referencedColumnName
,name是表示表中外键的列名,referencedColumnName表示外键引用的表的列名。
user实体
    @OneToOne(cascade={CascadeType.ALL})
    @JoinColumn(name="cell_id",referencedColumnName="id")
	public CellphoneNumber getCellphone() {
		return cellphone;
	}
 

手机实体类
 
   
   @OneToOne(mappedBy="cellphone")
	public Users getU() {
		return u;
	}
  

3.一对一可选关联
有的时候我们的外键是可选的,也就是说user表的外键是可以为空的,这个时候我们可以把这中可选的关联映射到一张表,加一张中间表,表示实体的对应关系
Users实体映射文件

  <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping >
        <class name="com.own.model.Users"  table="users"  dynamic-update="true"  dynamic-insert="true" >
           <id name="id"  column="id" >
              <generator class="native"></generator>
           </id>
            <property name="username"  column="username"   ></property>  
            <property name="password"  column="password" type="string"  ></property> 
            <!-- 加上唯一约束,使这个关系成为真正的一对一 --> 
            <!-- optional 告诉hibernate这个关系是可选的 ,当这个属性为空时,可以不插入关联表 -->
            <join table="user_cellphoneNumber"      >
              <key column="user_id"    unique="true"  />
               <many-to-one name="phoneNumber"  cascade="save-update"      class="com.own.model.CellphoneNumber"   column="cell_id"  
              unique="true"     >
            </many-to-one>
            </join>
        </class>   
</hibernate-mapping>

jpa注解把属性映射到两张表,通过使用@SecondaryTable,使属性映射到一张中间表。
   package com.own.model;


import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.SecondaryTable;
import javax.persistence.Table;

import org.hibernate.transaction.JOnASTransactionManagerLookup;
@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name="users")
@SecondaryTable(name="user_cellphoneNumber",pkJoinColumns={@PrimaryKeyJoinColumn(name="user_id",referencedColumnName="id")})
public class Users implements Serializable{
	private static final long serialVersionUID = 1381652232198529039L;
	private int id;
	private String username;
	private String password;
	private CellphoneNumber cellphone;
	@OneToOne(cascade={CascadeType.ALL})
    @JoinColumn(table="user_cellphoneNumber",name="cell_id",referencedColumnName="id")
	public CellphoneNumber getCellphone() {
		return cellphone;
	}
	public void setCellphone(CellphoneNumber cellphone) {
		this.cellphone = cellphone;
	}
	@Id
	@GeneratedValue
	@Column(name="id")
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	
	@Column(name="username")
	public String getUsername() {
		return username;
	}
	
	public void setUsername(String username) {
		this.username = username;
	}
	
	@Column(name="password")
	public String getPassword() {
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}

	
}     

4.一对多关联
一对多关联通过oneToMany和ManyToMany映射,这里的多段在java里用一个集合set来表示,这个用商品category和货物Goods来举例子。
one端实体Category 映射xml

 <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping >
        <class name="com.own.model.Category"  table="category"  dynamic-insert="true" dynamic-update="false"      >
           <id name="category_id"  column="id" >
              <generator class="native"></generator>
           </id>
            <property name="categoryName"  column="category_name" type="string"  ></property> 
             
            <set name="goodsSet" inverse="true"  cascade="save-update"   >    <!-- 用key column 的名字表示关联表的外键的名称  -->
               <key column="category_id"    /> 
               <one-to-many  class="com.own.model.Goods"   /> 
              </set> 
        </class>
</hibernate-mapping>

many端的映射文件
    <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping   >
        <class name="com.own.model.Goods"  table="goods"  dynamic-insert="true" dynamic-update="false"      >
           <id name="id"  column="goods_id" >
              <generator class="native"></generator>
           </id>
            <property name="price"  column="goods_price" type="double"  ></property>  
            <property name="goodsName"  column="goods_name" type="string"  ></property>  
            <property name="goodsDescription"  column="goods_description" type="string"  ></property>  
            <many-to-one name="category"      fetch="join"    class="com.own.model.Category"  column="category_id"      >
            </many-to-one>
        </class>
 
</hibernate-mapping>

jpa元数据注解
Category实体

  package com.own.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name="category")
public class Category implements Serializable {
	private static final long serialVersionUID = 1L;
	private Integer category_id;
	private String categoryName;
    private Set<Goods> goodsSet = new HashSet<Goods>();	
    
    @OneToMany(mappedBy="category",cascade={CascadeType.ALL})
	public Set<Goods> getGoodsSet() {
		return goodsSet;
	}
	public void setGoodsSet(Set<Goods> goodsSet) {
		this.goodsSet = goodsSet;
	}
	@Id
	@GeneratedValue
	@Column(name="id")
	public Integer getCategory_id() {
		return category_id;
	}
	public void setCategory_id(Integer categoryId) {
		category_id = categoryId;
	}
	
	@Column(name="category_name")
	public String getCategoryName() {
		return categoryName;
	}
	public void setCategoryName(String categoryName) {
		this.categoryName = categoryName;
	}

	
	
}


Goods实体
  package com.own.model;


import java.io.Serializable;
import javax.persistence.Column;
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.Table;

@Entity
@org.hibernate.annotations.Entity(dynamicInsert=true,dynamicUpdate=true)
@Table(name="goods")
public class Goods implements Serializable {
	private static final long serialVersionUID = 1L;
	private Integer id;
	private  String goodsName;
	private Double price;
	private String goodsDescription;	
	private Category category;
	@ManyToOne
	@JoinColumn(name="category_id",referencedColumnName="id")
	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	public Goods(){}
	
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@Column(name="goods_id")
	public Integer getId() {
		return id;
	}
	
	public void setId(Integer id) {
		this.id = id;
	}
	
	@Column(name="goods_name",length=40,nullable=false)
	public String getGoodsName() {
		return goodsName;
	}
	public void setGoodsName(String goodsName) {
		this.goodsName = goodsName;
	}
	
	@Column(name="goods_price")
	public Double getPrice() {
		return price;
	}
	public void setPrice(Double price) {
		this.price = price;
	}
	
	@Column(name="goods_description")
	public String getGoodsDescription() {
		return goodsDescription;
	}
	public void setGoodsDescription(String goodsDescription) {
		this.goodsDescription = goodsDescription;
	}

	
	@Override
	public boolean equals(Object o) {
		
		if(o == null || o.getClass() != this.getClass()){
			return false;
		}
		
		if(o == this){
			return true;
		}
		
		Goods goods = (Goods) o;
		
		if(id == null ? goods.id == null : this.id.equals(goods.id)){
			return true;
		}
		
		
		return false;
	}
	
	/*@Override
	public int hashCode() {
		//return this.id.hashCode();
		return 
	}*/
	
}



5.多对多关联
多对多关联用manyToMany来映射,这里用学生和选的课程,它们是多对多的关联,多对对
关联通常需要一张中间表,这个表就两字段,学生id和课程id(这里中间表就两个字段)
在java中用两set集合来表示
student 映射文件

  <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping >
        <class name="com.own.model.Student"  table="student"  dynamic-update="true"  dynamic-insert="true" >
           <id name="studentId"  column="id" >
              <generator class="native"></generator>
           </id>
            <property name="studentName"  column="student_name"   ></property>  
            <property name="studentNum"  column="student_no" type="string"  ></property> 
            <set name="cosrseSet"    table="student_course"  >
           <!--  引用当前实体主键的外键名称   -->   
          <key  column="student_id"   />
              <many-to-many column="course_id"  class="com.own.model.Course"   ></many-to-many>
            </set>
        </class>
</hibernate-mapping>

course映射文件
  <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
      "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping   >
        <class name="com.own.model.Course"  table="course"  dynamic-update="true"     dynamic-insert="true" >
           <id name="courseId"  column="id" >
              <generator class="native"></generator>
           </id>
            <property name="courseName"  column="course_name"   ></property>  
            <property name="courseNum"   column="course_no"  ></property> 
            
          <set name="studentSet"  inverse="true"  cascade="all"    table="student_course"    >
              <key  column="course_id"   />
              <many-to-many column="student_id"  class="com.own.model.Student"   ></many-to-many>
           </set>
        </class>
</hibernate-mapping>

jpa元数据
Student实体
  package com.own.model;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
@Entity
@Table(name="student")
public class Student implements Serializable {
	
	private static final long serialVersionUID = 1L;
	private Integer studentId;
	private String studentName;
	private String studentNum;
	private Set<Course> cosrseSet = new HashSet<Course>();
	@ManyToMany
	@JoinTable(name="student_course",joinColumns={@JoinColumn(name="student_id")},
			   inverseJoinColumns={@JoinColumn(name="course_id")})
	public Set<Course> getCosrseSet() {
		return cosrseSet;
	}
	public void setCosrseSet(Set<Course> cosrseSet) {
		this.cosrseSet = cosrseSet;
	}
    
	@Id
	@GeneratedValue
	@Column(name="id")
	public Integer getStudentId() {
		return studentId;
	}
	public void setStudentId(Integer studentId) {
		this.studentId = studentId;
	}
	
	@Column(name="student_name")
	public String getStudentName() {
		return studentName;
	}
	public void setStudentName(String studentName) {
		this.studentName = studentName;
	}
	
	@Column(name="student_no")
	public String getStudentNum() {
		return studentNum;
	}
	public void setStudentNum(String studentNum) {
		this.studentNum = studentNum;
	}

}


Course实体
  package com.own.model;

import java.io.Serializable;

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

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
@Entity
@Table(name="course")
public class Course implements Serializable {
	private static final long serialVersionUID = 1L;
	private Integer courseId;
	private String courseNum;
	private String courseName;
	private Set<Student> studentSet = new HashSet<Student>();
	
	@ManyToMany(mappedBy="cosrseSet")
	public Set<Student> getStudentSet() {
		return studentSet;
	}
	public void setStudentSet(Set<Student> studentSet) {
		this.studentSet = studentSet;
	}
	@Id
	@GeneratedValue
	@Column(name="id")
	public Integer getCourseId() {
		return courseId;
	}
	public void setCourseId(Integer courseId) {
		this.courseId = courseId;
	}
	
	@Column(name="course_no")
	public String getCourseNum() {
		return courseNum;
	}
	public void setCourseNum(String courseNum) {
		this.courseNum = courseNum;
	}
	
	@Column(name="course_name")
	public String getCourseName() {
		return courseName;
	}
	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}

  /* @Override
   public boolean equals(Object o) {
	 if(o == null || o.getClass() != Course.class){
		 return false;
	 }
	     
	 if(o == this){
		 return true; 
	 }
	   
	 Course another = (Course)o;
	 if(courseId == null ? another.courseId == null : courseId.equals(another.courseId)){
		 return true;
	 }
	 
	 return  false;
	
  }

  @Override
   public int hashCode() {
	return super.hashCode();
	 // return 1;
  }*/
   
	
}


在多对对关联的情况下,用的是set集合,实体要实现hashcode和equals,不然在更新关联表的时候会更新不了,比如学生不在选择这门课程,从set集合中remove掉这个课程,然后更新这个学生实体,代码如下,在不实现hashcode和equals更新不会成功,只有实现了才可以,hibernate返回了自己写的集合,PersistenceSet而不是HashSet,这也是为什么我们在实体中写set接口,不能写HashSet ... = new HashSet,要用 Set ... = new HashSet 。
  	tc = session.beginTransaction();
		    Student s1 = (Student) session.get(Student.class,9) ;
            Course c = new Course();
           s1.getCosrseSet().remove(c);
           session.update(s1);//更新学生的选课
			tc.commit();


最后讲解一下cascade和inverse这两个属性,刚用hibernate的时候也比较不理解,首先这两个属性没有任何关系,cascade表示级联,就是被关联的一段,比如cascade='save-update',级联保存和更新,在设置了cascade的端,保存这个对象,会一并保存关联的一端,省去了我们写保存关联端的代码,inverse表示有谁来维护关联,在一段设置inverse=true,则有关联对来维护关联关系,比如上面的例子,在course端设置了inverse=true,则有student来维护中间表,只有当插入student的时候,才向中间表插入数据,如果都设置inverse=true则会插入重复数据,如果不设置,则会出错,在jpa元数据注解中 用mappedBy来表示有那方来维护关联关系
分享到:
评论
1 楼 L504919167 2018-02-21  
有个问题,“1.一对一主键关联 ”的时候。
使用XML方式配置时,会生成一个外键约束,即:从表的主键->主表的主键;
使用注解配置时,则不会生成这个外键约束。
大神有什么解决办法吗?

相关推荐

    Hibernate+JPA注解教程.doc

    【Hibernate+JPA注解教程】 本教程将详细介绍如何在Java开发环境中利用Hibernate和Java Persistence API(JPA)的注解进行数据持久化操作。首先,我们需要了解开发所需的环境和工具,包括MyEclipse 8.5(内含...

    hibernate-jpa-2.1-api-1.0.0.final.jar.zip

    总的来说,`hibernate-jpa-2.1-api-1.0.0.final.jar`为开发者提供了丰富的JPA 2.1特性的实现,使得在Java项目中使用Hibernate进行数据库操作变得更加便捷和标准化。通过深入理解和熟练运用这个API,我们可以构建出...

    spring3.0 mvc+hibernate3.6 +jpa 注解实例

    在本实例中,我们探讨的是一个基于Spring 3.0、Hibernate 3.6和Java Persistence API (JPA) 的集成应用,其中充分利用了注解来简化开发过程。这是一个适用于初学者和经验丰富的开发者深入了解这些技术如何协同工作的...

    hibernate基于jpa注解说明[参考].pdf

    本篇文章将详细解释在Hibernate中基于JPA注解的使用方法。 1. **@Entity(name="EntityName")**:这个注解用于声明一个Java类作为数据库中的实体,"EntityName"是可选的,如果不指定,那么实体的名称默认为类名。每...

    hibernate-jpa.jar

    使用Hibernate JPA,开发者可以利用注解驱动的编程模型,减少代码量,同时通过ORM机制,使得业务逻辑和数据访问层更加分离,提高了代码的可读性和可维护性。然而,需要注意的是,虽然ORM工具带来了便利,但也可能...

    hibernate_ jpa.jar

    总结来说,Hibernate JPA为Java开发人员提供了强大且灵活的ORM工具,通过简化数据库操作,使得开发者能更专注于业务逻辑。正确理解和熟练使用Hibernate JPA,对于构建高效、可维护的Java应用至关重要。在实际项目中...

    hibernate-jpa

    **标题:“Hibernate-JPA”** ...总结来说,“Hibernate-JPA”是Java开发中一个强大且易用的数据持久化工具,通过遵循JPA规范,它为开发者提供了高效、灵活的数据库操作手段,降低了开发复杂度,提升了项目质量。

    5.Hibernate 05 Hibernate结合JPA1

    总结,结合Hibernate和JPA可以充分利用JPA的规范优势,同时利用Hibernate的强大功能。通过JPA,开发者可以编写更加简洁、面向对象的代码,减少对底层数据库的依赖,提高开发效率和代码可维护性。而Hibernate作为JPA...

    JPA实体关联(hibernate实现)

    理解并熟练掌握这些关联映射是JPA和Hibernate开发的基础,有助于提升数据库操作的效率和灵活性。通过深入研究官方文档、实践项目以及参考像iteye博客中提供的资源,开发者可以进一步提升在JPA实体关联方面的专业技能...

    hibernate-jpa-2.1-api 1.0.0.Final API

    开发者可以依赖这份文档理解Hibernate JPA 2.1的用法、方法和功能。同时,由于文档可能存在错误,用户被建议自行检查并修改HTML文件以确保准确性。这表明文档可能是HTML格式,方便直接在浏览器中查看。 **标签解析...

    hibernate-jpa学习

    总结,Hibernate-JPA作为Java ORM的重要实现,为开发者提供了丰富的功能和灵活的工具,使得数据库操作变得简单而高效。通过深入学习其原理和实践应用,开发者能够更好地应对复杂的业务场景,提升软件系统的质量和可...

    SpringMVC+JPA 注解开发 maven

    本项目提供了完整的配置代码,并有详细注释,非常适合初学者了解和学习SpringMVC+JPA的注解开发方式,以及如何结合Maven进行项目管理。通过实践这个项目,你可以深入理解Web应用开发的流程,掌握这些技术的使用。

    jpa/hibernate继承注解

    在Java Persistence API (JPA) 和 Hibernate ORM 框架中,继承注解是用于处理对象关系映射(ORM)中的类继承结构的关键概念。这些注解帮助开发者将数据库表的设计与面向对象的代码结构相匹配,使得在复杂的业务场景...

    JPA学习笔记-EJB-04JPA关联映射总结

    在实体类代码中,我们可以看到如何使用JPA注解来实现这些关联映射。例如,在UxAdmin类中,使用`@ManyToMany`注解定义了与UxRole的多对多关系,`@JoinTable`注解指定了中间表的名称和外键列。类似地,UxRole类中也...

    Hibernate annotation JPA 一对多,多对多

    在本主题中,我们将深入探讨使用Hibernate注解来实现JPA的一对多、多对多和多对一的关系映射。 1. **一对多关系**: 在现实世界中,一个老师可以教多个学生,或者一个班级可以包含多个学生,这就是典型的一对多...

Global site tag (gtag.js) - Google Analytics