NHibernate Forge
The official new home for the NHibernate for .NET community

NHibernate mapping - <database-object/>

I, like many, have grown used to NHibernate’s schema generation capabilities. Those make working with databases such a pleasure that I cannot imagine trying without them.

However, at some point, even NHibernate’s smarts reach an end, and such an occasion requires the use of direct SQL to manipulate the database directly. A good example of that would be:

<!-- SQL Server need this index -->
<database-object>
	<create>
	CREATE INDEX PeopleByCityAndLastName ...
	</create>
	<drop>
	DROP INDEX PeopleByCityAndLastName 
	</drop>
	<dialect-scope name="NHibernate.Dialect.MsSql2000Dialect"/>
	<dialect-scope name="NHibernate.Dialect.MsSql2005Dialect"/>
	<dialect-scope name="NHibernate.Dialect.MsSql2008Dialect"/>
</database-object>

<!-- Oracle need this stats only -->
<database-object>
	<create>
	CREATE STATISTICS PeopleByCityAndLastName ...
	</create>
	<drop>
	DROP STATISTICS PeopleByCityAndLastName 
	</drop>
	<dialect-scope name="NHibernate.Dialect.OracleDialect"/>
	<dialect-scope name="NHibernate.Dialect.Oracle9Dialect"/>
</database-object>

As you can see, this allows us to execute database specific SQL, using the dialect scope. It is not a common feature, but it can be incredibly useful.


Posted abr 16 2009, 12:47 a.m. by Ayende
Filed under:

Comments

Alexandre Lindolfo Vianna wrote re: NHibernate mapping - <database-object/>
on 09-12-2011 21:24

Hello,

I'm looking for a solution that would let me specify the Oracle column

comment in the mapping file. Below is an attempt using <database-

object> but I got that error...

21:13:38.714 DEBUG [SchemaExport.Execute] Sistema:

   comment on column Cone_Slab.Id_Cone_Slab IS 'Identificador do

registro'; comment on column Cone_Slab.Id_Slab IS 'Identificador da

placa';

21:13:38.734 WARN [SchemaExport.Execute] Sistema: Unsuccessful:

comment on column Cone_Slab.Id_Cone_Slab IS 'Identificador do

registro'; comment on column Cone_Slab.Id_Slab IS 'Identificador da

placa';

21:13:38.735 WARN [SchemaExport.Execute] Sistema: ORA-00911: caractere

inválido

 <class name="ConeSlab" table="Cone_Slab" lazy="false">

   <id name="Id" column="Id_Cone_Slab" type="Int32">

     <generator class="hilo"/>

   </id>

   <many-to-one name="Cone" column="Id_Cone" class="Cone"

cascade="none" fetch="join" not-null="true"/>

   <many-to-one name="Slab" column="Id_Slab" class="Slab"

cascade="none" fetch="join" not-null="true"/>

 </class>

 <database-object>

   <create>comment on column Cone_Slab.Id_Cone IS 'Identificador do

cone'; comment on column Cone_Slab.Id_Slab IS 'Identificador da

placa';</create>

   <drop></drop>

 </database-object>

How can I fix this?

Powered by Community Server (Commercial Edition), by Telligent Systems