Starting a Hibernate project This code calls three
Starting a Hibernate project This code calls three SQL statements inside the same database transaction: select m.MESSAGE_ID, m.MESSAGE_TEXT, m.NEXT_MESSAGE_ID from MESSAGES m where m.MESSAGE_ID = 1 insert into MESSAGES (MESSAGE_ID, MESSAGE_TEXT, NEXT_MESSAGE_ID) values (2, ‘Take me to your leader (please)’, null) update MESSAGES set MESSAGE_TEXT = ‘Greetings Earthling’, NEXT_MESSAGE_ID = 2 where MESSAGE_ID = 1 Notice how Hibernate detected the modification to the text and nextMessage properties of the first message and automatically updated the database Hibernate did automatic dirty checking. This feature saves you the effort of explicitly asking Hibernate to update the database when you modify the state of an object inside a unit of work. Similarly, the new message was made persistent when a reference was created from the first message. This feature is called cascading save. It saves you the effort of explicitly making the new object persistent by calling save(), as long as it s reachable by an already persistent instance. Also notice that the ordering of the SQL statements isn t the same as the order in which you set property values. Hibernate uses a sophisticated algorithm to determine an efficient ordering that avoids database foreign key constraint violations but is still sufficiently predictable to the user. This feature is called transactional write-behind. If you ran the application now, you d get the following output (you d have to copy the second unit of work after the third to execute the query-display step again): 2 message(s) found: Greetings Earthling Take me to your leader (please) You now have domain classes, an XML mapping file, and the Hello World application code that loads and stores objects. Before you can compile and run this code, you need to create Hibernate s configuration (and resolve the mystery of the HibernateUtil class). 2.1.3 Hibernate configuration and startup The regular way of initializing Hibernate is to build a SessionFactoryobject from a Configuration object. If you like, you can think of the Configuration as an object representation of a configuration file (or a properties file) for Hibernate. Let s look at some variations before we wrap it up in the HibernateUtil class.
We recommend high quality webhost to host and run your jsp application: christian web host services.