Length of column

5 views
Skip to first unread message

Martin Nilsson

unread,
Feb 22, 2009, 10:28:51 AM2/22/09
to nhu...@googlegroups.com
Length constraint of column is ignored when running SchemaExport.Create

Class:
public class Entity
{
  public virtual Guid Id { get; set; }
  public virtual string Content { get; set; }
}

Mapping file:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-lazy="true" assembly="PropertyLengthTest" namespace="PropertyLengthTest.Domain">
  <class name="Entity" table="`Entity`" xmlns="urn:nhibernate-mapping-2.2">
    <id name="Id" column="Id" type="Guid">
      <generator class="guid.comb" />
    </id>
    <property name="Content" length="2500" type="String">
      <column name="Content" />
    </property>  
  </class>
</hibernate-mapping>

Successful test:
[Test]
public void When_generating_schema_should_generate_correct_length_of_property()
{
  var configuration = new Configuration();
  configuration.Configure();
  configuration.AddAssembly(typeof (Entity).Assembly);
  var export = new SchemaExport(configuration);
  export.Drop(true, true);
  export.Create(true, true);
}

Generated table:
CREATE TABLE [dbo].[Entity](
  [Id] [uniqueidentifier] NOT NULL,
  [Content] [nvarchar](255) ...

NHibernate version: 2.1.0.1001

Any ideas?

Gustavo Ringel

unread,
Feb 22, 2009, 10:48:16 AM2/22/09
to nhu...@googlegroups.com
If you can reproduce it in a test then create a JIRA with the test at http://nhjira.koah.net

Thanks.

Gustavo

Fabio Maulo

unread,
Feb 22, 2009, 10:50:08 AM2/22/09
to nhu...@googlegroups.com
<property name="Content" length="2500" type="string"/>

2009/2/22 Martin Nilsson <mffm...@gmail.com>



--
Fabio Maulo

Gustavo Ringel

unread,
Feb 22, 2009, 10:53:22 AM2/22/09
to nhu...@googlegroups.com
Are you meaning that when you open a column tag every SQL Specific declaration in the property is disregarded?

Gustavo.

Fabio Maulo

unread,
Feb 22, 2009, 10:57:25 AM2/22/09
to nhu...@googlegroups.com
2009/2/22 Gustavo Ringel <gustavo...@gmail.com>

Are you meaning that when you open a column tag every SQL Specific declaration in the property is disregarded?

You should choose between the "short-way" or the "verbose-way"... without mix it.
BTW we having some issues related to the "mapping binders".

--
Fabio Maulo

Martin Nilsson

unread,
Feb 22, 2009, 11:17:06 AM2/22/09
to nhu...@googlegroups.com
I'm to new at NHibernate to follow you but the mapping is generated from Fluent NH so maybe it's an issue in that product?

public EntityMap()
{
  Id(x => x.Id);
  Map(x => x.Content).WithLengthOf(2500);
}

From "16.1.1. Customizing the schema"
http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html_single/#toolsetguide-s1-2

Ex:
<property name="Foo" type="String" length="64" not-null="true"/>

From my hbm:
<property name="Content" length="2500" type="string"/>

Do you mean that there are more ways of configure the length?

Gustavo Ringel

unread,
Feb 22, 2009, 1:59:10 PM2/22/09
to nhu...@googlegroups.com
What fabio is suggesting is removing the column tag or putting all the info there.
In your case take Fabio's suggestion and remove the unnecesary column tag.
Reply all
Reply to author
Forward
0 new messages