eclipse之SSH配置hibernate【三】
配置hibernate,没有和spring整合,可以看成独立的部分。
在src下创建hibernate配置文件,hibernate.cfg.xml。主要是sql连接相关配置。
<?xml version='1.0' encoding='utf-8'?>
<!--
~ Hibernate, Relational Persistence for Idiomatic Java
~
~ License: GNU Lesser General Public License (LGPL), version 2.1 or later.
~ See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
-->
<!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> <!-- Database connection settings -->
<property name="connection.driver_class">com.mysql.jdbc.Driver </property>
<property name="connection.url">jdbc:mysql://localhost:3306/cmsadmin</property>
<property name="connection.username">root</property>
<property name="connection.password">123456</property> <!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect </property> <!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property> <mapping resource="com/awu/models/user.hbm.xml"/>
</session-factory> </hibernate-configuration>
Tip:<mapping resource="com/awu/models/user.hbm.xml"/> 是entity的映射文件。一般创建在src的目录下即可。内容如:
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping package="com.awu.models">
<class name="User" table="user">
<id name="userid" type="string">
</id>
<property name="username" type="string"></property>
<property name="pwd" type="string"></property>
<property name="creator" type="string"></property>
<property name="createtime" type="date"></property>
<property name="updater" type="string"></property>
<property name="updatetime" type="date"></property>
<property name="isenabled" type="int"></property>
</class>
</hibernate-mapping>
使用hibernate示例代码:
Configuration configuration = new Configuration().configure();
SessionFactory factory = configuration.buildSessionFactory();
Session session = null;
try{
session = factory.openSession();
session.beginTransaction();
// ArrayList<User> result = (ArrayList<User>) session.createQuery("from User").list();
session.createQuery("from User").uniqueResult();
System.out.println(session.get(User.class,"402895da5a6def38015a6def39d80000").getUsername()); session.getTransaction().commit();
}catch (Exception e) {
System.out.println(e.getMessage());
session.getTransaction().rollback();
}finally {
if(session != null){
if(session.isOpen())
session.close();
}
}
hibernate相关的jar。
- antlr-2.7.7.jar
- classmate-1.3.0.jar
- dom4j-1.6.1.jar
- hibernate-commons-annotations-5.0.1.Final.jar
- hibernate-core-5.2.8.Final.jar
- hibernate-jpa-2.1-api-1.0.0.Final.jar
- jandex-2.0.3.Final.jar
- javassist-3.20.0-GA.jar
- jboss-logging-3.3.0.Final.jar
- jboss-transaction-api_1.2_spec-1.0.1.Final.jar
mysql连接库:
- mysql-connector-java-5.1.40-bin.jar
eclipse之SSH配置hibernate【三】的更多相关文章
- 【SSH】——Hibernate三种状态之间的转化
Hibernate的三种状态为:transient.persistent和detached.对这三种状态的理解可以结合Session缓存,在Session缓存中的状态为persistent,另外两种不 ...
- eclipse之SSH配置struts2【一】 (使用版本 2.3.24.1)
eclipse创建Dynamic web project,勾选生成web.xml,创建index.jsp页面,tomcat部署能正常运行.进行下一步struts配置. web.xml中添加配置,配置在 ...
- eclipse之SSH配置spring【二】
第一篇中配置struts完成(http://www.cnblogs.com/dev2007/p/6475074.html),在此基础上,继续配置spring. web.xml中增加listener,依 ...
- Eclipse搭建SSH(Struts2+Spring+Hibernate)框架教程
| 版权声明:本文为博主原创文章,未经博主允许不得转载. 前言 确实,刚创博客,对于这个陌生的东西还是有些许淡然.这是我的第一篇博文,希望能给你们有帮助,这就是我最大的乐趣! 好了下面进入正题: SS ...
- 用eclipse搭建SSH(struts+spring+hibernate)框架
声明: 本文是个人对ssh框架的学习.理解而编辑出来的,可能有不足之处,请大家谅解,但希望能帮助到大家,一起探讨,一起学习! Struts + Spring + Hibernate三者各自的特点都是什 ...
- eclipse中SSH三大框架环境搭建<三>
相关链接: eclipse中SSH三大框架环境搭建<一> eclipse中SSH三大框架环境搭建<二> 引言:通过上两篇文章我们已经可以掌握struts2和spring的环境的 ...
- ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存
ssh整合hibernate 使用spring管理hibernate二级缓存,配置hibernate4.0以上二级缓存 hibernate : Hibernate是一个持久层框架,经常访问物理数据库 ...
- SSH整合,applicationContext.xml中配置hibernate映射文件问题
今天在applicationContext.xml中配置sessionFactory时遇到了各种头疼的问题,现在总结一下: 1.<property name="mappingDirec ...
- jenkins SSH登录 Git配置(通过eclipse生成SSH 密钥)
1.通过eclipse生成SSH 密钥 菜单栏的windows-->preferences-->General-->Network Connections-->SSH2--&g ...
随机推荐
- 目标检测:SSD算法详解
一些概念 True Predict True postive False postive 预测为正类 False negivate True negivate 预测为负类 真实为 ...
- Python-SyntaxError: invalid syntax
Error: SyntaxError: invalid syntax Where? 运行Python代码时候,提示错误 Way? Python def class if elif for while ...
- Harmony OS 开发避坑指南——源码下载和编译
Harmony OS 开发避坑指南--源码下载和编译 本文介绍了如何下载鸿蒙系统源码,如何一次性配置可以编译三个目标平台(Hi3516,Hi3518和Hi3861)的编译环境,以及如何将源码编译为三个 ...
- .NET 是信息技术应用创新产业重要参与者
今天是国庆节,也是中秋节,月满中秋,举国欢庆,在这里祝各位开发者中秋国庆快乐. 放假在家就想把这几年对于.NET发展相关生态做个梳理,写一篇文章来总结一下这两年从腾讯出来自己创业,推动.NET在国内的 ...
- C 多态 RT-Thread
// RT-Thread对象模型采用结构封装中使用指针的形式达到面向对象中多态的效果,例如: // 抽象父类 #include <stdio.h> #include <assert. ...
- 【Java】socket编程,输入输出中的问题
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); PrintWri ...
- Java知识系统回顾整理01基础01第一个程序03Eclipse下载安装
Eclipse是最流行的java 集成开发环境IDE(Integrated Development Environment) 下载安装Eclipse两种方式 一.方式1:Eclipse官网下载安装 链 ...
- 序列化的JavaScript
下载 序列化的JavaScript序列化的JavaScript 将JavaScript序列化为包含正则表达式.日期和函数的JSON超集. 概述 这个包中的代码最初是作为表示状态的内部模块.为了扩展它的 ...
- Windows 10 系统 - business editions 和 consumer editions 的区别
我们在使用微软操作系统(Windows 10)的时候,因为系统版本太多导致我们不知道如何选择.对于 Windows 10 系统,应该下载安装 business 还是 consumer 版本这个问题,这 ...
- 2018年10月份编程语言排行榜(来自TIOBE Index for October 2018)
TIOBE Index for October 2018 from:https://www.tiobe.com/tiobe-index// October Headline: Swift is kno ...