Hibernate Series 4-----Delete

Source: Internet
Author: User

1. And it's the increase of the brother different, more than a until package defines the Hibernateuntil class, let's have a look.

1  Public classHibernateuntil {2     Private StaticConfiguration cfg=NewConfiguration (). Configure ();3    Private StaticSessionfactory factory=cfg.buildsessionfactory ();4 5     //1. Method returns session static member variable cannot use non-static member directly6     //The session relies on the session factory, and the factory relies on configure7      Public StaticSession getsession () {8       returnfactory.opensession ();9 Ten     } One     //2. Close Session A      Public Static voidclosesession () { - getsession (). Close (); -}
View Code

Here also examines a knowledge point static variable and non-static variable if you want to learn, you have to hit the foundation!

2. Next we'll write a test class

1 @Test 2      Public void testhibernate () {3         deletestudent ();   Delete Student 4     }
View Code
1  Private voiddeletestudent () {2Session session=hibernateuntil.getsession ();3Student student=NewStudent ();4Student.setsid (2);5       //Open Transaction6Transaction tx=session.begintransaction ();7 Session.delete (student);8 tx.commit ();9 hibernateuntil.closesession ();TenSystem. out. println ("Success OK"); One}
View Code

Yes, Hibernate series additions and deletions to the end, thanks to peer reading ha!

Hibernate Series 4-----Delete

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.