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