myeclipse数据库逆向hibernate教程 -
(导入自己的博客园的文章)
myeclipse数据库逆向hibernate教程
.首先我们的准备
1.项目
2.数据库
![](/assets/blank.gif)
![](/assets/blank.gif)
1 /*2 Navicat MySQL Data Transfer3 4 Source Server : mysql1235 Source Server Version : 506246 Source Host : localhost:33067 Source Database : inverse8 9 Target Server Type : MYSQL 10 Target Server Version : 50624 11 File Encoding : 65001 12 13 Date: 2016-06-30 15:46:41 14 */ 15 16 SET FOREIGN_KEY_CHECKS=0; 17 18 -- ---------------------------- 19 -- Table structure for users 20 -- ---------------------------- 21 DROP TABLE IF EXISTS `users`; 22 CREATE TABLE `users` ( 23 `id` int(4) NOT NULL AUTO_INCREMENT, 24 `name` varchar(20) DEFAULT NULL, 25 `content` varchar(100) DEFAULT NULL, 26 PRIMARY KEY (`id`) 27 ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
现在准备好了以上空项目和表后,我们开始逆向工程第一步
1.文字不重要,看图
2.接下来我们来配置我们的hibernate核心jar包
右键我们的项目选择myeclipse–》 project facets–>install hibernate facet
3.现在我们回到从自带的DB开始
4.然后就这样就可以了,让我们来看看我们反向的实体类
5.这样就好了,谢谢您的观看,大家一起学习
附上配置一份
hibernate.cfg.xml
![](/assets/blank.gif)
![](/assets/blank.gif)
<?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"> <!-- Generated by MyEclipse Hibernate Tools. --> <hibernate-configuration><session-factory><property name="dialect">org.hibernate.dialect.MySQLDialect</property><property name="connection.url">jdbc:mysql://localhost:3306/test</property><property name="connection.username">root</property><property name="connection.password">root</property><property name="connection.driver_class">com.mysql.jdbc.Driver</property><property name="myeclipse.connection.profile">test</property><mapping resource="com/hp/entity/Users.hbm.xml" /></session-factory></hibernate-configuration>
View Code
HibernateSessionFactory(工具类)
![](/assets/blank.gif)
![](/assets/blank.gif)
package com.hp.util;import org.hibernate.HibernateException; import org.hibernate.Session; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder;/*** Configures and provides access to Hibernate sessions, tied to the* current thread of execution. Follows the Thread Local Session* pattern, see {@link http://hibernate.org/42.html }.*/ public class HibernateSessionFactory {/** * Location of hibernate.cfg.xml file.* Location should be on the classpath as Hibernate uses * #resourceAsStream style lookup for its configuration file. * The default classpath location of the hibernate config file is * in the default package. Use #setConfigFile() to update * the location of the configuration file for the current session. */private static final ThreadLocal<Session> threadLocal = new ThreadLocal<Session>();private static org.hibernate.SessionFactory sessionFactory;private static Configuration configuration = new Configuration();private static ServiceRegistry serviceRegistry; static {try {configuration.configure();serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();sessionFactory = configuration.buildSessionFactory(serviceRegistry);} catch (Exception e) {System.err.println("%%%% Error Creating SessionFactory %%%%");e.printStackTrace();}}private HibernateSessionFactory() {}/*** Returns the ThreadLocal Session instance. Lazy initialize* the <code>SessionFactory</code> if needed.** @return Session* @throws HibernateException*/public static Session getSession() throws HibernateException {Session session = (Session) threadLocal.get();if (session == null || !session.isOpen()) {if (sessionFactory == null) {rebuildSessionFactory();}session = (sessionFactory != null) ? sessionFactory.openSession(): null;threadLocal.set(session);}return session;}/*** Rebuild hibernate session factory**/public static void rebuildSessionFactory() {try {configuration.configure();serviceRegistry = new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();sessionFactory = configuration.buildSessionFactory(serviceRegistry);} catch (Exception e) {System.err.println("%%%% Error Creating SessionFactory %%%%");e.printStackTrace();}}/*** Close the single hibernate session instance.** @throws HibernateException*/public static void closeSession() throws HibernateException {Session session = (Session) threadLocal.get();threadLocal.set(null);if (session != null) {session.close();}}/*** return session factory**/public static org.hibernate.SessionFactory getSessionFactory() {return sessionFactory;}/*** return hibernate configuration**/public static Configuration getConfiguration() {return configuration;}}
View Code
![](/assets/blank.gif)
![](/assets/blank.gif)
![](/assets/blank.gif)
关注 - 9
粉丝 - 0
» 下一篇:String判空效率比较
</div><div class="postDesc">posted @ <span id="post-date">2016-06-30 15:52</span> <a href="http://www.cnblogs.com/thehugo/">果果爱吃苹果</a> 阅读(<span id="post_view_count">1312</span>) 评论(<span id="post_comment_count">0</span>) <a href="https://i.cnblogs.com/EditPosts.aspx?postid=5630241" rel="nofollow">编辑</a> <a href="#" onclick="AddToWz(5630241);return false;">收藏</a></div>
</div>
myeclipse数据库逆向hibernate教程 -相关推荐
- eclipse从数据库逆向生成Hibernate实体类
2019独角兽企业重金招聘Python工程师标准>>> 做项目必然要先进行数据库表设计,然后根据数据库设计建立实体类(VO),这是理所当然的,但是到公司里做项目后,让我认识到,没有说 ...
- Eclipse实现hibernate反向工程:从数据库逆向生成实体类和hbm文件
转载请注明原文出处:http://blog.csdn.net/baidu_37107022/article/details/75205795 一.hibernate插件安装(已经安装的可以略过) 通过 ...
- myeclipse java可视化_使用MyEclipse可视化开发Hibernate实例
使用MyEclipse可视化开发Hibernate实例 2.7节的例子源代码在配套光盘sourcecode/workspace目录的chapter02_first项目中. 这个实例主要演示如何使用My ...
- 用MyEclipse自动生成hibernate映射文件和实体类
创建web工程,使用Hibernate的时候,在工程里一个一个创建实体类太麻烦,浪费时间,现在教大家如何用MyEclipse自动生成Hibernate映射文件及实体类 方法/步骤 1 创建数据库,创建 ...
- myeclipse自动生成hibernate映射文件的过程
在hibernate中,每个数据表对应的其实是一个实体类,每个实体类有一个对应的hbm.xml配置文件匹配,myeclipse中有个MyEclipse Database Explorer视图,它提供了 ...
- hibernate教程_Hibernate多对多教程
hibernate教程 介绍: 在本教程中,我们将学习使用Hibernate @ManyToMany注释定义和使用多对多实体关联. 上下文构建: 为了继续学习本教程,我们假设我们有两个实体– 雇员和资 ...
- Hibernate教程– ULTIMATE指南(PDF下载)
编者注:在本文中,我们提供了全面的Hibernate教程. Hibernate ORM(简称Hibernate)是一个对象关系映射框架,它有助于将面向对象的域模型转换为传统的关系数据库. Hibern ...
- myeclipse试用小记----Hibernate多对一双向关联(2)
myeclipse试用小记----Hibernate多对一双向关联(2) 在上篇文章"myeclipse试用小记----Hibernate多对一单向关联(1)"中,讲到了" ...
- Hibernate教程
Hibernate教程 最近我写了很多hibernate教程.Hibernate是当前市场上最好的Java ORM工具之一.所以这篇文章就像是hibernate教程和示例的所有帖子的索引.您可以按顺序 ...
最新文章
- R-error: 错误: nul character not allowed (line 1)
- 百度地图-解决新版百度定位失败问题
- 推荐系统笔记:无任何限制的矩阵分解
- k8s暴露nginx NodePort端口命令:expose暴露端口使用示例
- 用Python实现每天向女友表白一次,甜蜜暴击,最后终于被我追到手了!太厉害了!
- Qt Creator将应用程序部署到通用远程Linux设备
- Spark _16 _SparkUIMaster HA
- [html] 写一个三栏布局,中间固定,两边自适应(平均)
- DataFrame字符串之分割split()、清洗drop()、合并concat()、重新建立索引reset_index() - (Python)
- 关于索爱MT15i连接win7——MTP USB驱动无法安装
- 深度学习框架排行榜:找工作学TensorFlow,PyTorch搜索量逼近Keras
- 马尔科夫决策过程(MDP):汽车租赁问题
- 全国大学生电子设计竞赛(三)--线性电源设计
- rosetta_ddg 使用-rosetta 2020版
- 今日运势:“恶莫大于纵己之欲,祸莫大于言人之非“
- 天嵌TQ335X开发板学习-1
- 世纪龙校招java开发一、二面 面经
- 华为设备信息中心配置命令
- Mysql 多表联合更新
- 论文成功写作技巧之行之有效的写作从“结果”开始(下)