Hello everyone,
I am facing the following situation:
-I have set up the hbm2ddlauto value as "update" (I want to update (without dropping) the database schema each time I make some changes in the business entities)). I want that each time I perform the schema update, to run a series of sql sentences.
NHibernate offers us the possibility of running custom sql sentences on sql schema creation (in the <database-object> <create> section), or during the sql schema drop (in the <database-object><drop> section). Yet the <database-object> section does not contain a section called <database-object><update>, in order to run the custom sql sentences during the schema update. If I put my queries in the <create> section and change the hbm2ddlauto value to "create", I succeed running the queries, but it doesnt help me too much as I loose the data by dropping the database.
- As an alternative to the first point, In the hbm file you can also define a <query> section, where you can place your custom queries within a CDATA tags. Subsequently you can access the queries after creating the session object, with a declaration of the following type:
Code:
IQuery q = session.GetNamedQuery("MyCustomQuery");
My queries are not simple selects, they create objects or insert data in the catalogue tables. Thus, they dont return records/objects. And here we arrive at the second problem I face: If I put my custom query in the <query> tag, when I create the session factory, I receive the following error: "Error in custom query {MyQueryName}".
Resuming the ideas written above, my question is:
- Is it possible to run custom queries or TSQL sentences in the moment I update the database schema ?
Thank you,
C.