Hibernate3 Learning Notes (iv) Increase the check

Source: Internet
Author: User
Tags commit

Test code:

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 ();
}
}
Execution results:

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.