一、最原始的hibernate框架的配置(不整合spring)

一、首先需要引入相关jar包,这里是一个maven项目

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/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>

	<groupId>com.ge</groupId>
	<artifactId>hibernatexml</artifactId>
	<version>1.0</version>
	<packaging>jar</packaging>

	<name>hibernatexml</name>
	<url>http://maven.apache.org</url>

	<properties>
		<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
		<junit.version>4.12</junit.version>
		<log4j.version>1.2.17</log4j.version>
		<spring.version>4.3.14.RELEASE</spring.version>
		<hibernate.version>4.3.11.Final</hibernate.version>
		<mysql.version>5.1.38</mysql.version>
	</properties>

 
	<dependencies>

		<!-- 导入spring容器相关JAR文件 -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-context</artifactId>
			<version>${spring.version}</version>
		</dependency>
		
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-test</artifactId>
			<version>${spring.version}</version>
		</dependency>

		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>${junit.version}</version>
			<scope>test</scope>
		</dependency>

		<dependency>
			<groupId>log4j</groupId>
			<artifactId>log4j</artifactId>
	 		<version>${log4j.version}</version>
		</dependency>

		<!-- 导入hibernate持久层框架JAR包 -->
		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-core</artifactId>
			<version>${hibernate.version}</version>
		</dependency>
 

		<!-- 导入hibernate持久层框架的C3P0连接池JAR包 -->

		<dependency>
			<groupId>org.hibernate</groupId>
			<artifactId>hibernate-c3p0</artifactId>
			<version>${hibernate.version}</version>
		</dependency>

		<!-- 导入JDBC的JAR包 -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>${mysql.version}</version>
		</dependency>

	</dependencies>




	<build>
		<pluginManagement>

			<!-- 配置maven 在构建项目时,采用相关插件 -->
			<plugins>
				<plugin>
					<groupId>org.apache.maven.plugins</groupId>
					<artifactId>maven-compiler-plugin</artifactId>
					<version>3.8.0</version>
					<configuration>
						<source>1.8</source>
						<target>1.8</target>
					</configuration>
				</plugin>


			</plugins>
		</pluginManagement>
	</build>

</project>

 

二、开启spring的自动扫描功能

applicationContext.xml配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans
						http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
						http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/aop 
        http://www.springframework.org/schema/aop/spring-aop.xsd
         http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd">

<!--开启spring的自动扫描功能 -->
	<context:component-scan base-package="com.ge.hibernatexml"></context:component-scan>

</beans>

 

三、配置hibernate的基本连接信息

hibernate.cfg.xml配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
	"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
	"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
	<session-factory>

		<!-- 定义数据库方言 -->
		<property name="dialect">
			org.hibernate.dialect.MySQLDialect
			<!-- org.hibernate.dialect.SQLServerDialect -->
			<!-- org.hibernate.dialect.OracleDialect -->
		</property>

		<!-- 配置JDBC连接数据库的4个最基本的元素 -->
		<property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
		<property name="connection.url">jdbc:mysql://127.0.0.1:3306/test?characterEncoding=UTF-8</property>
		<property name="connection.username">root</property>
		<property name="connection.password">1234</property>

		<!-- 使用C3P0作为连接池技术 -->
		<property name="hibernate.connection.provider_class">org.hibernate.c3p0.internal.C3P0ConnectionProvider</property>
		<!-- 配置C3P0连接池中,最大连接数为10 -->
		<property name="hibernate.c3p0.max_size">10</property>
		<!-- 指定连接池最小连接数 -->
		<property name="hibernate.c3p0.min_size">1</property>
		<!-- 指定连接池里连接超时时长 -->
		<property name="hibernate.c3p0.timeout">5000</property>
		<!-- 指定连接池里最大缓存多少个PreparedStatement对象 -->
		<property name="hibernate.c3p0.max_statements">100</property>
		<!-- 指定校验空闲连接的时间为:半分钟 -->
		<property name="hibernate.c3p0.idle_test_period">30000</property>
		<!-- 当连接不足时,需要再次获取的连接数量 -->
		<property name="hibernate.c3p0.acquire_increment">5</property>
		
		<!--显示SQL语句-->
		<property name="show_sql">true</property>
		<!--以格式良好的方式显示SQL语句-->
		<property name="format_sql">true</property>
		
		<!-- 如果使用resource,从com包开始写,引入对象与数据库关联的配置文件,参见下面:二   引入多个对象配置文件就在后面追加就可以了-->
		<mapping resource="com/ge/hibernatexml/xml/UserBean.hbm.xml"/>
    <!--<mapping resource="com/gezhi/hibernatexml/xml/TeacherBean.hbm.xml"/>-->

	</session-factory>


</hibernate-configuration>

 

二、hibernate中关于对象与数据库中数据的对应关系配置文件的编写(xx.hbm.xml配置文件的编写):https://blog.csdn.net/IT_CREATE/article/details/87370051

Python网络爬虫与推荐算法新闻推荐平台:网络爬虫:通过Python实现新浪新闻的爬取,可爬取新闻页面上的标题、文本、图片、视频链接(保留排版) 推荐算法:权重衰减+标签推荐+区域推荐+热点推荐.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值