How to connect many database to NHibernate? - nhibernate

I would like to re-program my product to use two, three or more databases in my project.
Now I have one MSSQL database, product connect to this database by Nhibernate (standard hibernate.cfg.xml file with one connection-string).
I do not want to separate records in tables by unique identifier.
Can I manage that?
<property name="connection.connection_string">
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Application.mdf;Integrated Security=True;User Instance=True
</property>

There are multiple solutions to do this, two of them are:
Use for each database a different configuration/session factory
If the database are on the same database server you can put the database name in mapping: databasename.dto.TableName

Related

One database, multiple names in SQL Server

I have an old ERP, which handled many organizations in a single db with a suffix on the tables. Lets say the db name is ORG and the tables look like CLIENTS01, CLIENTS02, CLIENTS03.
The new ERP connects to one database per organization.
The sad thing is I need to use both ERPs, so I need to replicate SAME DB WITH MULTIPLE NAMES: ORG01, ORG02, ORG03.
I was thinking for mirroring but this will increase database workload.
I looked for aliases but didn't find the way to make it work on the same instance.
I tried to create new database and then attach same file MDF file without success.
What would be the simplest way to just create 3 new databases connecting to the same database (1 database, multiple names)?

Change schemas' structure in a PostgreSQL database

I have a Postgres database with some schemas (all have the same structure), I want to know if there is the possibility to change the structure (Table names, new columns etc) for all the schemas in the same database. Is it possible or what's the purpose of the schemas in a database?
Thanks.
I'm going to focus on the second half of your question, because I think it'll answer the first half (and I'm not sure I understand the first half).
what's the purpose of the schemas in a database?
This confused me when I first switched from MySQL to PostgreSQL. A Postgres schema is essentially the same as a MySQL database. In fact, according to the MySQL Reference Manual:
In MySQL, physically, a schema is synonymous with a database.
That begs the question of what is a PostgreSQL database, then? From the PostgreSQL Documentation:
More accurately, a database is a collection of schemas and the schemas contain the tables, functions, etc. So the full hierarchy is: server, database, schema, table (or some other kind of object, such as a function).
So a PostgreSQL database is essentially a collection of schemas? Seems kind of pointless, why do we need that step in the hierarchy? Let's take a look at the docs for a PostgreSQL schema:
A PostgreSQL database cluster contains one or more named databases. Users and groups of users are shared across the entire cluster, but no other data is shared across databases. Any given client connection to the server can access only the data in a single database, the one specified in the connection request.
A database contains one or more named schemas, which in turn contain tables. Schemas also contain other kinds of named objects, including data types, functions, and operators. The same object name can be used in different schemas without conflict; for example, both schema1 and myschema can contain tables named mytable. Unlike databases, schemas are not rigidly separated: a user can access objects in any of the schemas in the database he is connected to, if he has privileges to do so.
So, in PostgreSQL, a schema contains tables, functions, etc. And a database manages user/group connectivity and access/roles to specific clusters of schemas. Typically, I work under one database and have information broken into schemas to segment information.

Can Datanucleus SchemaTool create additional columns not bound to a PC but mapped in JDO ORM?

I have a User class (#PC) currently having only one property: 'email', now I want the user-table (where User class is stored) to have additional columns, which are not managed by JDO but are subject of authentication happening outside of PM. When I auto-create the table by Datanucleus and then ALTER the table adding my columns everything works as expected.
Of course I would be happy to use SchemaTool for generation/update of the schema, yet dont want to have manual ALTER table procedure on that user table. Naively I've tried to put the two extra columns into ORM file (omitting targets):
<package name="bo">
<class name="User" table="tb_user">
<column name="USER_SECURITY" jdbc-type="VARCHAR" length="64"/>
<column name="SEC_SALT" jdbc-type="VARCHAR" length="10"/>
</class>
</package>
but SchemaTool did not generate the extra columns, altough ORM file was loaded according to logs.
BTW: no way I want to have those columns mapped and managed during JDO lifecycle.
so, is it possible to get Schematool to generate extra columns on tables or do I have to sort them out into another table not managed by Datanucleus?
thanks
JDO spec defines such as that as seen in this link, and I have no problem with our tests using such unmapped columns in SchemaTool
http://www.datanucleus.org/products/accessplatform_3_3/jdo/orm/schema_mapping.html#unmapped

using Hibernate-tools to update schema

I am currently using EclipseLink JPA and in my persistence.xml file i have this property set
<property name="eclipselink.ddl-generation" value="drop-and-create-tables"/>
The value field currently set to drop and create tables on each run is causing my test data to be deleted. Unfortunately, EclipseLink does not support an update schema property that integrates with any changes to Entities in my project. I read somewhere, Hibernate-tools can be used to update the database schema without deleting current records?
I have tried this property
<property name="eclipselink.ddl-generation" value="create-tables"/>
while it does keep my data, it doesn't update table schema.
In my persistence.xml can i include the hibernate property ?
property name="hibernate.hbm2ddl.auto" value="update"
EclipseLink (as of 2.3.2) doesn't support DDL altering existing tables to add missing fields. Please see feature request https://bugs.eclipse.org/bugs/show_bug.cgi?id=368365
No, you can use only standart jpa properties or properties of your persistence provider (EclipseLink in your case). I believe that here you will find your answer.

Data Migration from different Databases different tables

I have a Db called Db1, and also I have a different Db called Db2. Db2 has no data. I want to migrate data from Db1 to Db2, but this two databases are not the same with each other. They include different tables, different column names.
Is there anyway to bind one or more tables or columns to other Db's tables columns to transport data?
SQL Server Integration Services
http://msdn.microsoft.com/en-us/library/ms141026.aspx
Using the SQL Server Import and Export Wizard to Move Data
http://msdn.microsoft.com/en-us/library/ms141209.aspx