After Domino integrates hibernate, hibernate can manage the database (such as MySQL) and can access the database content using object mode, which improves the development efficiency.
This article shows the concrete steps of integration between Domino and hibernate,mysql through the example code, and explains how to use hibernate in Xpages.
About Hibernate
Hibernate is an open-source object-relational mapping framework that provides JDBC with a very lightweight object encapsulation that allows Java programmers to manipulate databases at will using object programming thinking.
Hibernate can be applied to any JDBC application, both in Java client applications and in servlet/jsp Web applications, and most revolutionary of all, hibernate can replace CMP in the EE architecture of the EJB application. The task of achieving data persistence.
Hibernate helps us to develop relational database-based applications using object-oriented thinking
First: Save the object data to the database
Second: Read the database data into the object
Hibernate architecture:
A very brief overview of the hibernate architecture
As you can see from this diagram, Hibernate uses database and configuration information to provide persistent services (and persistent objects) to applications.
Let's look at the Hibernate runtime architecture in more detail. Since hibernate is very flexible and supports a variety of application scenarios, we describe only two extreme situations.
A "lightweight" architecture scenario that requires the application to provide its own JDBC connection and manage its own transactions. This scenario uses the minimum subset of the Hibernate API:
Integration Steps
In the process of integrating Hibernate, first use Eclplise to build the hibernate environment, then the whole project into a jar package, add this jar package to Domino, to Xpage call.
Eclipse Manually build Hibernate environment
1 First use Eclipse to create a new Java project, add the Lib directory under the SRC directory, add hibernate jar package in this directory, because there is a mutual call between the jar package, note that all jar package versions need to be consistent, and, To copy the database driver package to the Lib directory, the database I used here is MySQL (Mysql-connector-java-5.1.8-bin.jar). Finally, add the jar package from the Lib directory to the build path.
2. Establish Hibernate.cfg.xml, which contains the basic connection information for hibernate and the database. The configuration is responsible for starting hierbante and creating sessionfactory instances. The Sessionfactory interface is responsible for initializing hibernate, which acts as a proxy for the data source and is responsible for creating session objects, which are loaded, saved, updated, deleted, and so on by the method of this object.
2 establishes the Entity Bean Class (Slwfpersonbean.java), which is the persisted object (PO). PO has three states in Hibernate: temporary (Transient), persistent (persistent), Off-tube status (Detached). When an JavaBean object is isolated in memory and does not have any relation to the data in the database, then this JavaBean object is called Transientobject; when it is associated with a session, it becomes persistentobject; When this session is closed, the object is also out of the persistent state and becomes the detachedobject.1.3
3. Create a mapping file (SlwfPerson.hbm.xml): Used to map the PO to the table in the database, the relationship between the PO and the data table, and the properties of the Po and table field one by one mapping, it is the core file of hibernate.
5. Test hibernate, build success.
6. Export the entire project to a jar file (Hibernatetest.jar), select the project, then right-click to select Export, export type to jar, and select Finish button to export successfully.
Hibernate integration into Domino
Method 1:
The first thing to do is switch the designer to Java view
Open Designer, select Window properties, and switch to Java Development view. Locate the Web_inf directory, copy the jar package to the Lib directory, and then select Hibernatetest.jar Right-click to select the build path and add the jar. This approach, as a Java developer, would choose to do so.
Then create a new Xpage page and do the test.
In the designer, create a new Xpage page, add a button to the page, write the LS code to call Hibernatetest.jar, inside the method.
Importpackage (Com.gzsolar.util)//If you want to invoke a class, you need to introduce the package name inside the jar importpackage (com.gzsolar.cnst) Try{var Unid = ""; Param.containskey ("Unid")) {Unid = Param.get ("Unid")}unid = "" var doc:notesdocument = Database.getdocumentbyunid (" dd757e2d538c359f48257d0100068299 "), var instanceId = doc.getitemvaluestring (" instanceId ");d Oc.replaceitemvalue (" Instancestatusos ", Instancestatus.cancel);d oc.save (); var util:engineutils = new engineutils (); Util.cancelinstance (INSTANCEID); }catch (e) {print (e);}
Next, import the jar package into the EXT directory
In the process of integration, the jar package that needs hibernate is put into the Path:\ibm\domino\jvm\lib\ext directory, which is the most error-prone place. Here you may feel that the hibernatetest.jar, inside there are these packages, can not import it, certainly not, this will be back to the background error, suggesting that no session of this class, in Domino found.
So the hibernate package, put in the Ext directory, for Domino to compile, before it can be used.
Test succeeded: Domino spooled hibernate statement, MYQL table also added a record,
Method 2:
Place the Hibernatetest.jar directly under the Path:\ibm\domino\jvm\lib\ext directory. Then restart the service.