当前位置:七道奇文章资讯编程技术Java编程
日期:2011-03-22 16:13:00  来源:本站整理

hibernate3学习笔记(四) 增删改查[Java编程]

赞助商链接



  本文“hibernate3学习笔记(四) 增删改查[Java编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:

测试代码:

package com.hb3.pack_01;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

import com.hb3.pack_01.model.User;

public class BusinessService {

public static void main(String[] args) {

Configuration config = new Configuration().configure();
SessionFactory sessionFactory = config.buildSessionFactory();
Session session = sessionFactory.openSession();

//insert
User user = new User();
user.setName("chenyan");
//user.setAge(new Integer(23));
Transaction tx = session.beginTransaction();
session.save(user);
tx.commit();

//get
user = (User) session.get(User.class, user.getId());
System.out.println(user.getAge());

//update
user.setAge(new Integer(24));
tx= session.beginTransaction();
session.update(user);
tx.commit();

//load
user = (User) session.load(User.class, user.getId());
System.out.println(user.getAge());

//delete
tx = session.beginTransaction();
session.delete(user);
tx.commit();

session.close();
sessionFactory.close();
}
}
履行后果:

11:50:50,750 WARN ConfigurationFactory:127 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/Java/MyEclipse%206.0/workspace/hb3demo/ehcache-1.2.3.jar!/ehcache-failsafe.xml
11:50:51,156 WARN EhCacheProvider:93 - Could not find configuration [org.hibernate.cache.UpdateTimestampsCache]; using defaults.
11:50:51,171 WARN EhCacheProvider:93 - Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults.
Hibernate: insert into user (name, age) values (?, ?)
null
Hibernate: update user set name=?, age=? where id=?
24


  以上是“hibernate3学习笔记(四) 增删改查[Java编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:

  • 在Hibernate里面动态切换SChema实现访谒差别的数据库的几种办法
  • Hibernate 3新增XML关系长期性介绍
  • Hibernate配置文件在单元测试中的操纵
  • 在Hibernate中动态切换Schema
  • hibernate annoation (八 关联映射)
  • hibernate annoation (九 cascading)
  • <b>hibernate annoation (十 映射查询)</b>
  • hibernate annoation(十一 缓存Ehcache 采纳annoation)
  • Hibernate:操作配置文件生成数据库
  • hibernate annoation (一 加载)
  • hibernate annoation (二 成立表)
  • <b>hibernate annoation (三 id生成器)</b>
  • 本文地址: 与您的QQ/BBS好友分享!
    • 好的评价 如果您觉得此文章好,就请您
        0%(0)
    • 差的评价 如果您觉得此文章差,就请您
        0%(0)

    文章评论评论内容只代表网友观点,与本站立场无关!

       评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论
    Copyright © 2020-2022 www.xiamiku.com. All Rights Reserved .