View code
1 Public Class Hibernatecoreapitest { 2 Private Static Sessionfactory; 3 4 @ Beforeclass 5 Public Static Void Beforeclass (){ 6 Sessionfactory = New Annotationconfiguration (). Configure (). buildsessionfactory (); 7 } 8 @ Afterclass 9 Public Static Void Afterclass (){ 10 Sessionfactory. Close (); 11 } 12 13 @ Test 14 Public Void Testgetstudent (){ 15 Session session = Sessionfactory. getcurrentsession (); 16 Session. begintransaction (); 17 Student s = (student) Session. Get (student. Class , 1 ); 18 S. setname ("XML" ); 19 Session. gettransaction (). Commit (); 20 } 21 }
In this case, it will never work. In main
Public static void main (string [] ARGs) {beforeclass (); afterclass ();}
This can be found out.
Previously written
<Mapping class = "com/test/hibernate/model/student. HBM. xml"/>
<Mapping class = "com. Test. hibernate. model. Teacher"/>
Correct writing
XML: <MappingResource= "Com/test/hibernate/model/student. HBM. xml"/>
Note: <MappingClass= "Com. Test. hibernate. model. Teacher"/>