Jump to Content
Developers & Practitioners

NHibernate Dialect for Cloud Spanner is now Generally Available

October 25, 2022
https://storage.googleapis.com/gweb-cloudblog-publish/images/Google_Cloud_Spanner_Blog_Header.max-1800x1800.png
Knut Olav Løite

Software Engineer

The Cloud Spanner NHibernate Dialect is now Generally Available

Introduction

Do you have an application that you developed with NHibernate and now you want to migrate to a cloud database? Google Cloud Spanner now supports the NHibernate Object Relational Mapper. You can reuse existing NHibernate code with the Cloud Spanner NHibernate dialect, or write new features while leveraging existing knowledge.

The Cloud Spanner NHibernate dialect implements all the classes and interfaces that are needed to use Cloud Spanner with NHibernate. Add the Spanner NHibernate nuget package to your project and connect to Cloud Spanner as follows:

Installing

Install the Spanner NHibernate dialect:

dotnet add package Google.Cloud.Spanner.NHibernate --version 1.0.0

Connecting

Connect to Cloud Spanner with NHibernate:

Loading...

You can also use a custom connection provider or a user supplied connection with Spanner NHibernate. See this example for more information.

Usage

The Cloud Spanner NHibernate dialect supports standard NHibernate features, like querying data using both the NHibernate Criteria API and Linq, managing associations and executing transactions. The dialect also supports specific Spanner features such as interleaved tables, mutations and stale reads.

Query with Linq

NHibernate 3.0 introduced the Linq to NHibernate provider. The Spanner NHibernate dialect implements translations for the most commonly used functions and operators so these can be used with LInq.

Loading...

Interleaved Tables

Using interleaved tables for parent-child relationships in your schema can improve performance. Interleaving a child table with a parent means that the child records will be stored physically together with the parent. These relationships can be modeled and used as any other association in NHibernate.

Loading...

This directory contains the complete mapping of all the entities that are used in the sample above.

Mutations

NHibernate will use Data Manipulation Language (DML) by default. You can instruct NHibernate to use mutations for all transactions that are executed using a specific NHibernate session, or for a single transaction.

Loading...

Further Samples

The GitHub repository contains a directory with multiple samples for common use cases for working with NHibernate and/or Cloud Spanner. 

Limitations

Cloud Spanner features that are not supported in NHibernate are listed here.

Getting Involved

We'd love to hear from you, especially if you're a .NET developer considering Cloud Spanner or an existing Cloud Spanner customer who is considering using NHibernate for new projects. The project is open-source, and you can comment, report bugs, and open pull requests on Github.

Posted in