- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
MULTIPLE DATABASES AND SESSION FACTORIES in C#
MULTIPLE DATABASES AND SESSION FACTORIES Code 39 Full ASCII Drawer In Visual C#.NET Using Barcode creation for Visual Studio .NET Control to generate, create ANSI/AIM Code 39 image in Visual Studio .NET applications. www.OnBarcode.comScanning Code39 In C#.NET Using Barcode decoder for .NET framework Control to read, scan read, scan image in .NET applications. www.OnBarcode.comWe ve demonstrated the creation of a single SessionFactory, which is all that most applications need. If you need another ISessionFactory instance in the case of multiple databases, for example repeat the process. Each SessionFactory is then available for one database and ready to produce ISession instances to work with that particular database and a set of class mappings. Once you have your SessionFactory, you can go on to create sessions, and start loading and saving objects. QR Maker In Visual C# Using Barcode creator for .NET Control to generate, create Quick Response Code image in VS .NET applications. www.OnBarcode.comDrawing Barcode In Visual C# Using Barcode creation for Visual Studio .NET Control to generate, create Barcode image in .NET framework applications. www.OnBarcode.comCONFIGURATION TECHNIQUES
Paint Linear Barcode In C#.NET Using Barcode encoder for Visual Studio .NET Control to generate, create 1D image in Visual Studio .NET applications. www.OnBarcode.comCode 39 Drawer In Visual C#.NET Using Barcode creator for VS .NET Control to generate, create Code 39 Extended image in Visual Studio .NET applications. www.OnBarcode.comOf course, there is more to configuring NHibernate than pointing to mapping documents. You also need to specify how database connections are to be obtained, along EAN 128 Encoder In C# Using Barcode drawer for Visual Studio .NET Control to generate, create GS1-128 image in .NET framework applications. www.OnBarcode.comGenerating I-2/5 In Visual C# Using Barcode encoder for VS .NET Control to generate, create ITF image in .NET framework applications. www.OnBarcode.comBasic configuration
Code 3/9 Creator In Java Using Barcode encoder for Android Control to generate, create Code 39 Full ASCII image in Android applications. www.OnBarcode.comDecoding ANSI/AIM Code 39 In .NET Using Barcode reader for VS .NET Control to read, scan read, scan image in .NET framework applications. www.OnBarcode.comwith various other settings that affect the behavior of NHibernate at runtime. The multitude of configuration properties may appear overwhelming (a complete list appears in the NHibernate documentation), but don t worry; most define reasonable default values, and only a handful are commonly required. To specify configuration options, you may use any of the following techniques: Print Code 128 Code Set A In Java Using Barcode generation for Java Control to generate, create Code-128 image in Java applications. www.OnBarcode.comDraw PDF 417 In None Using Barcode creator for Online Control to generate, create PDF-417 2d barcode image in Online applications. www.OnBarcode.comPass an instance of System.Collections.IDictionary to Configuration. SetProperties(), or use Configuration.SetProperty() for each property (or manipulate the collection Configuration.Properties directly). Set all properties in application configuration file (App.config or Web.config). Include <property> elements in an XML file called hibernate.cfg.xml in the current directory. QR Creator In Java Using Barcode generation for Android Control to generate, create QR Code ISO/IEC18004 image in Android applications. www.OnBarcode.comPaint Code 39 Full ASCII In VS .NET Using Barcode creation for Reporting Service Control to generate, create Code 3 of 9 image in Reporting Service applications. www.OnBarcode.comThe first option is rarely used except for quick testing and prototypes, but most applications need a fixed configuration file. Both the application configuration file and the hibernate.cfg.xml file provide the same function: to configure NHibernate. Which file you choose to use depends on your syntax preference. hibernate.cfg.xml is the filename chosen by convention. You can use any filename (such as NHibernate.config, because .config files are automatically protected by ASP.NET when deployed) and provide this filename to the Configure() method. It s even possible to mix both options and have different settings for development and deployment. A rarely used alternative option is to let the application provide an ADO.NET IDbConnection when it opens an NHibernate ISession from the SessionFactory (for example, by calling sessionFactory.OpenSession(myConnection)). Using this option means you don t have to specify any database-connection properties (the other properties are still required). We don t recommend this approach for new applications that can be configured to use the environment s database-connection infrastructure. Of all the configuration options, database-connection settings are the most important because, without them, NHibernate won t know how to correctly talk to the database. Creating Barcode In Java Using Barcode generator for Android Control to generate, create Barcode image in Android applications. www.OnBarcode.comBarcode Encoder In Objective-C Using Barcode generation for iPhone Control to generate, create Barcode image in iPhone applications. www.OnBarcode.comConfiguring the ADO.NET database access
PDF 417 Recognizer In Java Using Barcode scanner for Java Control to read, scan read, scan image in Java applications. www.OnBarcode.comPDF417 Maker In Java Using Barcode creator for BIRT Control to generate, create PDF 417 image in BIRT reports applications. www.OnBarcode.comMost of the time, the application is responsible for obtaining ADO.NET connections. NHibernate is part of the application, so it s responsible for getting these connections. You tell NHibernate how to get (or create new) ADO.NET connections. Figure 2.2 shows how .NET applications interact with ADO.NET. Without NHibernate, the application code usually receives an ADO.NET connection from the connection pool (which is configured transparently) and uses it to execute SQL statements. Draw Data Matrix ECC200 In Objective-C Using Barcode creation for iPhone Control to generate, create Data Matrix image in iPhone applications. www.OnBarcode.comGenerate Barcode In None Using Barcode printer for Font Control to generate, create Barcode image in Font applications. www.OnBarcode.com.NET Environment
Application ASP.NET Windows
User-managed ADO.NET connections
Connection Pool
Service Database
Figure 2.2 Direct access to ADO.NET connections
Hello NHibernate! .NET Environment NHibernate
Application ASP.NET Windows
ISession ITransaction IQuery
Connection Pool
Service
Database
Figure 2.3 NHibernate managing database access
With NHibernate, the picture changes: NHibernate acts as a client of ADO.NET and its connection pool, as shown in figure 2.3. The application code uses the NHibernate ISession and IQuery APIs for persistence operations and only has to manage database transactions, ideally using the NHibernate ITransaction API. CONFIGURING NHIBERNATE USING HIBERNATE.CFG.XML
Listing 2.6 uses a file named hibernate.cfg.xml to configure NHibernate to access a Microsoft SQL Server 2000 database. Listing 2.6 Using hibernate.cfg.xml to configure NHibernate
< xml version="1.0" > <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2"> <session-factory> <property name="connection.provider"> NHibernate.Connection.DriverConnectionProvider </property> <property name="dialect"> NHibernate.Dialect.MsSql2000Dialect </property> <property name="connection.driver_class"> NHibernate.Driver.SqlClientDriver </property> <property name="connection.connection_string"> Data Source=(local); Initial Catalog=nhibernate; Integrated Security=SSPI </property> </session-factory> </hibernate-configuration> This code s lines specify the following information: connection.provider specifies the name of the .NET class implementing the IConnectionProvider interface; here, we use the default one. dialect specifies the name of the .NET class implementing the database Dialect. Dialects are how NHIbernate can take advantage of database-specific fea- tures. Despite the ANSI standardization effort, SQL is implemented differently by various databases vendors. You must specify a Dialect. NHibernate includes built-in support for most popular SQL databases, and new dialects may be defined easily.
|
|