-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Running custom query when hbm2ddlauto = update
PostPosted: Fri Aug 06, 2010 7:09 am 
Newbie

Joined: Tue Dec 22, 2009 8:38 am
Posts: 18
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.