①纯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&amp;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整合里的配置方式的更多相关文章

  1. 使用oracle数据库和MySQL数据库时hibernate的映射文件.hbm.xml的不同

    假设是使用oracle数据库.那么hibernate的映射文件.hbm.xml例如以下: <id name="xuehao" column="xuehao" ...

  2. 通过MyEclipse生成Hibernate类文件和hbm.xml文件,或者annotation文件

    1.   前言 很多人都在使用myEclipse,很多公司也都使用hibernate框架,老版本的hibernate中,由于没有annotation,我们需要写两个文件来维护表与对象的关系,写一个类, ...

  3. 错误/异常:org.hibernate.InvalidMappingException: Could not parse mapping document from resource com/shore/model/Husband.hbm.xml 的解决方法

    1.错误/异常视图 错误/异常描述:无效的映射异常,无法从xxxxx资源中解析映射文档 2.解决方法     出现这个异常,一般情况下是包名写错了.改回来即可. 看报错/异常的第一行,最后面,会提示你 ...

  4. Spring,Hibernate 集成解决多hbm.xml文件繁多的方案

    开发一个大一点的项目有很多的hbm.xml文件,有时候上百个也不稀奇,如果用 <property name="mappingLocations"> <list&g ...

  5. springboot整合mybatis时无法读取xml文件解决方法(必读)

    转    http://baijiahao.baidu.com/s?id=1588136004120071836&wfr=spider&for=pc 在springboot整合myba ...

  6. vs2017 项目生成时不产生xml文件的方法

    在项目.csproj文件 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' & ...

  7. centos下网络配置方法(网关、dns、ip地址配置)

    本文介绍了centos网络配置的方法,centos网络配置主要包括dns.网关.IP地址: 1.IP地址配置: /etc/sysconfig/network-scripts/ifcfg-eth0 2. ...

  8. hibernate注解的简单应用

    注解代替了我们用的*.hbm.xml文件.简少了我们的代码量:应用简单. @Override 用途:重写父类的同名方法 单元测试注解 @Test 用途:用于测试 @Before 用途:单测方法走之前执 ...

  9. 关于hibernate注解的简单应用

    @Override 用途:重写父类的同名方法 单元测试注解 @Test 用途:用于测试 @Before 用途:单测方法走之前执行 @After 用途:单测方法走之后执行 注解的目标:替换小配置.替换h ...

随机推荐

  1. IEnumerable 和 IQueryable

    共有两组 LINQ 标准查询运算符,一组在类型为 IEnumerable<T> 的对象上运行,另一组在类型为 IQueryable<T> 的对象上运行.构成每组运算符的方法分别 ...

  2. Java 计算文件大小

    long available = (long)getAttachmentContent(att.getId()).available();   public static String bytesTr ...

  3. 多版本uboot命令行分析

    1.1.6 经典版本: 1.uboot第二阶段第一个函数void start_armboot (void),一路gd参数设置.设备初始化.控制台初始化.端口初始化,最后到main_loop ()命令行 ...

  4. Nullable类型和HashSet<T>集合

    今天接触到两个新的类型,查了一下才发现它们已经出现好久了,特作一下标记 Nullable结构 在System命名空间下,在 .NET Framework 2.0 版中是新增的:用它定义的值类型的对象与 ...

  5. mysql - 启动错误InnoDB: mmap(137363456 bytes) failed; errno 12

    [zsm]下午mysql出现了问题,很纠结,最后找到了原因,原因是内存不够用: 查看内存显示   [root@AY1305070924544 /]# free -m              tota ...

  6. Js~数组的操作push,pop,shift,unshift

    说几个概念: 队列:先进先出堆栈:先进后出 shift:从集合中把第一个元素删除,返回这个元素的值pop:从集合中把最后一个元素删除,返回这个元素的值 unshift:在集合开头添加一个或者多个元素, ...

  7. asp.net mvc Remote远程验证

    1.Model实体 /// <summary> /// 课程编号 /// </summary> [MaxLength()] [Remote("IsUnique_Ava ...

  8. ios 从微信返回自己的app

    有这样一个需求.从我们自己的app分享内容到微信.点击分享内容返回到我们自己的app.(新浪微博的内容分享到微信就是这样的) 前面一直百度,谷歌都没用.可能我用的方法跟他们不一样吧.而且他们的方法都比 ...

  9. 巧谈 GCD

    转载自:http://www.jianshu.com/p/665261814e24 谈到iOS多线程,一般都会谈到四种方式:pthread.NSThread.GCD和NSOperation.其中,苹果 ...

  10. frame 第三节

    1.准备3个文件 main.html: <html> <head> <title>框架</title> </head> <frames ...