hibernate第一个例子-保存对象
发表于:2024-10-25 作者:千家信息网编辑
千家信息网最后更新 2024年10月25日,3.hibernate第一个例子-保存对象使用hibernate框架需要导入的jar包:antlr-2.7.6backport-util-concurrentc3p0-0.9.1commons-col
千家信息网最后更新 2024年10月25日hibernate第一个例子-保存对象
3.hibernate第一个例子-保存对象
使用hibernate框架需要导入的jar包:
antlr-2.7.6
backport-util-concurrent
c3p0-0.9.1
commons-collections-3.1 apache集合帮助的包
commons-logging-1.1.1日志
dom4j-1.6.1解析XML
ehcache-1.5.0缓存框架
hibernate3hibernate核心包
javassist-3.9.0.GA代理模式工具包,解决懒加载问题
jta-1.1
log4j日志
mysql-connector-java-5.1.10-bin数据库连接
slf4j-api-1.5.8
slf4j-log4j12
Person-持久化类
/** * 对象的序列化的作用:让对象在网络上传输,以二进制的形式传输 * Serializable标示接口 */public class Person implements Serializable{ private Long pid; private String pname; private String psex; set,get方法}
映射文件 Person.hbm.xml
配置文件 hibernate.cfg.xml
root root jdbc:mysql://localhost:3306/hibernateDay01 update true
测试
import org.hibernate.Session;import org.hibernate.SessionFactory;import org.hibernate.Transaction;import org.hibernate.cfg.Configuration;import org.junit.Test; public class PersonTest { @Test public void testCreateTable(){ //测试数据库中会不会根据持久化类和映射文件生成表 Configuration configuration = new Configuration(); configuration.configure(); //加载配置文件1、该配置文件必须放在classpath下2、名称必须为hibernate.cfg.xml configuration.buildSessionFactory(); } @Test public void testSavePerson(){ Configuration configuration = new Configuration(); configuration.configure(); SessionFactory factory = configuration.buildSessionFactory(); Session session = factory.openSession(); Transaction transaction = session.beginTransaction(); Person person = new Person(); person.setPname("班长2"); person.setPsex("女"); /** * 参数必须持久化对象 */ session.save(person); transaction.commit(); session.close(); }}
文件
对象
配置
数据
数据库
日志
框架
传输
测试
例子
二进制
作用
参数
名称
工具
工具包
序列
形式
接口
方法
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络服务器配置与管理笔记
多媒体软件开发流程
系统管理员服务器设置
苹果服务器营收入
呼伦贝尔服务器数据迁移
网络安全检查数据泄露
5g手机软件开发
网络安全意识安全报告
国家网络安全护网一天的工资
浪潮瀚高数据库
c 添加员工到数据库代码
汉邦服务器
LOL是不是服务器崩了
数据库在整个设计过程中最困难
泰拉瑞亚最近的服务器
公安部网络安全监察网站
交通网络安全计划
无锡财务软件开发公司
大专女生可以学软件开发吗
重庆网络安全学院
为什么企业要加强网络安全
杭州国产服务器哪个好
要想加工或使用数据库中的数据
云南省医药软件开发员待遇
网络技术公司架构
数据库营销学案例
达梦数据库number
网络安全趣味宣传标语
创建数据库表宽度
金华网络安全竞赛怎么参加