Hibernate 注解时 hibernate.hbm.xml的配置方法 以及与SSH整合里的配置方式
①纯Hibernate开发:
当你在Bean中写入注解后,需要告诉hibernate哪些类使用了注解。
方法是在hibernate.hbm.xml文件中配置
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <!-- 这些信息都可以在官方目录下的properties文件中找到 -->
<hibernate-configuration>
<!-- 告诉hibernate怎么连接数据库,底层还是用jdbc访问的 -->
<session-factory>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.url">
jdbc:mysql:///hibernatetest
</property>
<property name="connection.username">root</property>
<property name="connection.password">123</property> <property name="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</property>
<!-- hibernate启动的时候将已有的表重新覆盖,使用create的话 -->
<property name="hbm2ddl.auto">create</property>
<!-- 当hibernate运行时产生sql语句 -->
<property name="show_sql">true</property> <mapping class="com.hyy.hibernate.one_to_many.domain.Department"/>
<mapping class="com.hyy.hibernate.one_to_many.domain.Employee"/>
</session-factory>
</hibernate-configuration>
即上述xml文件中带下划线部分。
②如果是SSH整合框架中:
<?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:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<!-- 扫描 -->
<context:component-scan base-package="com.hlcg"></context:component-scan> <!-- 配置数据源 -->
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
destroy-method="close">
<property name="driverClass" value="org.gjt.mm.mysql.Driver"/>
<property name="jdbcUrl" value="jdbc:mysql://localhost:3306/hlcg?useUnicode=true&characterEncoding=UTF-8"/>
<property name="user" value="root"/>
<property name="password" value="123"/>
<!--初始化时获取的连接数,取值应该在最大和最小之间。默认:3-->
<property name="initialPoolSize" value="15"/>
<property name="minPoolSize" value="10"/>
<!-- 连接池中保留的最大连接数,默认:15 -->
<property name="maxPoolSize" value="80"/>
<!-- 最大空闲时间,60秒内未使用则连接被丢弃。若0则永远不丢弃,默认:0 -->
<property name="maxIdleTime" value="30"/>
<!-- 当连接池的连接耗尽的时候,c3p0一次同时获取的连接数,默认:3 -->
<property name="acquireIncrement" value="5"/>
<!-- 每60秒检查连接池中所有空闲连接,默认:0 -->
<property name="idleConnectionTestPeriod" value="30"/>
</bean> <!-- 配置sessionFactory -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<!--这里是存放以XML形式映射实体的xml文件路径-->
</list>
</property> <property name="hibernateProperties">
<value>
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
hibernate.hbm2ddl.auto=update
show_sql=true
format_sql=true
cache.use_second_level_cache=true
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.EhCacheRegionFactory
hibernate.cache.use_query_cache=true
</value>
</property> <property name="packagesToScan" value="com.hlcg.main.bean"/>
</bean>
</beans>
以上下划线部分配置Hibernate注解。
Hibernate 注解时 hibernate.hbm.xml的配置方法 以及与SSH整合里的配置方式的更多相关文章
- 使用oracle数据库和MySQL数据库时hibernate的映射文件.hbm.xml的不同
假设是使用oracle数据库.那么hibernate的映射文件.hbm.xml例如以下: <id name="xuehao" column="xuehao" ...
- 通过MyEclipse生成Hibernate类文件和hbm.xml文件,或者annotation文件
1. 前言 很多人都在使用myEclipse,很多公司也都使用hibernate框架,老版本的hibernate中,由于没有annotation,我们需要写两个文件来维护表与对象的关系,写一个类, ...
- 错误/异常:org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/shore/model/Husband.hbm.xml 的解决方法
1.错误/异常视图 错误/异常描述:无效的映射异常,无法从xxxxx资源中解析映射文档 2.解决方法 出现这个异常,一般情况下是包名写错了.改回来即可. 看报错/异常的第一行,最后面,会提示你 ...
- Spring,Hibernate 集成解决多hbm.xml文件繁多的方案
开发一个大一点的项目有很多的hbm.xml文件,有时候上百个也不稀奇,如果用 <property name="mappingLocations"> <list&g ...
- springboot整合mybatis时无法读取xml文件解决方法(必读)
转 http://baijiahao.baidu.com/s?id=1588136004120071836&wfr=spider&for=pc 在springboot整合myba ...
- vs2017 项目生成时不产生xml文件的方法
在项目.csproj文件 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' & ...
- centos下网络配置方法(网关、dns、ip地址配置)
本文介绍了centos网络配置的方法,centos网络配置主要包括dns.网关.IP地址: 1.IP地址配置: /etc/sysconfig/network-scripts/ifcfg-eth0 2. ...
- hibernate注解的简单应用
注解代替了我们用的*.hbm.xml文件.简少了我们的代码量:应用简单. @Override 用途:重写父类的同名方法 单元测试注解 @Test 用途:用于测试 @Before 用途:单测方法走之前执 ...
- 关于hibernate注解的简单应用
@Override 用途:重写父类的同名方法 单元测试注解 @Test 用途:用于测试 @Before 用途:单测方法走之前执行 @After 用途:单测方法走之后执行 注解的目标:替换小配置.替换h ...
随机推荐
- 基于u盘安装centos6.0
本人在dell笔记本上尝试安装centos6.0,与win7形成双系统,安装过程如下: 1.使用ultraliso制作u盘启动盘,启动盘以centos6.0的映像文件为源头制作: 2.制作完成后,删除 ...
- ASP与ASP.NET转换Session数据桥的应用
背景: 现有公司的产品OA是采用ASP早先的技术开发,需要与目前最新的ASP.NET产品进行数据交互的应用.现有的ASP应用程序往往采用“ASP Sessions”,这是一种经典的ASP内置模式,即允 ...
- 20160314 Servlet 入门
一.Servlet 1.sun提供的一种动态web资源开发技术.本质上就是一段java小程序.可以将Servlet加入到Servlet容器中运行. *Servlet容器 -- 能够运行Servlet的 ...
- Android网络对讲机的实现
上个星期公司给出了一个项目需求,做一个基于socket通讯协议的网络对讲机.于是在项目开始前计划了一下基本的实现流程. 1.从手机麦中采集音频数据:2.将PCM音频数据编码压缩:3.将压缩好的音频通过 ...
- 怎样区分JQuery对象和Dom对象 常用的写法
第一步,http://www.k99k.com/jQuery_getting_started.html 第二步,新手先仔细得全部看一遍jQuery的选择器,很重要!!! (http://shawphy ...
- OC - 2.OC基础知识介绍
一.基础语法 1> OC语言和C语言 C语言是面向过程的语言,OC语言是面向对象的语言 OC语言继承了C语言,并增加了面向对象的思想 以下内容只介绍OC语言与C语言的不同之处 2> 关键字 ...
- 【转帖】客户端通过 HTTP 请求和响应 的 Header 信息总结
请求Header原帖地址:http://technique-digest.iteye.com/blog/1174581 响应Header原帖地址:http://blog.pfan.cn/hurongl ...
- Top命令查看内存
c 切换显示命令名称和完整命令行. M 根据驻留内存大小进行排序 第四行:内存状态 8306544k total — 物理内存总量(8GB) 7775876k used — 使用中的内存总量(7.7G ...
- 选择第n小的元素之python实现源码
def partition(A, p, r): j = p+1 for i in range(p+1, r+1): if(A[i] < A[p]): tmp = A[i] A[i] = A[j] ...
- Plugin 'FEDERATED' is disabled 或 1067错误 启动错误与“服务 mysql 意外停止”解决方法
MYSQL启动报1067错误,系统日志中是“服务 mysql 意外停止” Mysql日志中则是:“Plugin 'FEDERATED' is disabled” 网我在网上找到解决方案:1.在MY.I ...