eBiss 3

Hilfe & Dokumentation

User Tools

Site Tools


en:ueberblick:installation:konfiguration:nhibernate

NHibernate configuration

NHibernate offers a way to access different databases using Life Objects. The object (C# or VB class structure) is used to map the relevant table from which data is to be retrieved or written to the data. The merging of the table fields with the class fields is done by NHibernate-HBM-XML-Mapping.
The following files are required:

Life Object Class:

Object that maps the table structure with which data is retrieved from or written to the database.
In this example, article data is written to an MS Access database. If data is to be read from a database, the Load method must be implemented and used accordingly. The interfaces IMapObjectRoot and IDbLifecycle must be specified in the cash declaration.

  • IMapObjectRoot: Determines whether this class is displayed as the top level (root object) in the mapping source/target object
  • IMapObjectItem: Represents this class as a child element of the root object in the mapping source/target object.
  • IDbLifecycle: Enables read/write access to a database

konfiguration_nhibernate_klasse.jpg
konfiguration_nhibernate1.jpg

Here is another example of a class declaration. Article data is retrieved from a database to compile an article catalog. Therefore, the Save and Rollback methods are not filled in. For this operation, only the Load method is used to retrieve the data from the database and create an object list of item data, and the Commit method is used to identify the retrieved records.
nhibernate_class2.jpg

NHibernate hbm.xml-Mapping :

This mapping connects the fields in the object to the table columns of the target database. It is important that in the mapping name hbm. xml like in the following example (ArtikeldatenStructure.hbm.xml) is included. It is also important to use NHibernate data types in database object mapping. These are listed in the left-hand column. Do not use the. net data types in the database object mapping under any circumstances..nhibernate_datatypes1.jpg

konfiguration_nhibernate2.jpg

Data is often retrieved from a database, e. g. when article data is to be compiled for an article catalog. In many cases, the retrieved data records are flagged as retrieved by an entry in a column provided for this purpose. In this case, only one column is affected. In most cases, a boolean (Yes/No) or alphanumeric (Y/N) value is written to the column designated for this purpose after retrieving all data records for an article catalog. So that not all fields of a data record are written back to the database during the update process, the following paramens can be specified at class level:

<class name=“jakoby.DBIntegration.ArtikelPositionen, ascii.jakoby” table=“Artikelkatalog” dynamic-update=“true” dynamic-insert=“true”>

  • dynamic-update=“true|false”
  • dynamic-insert=“true|false”

This takes advantage of the possibility to use a switch at field level that allows the update mechanism to be switched on and off for each individual field. If the update parameter is entered in a property (mapped field) as follows:

<property name=“ItemDescription” type=“String” access=“field” column=“ItemDescription” update=“false” />

* update="false"

With this setting, the field is not included in the update process. If a field is to be considered, you do not need to specify extra update=“true”, since this corresponds to the default setting of the NHibernate mapping property.

Simple or combined key (primary key)

If, for example, article data is fetched, the records (an article record) are entered in a list. Since NHibernate determines the way in which this list is filled, a unique primary and foreign key is essential.nhibernate_singleprimarykey.jpg

nhibernate_composidekey.jpg

It is important that the id tag of the NHibernate mapping contains a table column containing different values for each data record. If, on the other hand, only the foreign key is specified, the list is filled with the first item, since it always has the same value. The result is that the item list contains the correct number of items, but all items contain the same data, namely that of the first item. For this reason, you should either select a table column with a sequential number (autoindex) in the id tag of the mapping, or a unique composite key from several columns so that all positions of the document are also entered in the list so that they can be used later for processing.

hibernate.cfg.xml :

Contains the database type and command. This file should be in the eBiss directory. The example below establishes a connection to an Access database.

konfiguration_nhibernate3.jpg

The next example shows the settings for connecting via Odbc to a Microsoft SQL server.:
nhibernate_connection2.jpg

In the next example, the parameters for a native connection to an MS SQL server are given:
nhibernate_connection3.jpg

File Appender for error output in Log :

The FileAppender contains the path to the Log4Net log file. This is where NHibernate's error messages are written. To activate it you have to name a file log4net. config. xml and put it in the eBiss directory.

konfiguration_nhibernate4.jpg

For more information, see :

en/ueberblick/installation/konfiguration/nhibernate.txt · Last modified: 2024/02/20 08:15 by 127.0.0.1