building database w/AutoMapping column ordering question

11 views
Skip to first unread message

MaggiePlusPlus

unread,
Apr 16, 2009, 12:39:36 PM4/16/09
to Fluent NHibernate

Here is the code I am using to create my database and to export the
xml mapping files:

return Fluently.Configure()
.Database(JetDriverConfiguration.Standard
.ConnectionString(c => c
.DatabaseFile
(FileName)
.Provider
("Microsoft.ACE.OLEDB.12.0")
.Username
("")
.Password
("")))
.Mappings(m =>
m.AutoMappings.Add(

AutoPersistenceModel.MapEntitiesFromAssemblyOf<IPCApplication.Entities.Model.Pipe>
()
.Where(type =>
type.Namespace.EndsWith("Model")))
.ExportTo(@"ExportAutoMaps"));

one sample input/output is:

public class InspectionPlan
{
public virtual int Id { get; private set; }

public virtual string PipelineName { get; set; }
public virtual string PipeName { get; set; }
public virtual string CreationDate { get; set; }

}
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="IPCApplication.Entities, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null" namespace="IPCApplication.Entities.Model">
<class name="InspectionPlan" table="`InspectionPlan`"
xmlns="urn:nhibernate-mapping-2.2">
<id name="Id" type="Int32" column="Id">
<generator class="identity" />
</id>
<property name="PipeName" type="String">
<column name="PipeName" />
</property>
<property name="CreationDate" type="String">
<column name="CreationDate" />
</property>
<property name="PipelineName" type="String">
<column name="PipelineName" />
</property>
</class>
</hibernate-mapping>

All is working except that the columns are not kept in order. What do
I need to do to retain the input order?

Paul Batum

unread,
Apr 18, 2009, 4:45:40 AM4/18/09
to fluent-n...@googlegroups.com
Is this somehow different to the problem that you've been discussing
in the other thread, that was supposed to be fixed in revision 444?

Hudson Akridge

unread,
Apr 18, 2009, 10:29:54 AM4/18/09
to fluent-n...@googlegroups.com
I believe this is the scenario that maggie has that wasn't fixed with 444. I'll be able to check into it later today :)

Just as a general note Maggie, the fix in 444 was for writing out properties in the order they were added to a class mapper. It's possible that this isn't what's wrong, but it's that the fields are being added by the automapper in an order not consistent with your declaration order.

Hudson Akridge

unread,
Apr 19, 2009, 12:32:24 AM4/19/09
to fluent-n...@googlegroups.com
I could not recreate your issue Maggie, using your exact class/auto config, could you please verify that you are at least at revision 444?

MaggiePlusPlus

unread,
Apr 19, 2009, 12:59:29 PM4/19/09
to Fluent NHibernate
Thanks for looking at it. Jon also mentioned to have me check the
version and while I did have 447 source, one of the projects did not
have the corresponding .dll.

I corrected the dll reference and now the columns are indeed in the
correct order.

Thanks again,
Maggie

MaggiePlusPlus

unread,
May 1, 2009, 11:56:23 AM5/1/09
to Fluent NHibernate
I updated to version 464 of FNH and the columns are again out of order
and the hbm.xml files have no formatting - all on one line.

James Gregory

unread,
May 1, 2009, 12:07:25 PM5/1/09
to fluent-n...@googlegroups.com
That'll be my fault, as part of our redesign I've had to rewrite the ordering code and it looks like I didn't incorporate the changes that were done to fix this issue.

I've created a new issue for this and either myself or one of the other developers will look into it as soon as we can. Thanks for pointing this out Maggie!

Stuart Childs

unread,
May 1, 2009, 12:05:10 PM5/1/09
to Fluent NHibernate
While I'm not using AutoMappings, I was having a similar issue but was
more severe (with only one of my classes, too... one of many oddities)
where properties/components were being put before the <id> tag,
causing NHibernate to fail. It's very bizarre, but grouping all the
Map(), Component(), and References() calls separately and playing with
the ordering of the calls within those groups finally spit out a
mapping that passes validation... maybe you can try a similar
workaround until the issue is fixed? (I'm assuming it's a result of
the hacking they've been doing on the code to get the new model in)

James Gregory

unread,
May 1, 2009, 12:09:31 PM5/1/09
to fluent-n...@googlegroups.com
Stuart: It might be too late now, but we'd greatly appreciate seeing the mappings causing the problems for you. They'd help us debug the ordering code.

Stuart Childs

unread,
May 1, 2009, 12:33:43 PM5/1/09
to Fluent NHibernate
In my case, it looks like it was because the sorting dictionary in
SortChildren() in XmlHibernateMappingWriter.cs was missing a
"component" pair. Adding
{ "component", new SortValue { Position = PartPosition.Anywhere, Level
= 2 } },
seems to have fixed my issue with that class, but it's hard to say if
this is a complete fix. It does appear that all elements are grouped
together in all of my mapping files with that change.

I'd submit a patch (and will if it's helpful to you for tracking
purposes) but it seems like a pretty trivial change and if one tag was
missing from the sorting dictionary, it may be worth double checking
that all possible types are there.

On May 1, 11:09 am, James Gregory <jagregory....@gmail.com> wrote:
> Stuart: It might be too late now, but we'd greatly appreciate seeing the
> mappings causing the problems for you. They'd help us debug the ordering
> code.
>

James Gregory

unread,
May 1, 2009, 12:41:20 PM5/1/09
to fluent-n...@googlegroups.com
Ah yes, silly mistake. I've added this in my local copy, but am in the middle of some changes so haven't yet committed it. I've also noticed that dynamic-component and one-to-one are both missing too, so there may be more too. This should really be reviewed.

As for the other thing, is it that there's no whitespace in the output?

Stuart Childs

unread,
May 1, 2009, 12:45:36 PM5/1/09
to Fluent NHibernate
Correct; the generated HBM files have no whitespace... easy enough to
fix with a ctl+k, ctl+d in VS. ;)

On May 1, 11:41 am, James Gregory <jagregory....@gmail.com> wrote:
> Ah yes, silly mistake. I've added this in my local copy, but am in the
> middle of some changes so haven't yet committed it. I've also noticed that
> dynamic-component and one-to-one are both missing too, so there may be more
> too. This should really be reviewed.
> As for the other thing, is it that there's no whitespace in the output?
>

Stuart Childs

unread,
May 1, 2009, 1:02:57 PM5/1/09
to Fluent NHibernate
I believe the full list of missing tags is:
timestamp
one-to-one
component
dynamic-component
any

Also is <import> but if I understand correctly that's at the level ==
class and this function is just for <class> children? I haven't
stepped through all the XML generation code so I'm not 100% sure about
what gets added where. Along those lines, the collection children are
also missing but might be unnecessary depending on how those elements
are being created/sorted (I think as long as <key> gets put first the
rest don't matter):

key
index
index-many-to-many
element
composite-element
one-to-many
many-to-many
collection-id

James Gregory

unread,
May 1, 2009, 1:05:04 PM5/1/09
to fluent-n...@googlegroups.com
Great, thanks Stuart, I'll make sure those get added.

As for the whitespace, it's a simple oversight. Until I can come to commit, if you open the PersistenceModel code and goto line 195, just before that line add writer.Formatting = Formatting.Indented;, that'll make it indent the xml nicely.

MaggiePlusPlus

unread,
May 1, 2009, 2:37:59 PM5/1/09
to Fluent NHibernate
Thank you very much! let me know if I can help with anything.

On May 1, 12:07 pm, James Gregory <jagregory....@gmail.com> wrote:
> That'll be my fault, as part of our redesign I've had to rewrite the
> ordering code and it looks like I didn't incorporate the changes that were
> done to fix this issue.
> I've created a new
> issue<http://code.google.com/p/fluent-nhibernate/issues/detail?id=211>
> for
> this and either myself or one of the other developers will look into it as
> soon as we can. Thanks for pointing this out Maggie!

Stuart Childs

unread,
May 1, 2009, 4:18:34 PM5/1/09
to Fluent NHibernate
Oops, I made the previous list by scanning the documentation instead
of the mapping schema .xsd...

Might want to add the following to the list:
meta
jcs-cache
idbag
primitive-array
union-subclass
filter
sql-*

Though it's probably unnecessary since I think most (all?) don't
really apply for FNH's current feature set. Still, there they are for
completeness ;)
Reply all
Reply to author
Forward
0 new messages