Finally a bit of the feeling of introducing Hibernate. Conveniently, the learner outside the door gives a simple entry example. If you have used other persistent architectures to hibernate is actually very simple. Some principles are not talking, Robbin is definitely better than me, go to the essence version. What I gave just I originally started to get in touch with hibernate and set up a way. I haven't found it, so I now put it here to give you a look, (only give an intuitive induction I want to get started, I must first create a new project, then in Project property-> Paths-> Required libraries-> add-> New here defines the Hibernate class library to put all the JAR packages under Hibernate's LIB in course, and Hibernate2.jar is also going to go all the way.
Again is hibernate.properties to find it from Hibernate's SRC to copy it to the SRC directory of your project (what, your project does not have a src directory, newly built a casual class has a src directory) such a JB below Hibernate development The environment is just in hibernate.properties, setting your database connection by default is HypersonicsQL. It is what you most want to do. It is actually very simple new. io.Serializable; / ** * @author getdown * @version 1.0 * / public class Message implements Serializable {private Long id; private String text; // points to further define a simple list of a Message private Message nextMessage; public Message () {} public message (long ID) {this.id = ID;} public message (string text) {this.text = text;} public message (long ID, string text) {this.id = id; this.text = Text;} public long (} private void set;}) {this.id = id;} public string getText () {return text;} public void setText (String text) {this.text = text;} public Message getNextMessage () {return nextMessage;} public void setNextMessage (Message nextMessage) {this.nextMessage = nextMessage;}} the next is a class corresponding to hibernate profile Message.hbm.xml Code: NOT-NULL = "true" /> proty> When you run, run the following statement, you can remove the following you can get the following. BuildSessionFactory (); // Receive a session session session = sessions.opensession (); // Start the operation of the database / * -------- * / message Message = new message ("HelloWorld"); // Create a record session.save (message); // Deposit Record session.flush (); / * --- Query of the database ------- -------- * / // Message Message = new message (); // query q = session.createQuery ("from message as message where message.id = 1"); // message = (Message) Q.List (). get (0); // message.getnextMessage (). setText ("HellOnext"); // session.flush (); // session.close (); // long id = new long 1); // Message Message = (Message) session.find ("from message as message where message.id =?", Id, hibernate.long) .get (0); // system.out.println (Message). Gettext ()); // / * ------- Transaction processing ---------------- / // Transaction TX = session.begintransaction (); // Try {// message message = new message ("hello"); // session.save (message); // Session.flush (); // Message = new message ("hello"); // session.save (message); // session.flush (); // tx.commit (); //} // catch ( HibernateException ex) {// tx.rollback (); //} / * ------- Add 1000 recording time ------------- * / // message message; // long start = system.currenttimemillis (); // for (INT i = 0; i <1000; i ) {// message = new message ("hello"); // session.save (Message); // session.flush (); //} // long end = system.currenttimemillis (); // system.out.println ("Add 1000 Record Time ---" (End-Start) / 1000 " S "); session.close ();