hibernate入门
什么是hibernate
hibernate是一个ORM框架/持久层框架
ORM (Object Relational Mapping):对象关系映射
hibernate的作用:
既对象与关系型数据库之间的映射管理框架
可以代替我们来操作数据库
优势:
跨数据库的无缝移植(SqlServer、Oracle、MySql)
Maven和hibernate结合项目搭建
第一步添加hibernate相关依赖(pom.xml)
在链接地址搜索hibernate并选择Hibernate Core Relocation
然后我用的是5.2.12.Final的版本
然后copy以下字符,这里将配置代码放在下面方便使用
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.12.Final</version>
</dependency>
然后将它放到pom.xml文件里
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.solar</groupId>
<artifactId>maven</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>maven Maven Webapp</name>
<url>http://maven.apache.org</url>
<properties>
<servlet.version>4.0.1</servlet.version>
<junit.version>3.8.1</junit.version>
<mysql.version>5.1.44</mysql.version>
<jstl.version>1.2</jstl.version>
<hibernate.version>5.2.12.Final</hibernate.version>
</properties>
<dependencies>
<!-- hibernate -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${
hibernate.version}</version>
</dependency>
<!-- jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>${
jstl.version}</version>
</dependency>
<!-- junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${
junit.version}</version>
<scope>provided</scope>
</dependency>
<!-- servlet -->
<dependency>