Re: [fluent-nhib] Bug on CompositeId() when setting column length?

111 views
Skip to first unread message

Oskar Berggren

unread,
Dec 25, 2012, 7:00:57 AM12/25/12
to fluent-n...@googlegroups.com
If you look at the XML mapping generated by fluent nhibernate's
ExportTo(), is the length property present (and with what value) for
the relevant key-property?

/Oskar


2012/12/24 <phin...@gmail.com>:
> Here i have the following mapping:
>
> CompositeId()
> .KeyProperty(e => e.TransactId, "TransactId")
> .KeyProperty(e => e.TransactType, p =>
> {
> p.ColumnName("TType");
> p.Length(2);
> })
> .KeyReference(e => e.Entity, "EntityId");
>
> ... which is supposed to create 3-column index key:
> TransactId - bigint
> TType -varchar(2)
> EntityId - bigint
>
> I am using Firebird 2.5 (32bit), and FluentNHibernate v1.3. The database is
> UTF8 encoded.
>
> However, it throws an index creation exception saying the index size
> exceeded the limit. Looking at the schema, the DDL generated is :
> TransactId BIGINT not null,
> TType VARCHAR(255) not null,
> EntityId BIGINT not null,
>
> The length did not changed; only the column name.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Fluent NHibernate" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/fluent-nhibernate/-/9TIhIZNY99oJ.
> To post to this group, send email to fluent-n...@googlegroups.com.
> To unsubscribe from this group, send email to
> fluent-nhibern...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/fluent-nhibernate?hl=en.

phin...@gmail.com

unread,
Dec 25, 2012, 7:31:36 AM12/25/12
to fluent-n...@googlegroups.com
Hi Oskar,

This is the composite-id fragment:

<composite-id>
  <key-property name="TransactId" type="...">
    <column name="TransactId" />
  </key-property>
  <key-property name="TransactType" type="..." length="2">
    <column name="TransactType" />
  </key-property>
  <key-many-to-one name="Entity" type="...">
    <column name="EntityId" />
  </key-many-to-one>
</composite-id>

Thanks.
Aris

phin...@gmail.com

unread,
Dec 25, 2012, 9:38:54 AM12/25/12
to fluent-n...@googlegroups.com
I tried to create a simple table with 2 bigint and 1 varchar(2) fields, and test the hbm file with NHibernate.  Basically, it contains a <composite-id> with 3 <key-property> elements, with the string field having length=2.  Running the test while stepping through the NHb code, I verified that it is ignoring the length attribute and creates the field as varchar(255).

I only started 3 days ago on Nhibernate so I am just depending on online samples and documentation, but I couldn't figure out how to fix this.  I'm going to use a workaround just for this entity temporarily (single Id for NHb + unique constraint + index table on backend).  I hope you can help me find a fix or a better workaround. :)

Oskar Berggren

unread,
Dec 25, 2012, 10:38:56 AM12/25/12
to fluent-n...@googlegroups.com
2012/12/25 <phin...@gmail.com>:
> Hi Oskar,
>
> This is the composite-id fragment:
>
> <composite-id>
> <key-property name="TransactId" type="...">
> <column name="TransactId" />
> </key-property>
> <key-property name="TransactType" type="..." length="2">
> <column name="TransactType" />

When the optional <column> element is specified, the type/length
information from the <key-property> element is ignored. These
attributes are there as a short-hand to avoid having the <column>
element when there is only a single column. This looks like it may be
a bug in fluent nhibernate which you can search for or report at
https://github.com/jagregory/fluent-nhibernate/issues. (To fix, fluent
should either not give the <column> element when there is a single
column, or specify the length etc there instead of on key-property.)


/Oskar

phin...@gmail.com

unread,
Dec 26, 2012, 12:27:18 AM12/26/12
to fluent-n...@googlegroups.com
Thanks for your assistance.  I have submitted this issue as you recommended.

Oskar Berggren

unread,
Dec 26, 2012, 7:20:58 AM12/26/12
to fluent-n...@googlegroups.com
Great. Now you may proceed to fork fluent nhibernate on github,, have
a look in the code, and then submit a pull request with the fix. :)

/Oskar


2012/12/26 <phin...@gmail.com>:
> --
> You received this message because you are subscribed to the Google Groups
> "Fluent NHibernate" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/fluent-nhibernate/-/0NCX7ZzqB7UJ.
Reply all
Reply to author
Forward
0 new messages