-->
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.  [ 7 posts ] 
Author Message
 Post subject: NMHA.HibernateMapping DefaultAccess attribute issue
PostPosted: Thu May 11, 2006 6:02 am 
Newbie

Joined: Wed Mar 29, 2006 4:42 am
Posts: 11
Location: Ware, Herts., UK
I have the following line of code on my class:

Code:
[NHMA.HibernateMapping(DefaultAccess = "field.camelcase-underscore")]


I'm then using the NHibernate.Mapping.Attributes.HbmSerializer to serialize my assembly and get my mapping file from a memory stream.

The .hbm.xml file that is created by this process does not contain the

Code:
default-access="field.camelcase-underscore"


attribute in the <hibernate-mapping> element.

In fact, looking at the relevant example code in the NHibernateContrib project shows that the file Baz.Reference.hbm.xml has the following...:

Code:
<hibernate-mapping ... default-access="Int32" ...


The code on the Baz class is decorated with a DefaultAccessTypeAttribute NOT a DefaultAccessAttribute.

Surely this is wrong compared to the default-access attribute definitions in the documentation sections 4.1 and 4.2?


Top
 Profile  
 
 Post subject: Found the solution to my issue
PostPosted: Thu May 11, 2006 7:24 am 
Newbie

Joined: Wed Mar 29, 2006 4:42 am
Posts: 11
Location: Ware, Herts., UK
After looking through the HbmSerializer code it became obvious that the NHMA.HibernateMapping attribute does not work when it is applied to classes within an assembly when you are serializing the whole assembly in one go (as per the example in the documentation).

What you need to do is have the following code as part of the serialization of your assembly:

Code:
System.IO.MemoryStream stream = new System.IO.MemoryStream(); // where the xml will be written

NHibernate.Mapping.Attributes.HbmSerializer.Default.Validate = true; // Enable validation (optional)

// Set any specific values for the <hibernate-mapping> element here
// Must do this before calling the Serialize() method!
NHibernate.Mapping.Attributes.HbmSerializer.Default.HbmDefaultAccess = "field.camelcase-underscore";

// Here, we serialize all decorated classes (but you can also do it class by class)
NHibernate.Mapping.Attributes.HbmSerializer.Default.Serialize(stream, System.Reflection.Assembly.GetExecutingAssembly() );


Top
 Profile  
 
 Post subject: A
PostPosted: Thu May 11, 2006 7:28 am 
Newbie

Joined: Wed Mar 29, 2006 4:42 am
Posts: 11
Location: Ware, Herts., UK
BTW, I still think there's a problem with Baz.Reference.hbm.xml file in the NHibernateContrib project though.

"Int32" is not a valid value for the default-access attribute in the <hibernate-mapping> element.


Top
 Profile  
 
 Post subject:
PostPosted: Sat May 13, 2006 2:24 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Code:
[NHMA.HibernateMapping(...)]
is only relevant when doing serialization class by class.

And the mapping of Bas (in NHMA.Test) has no real meaning, it is just used for testing purpose.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 15, 2006 4:07 am 
Newbie

Joined: Wed Mar 29, 2006 4:42 am
Posts: 11
Location: Ware, Herts., UK
Agreed. The HibernateMappingAttribute is not needed when serializing the whole assembly. Thank you for confirming this.

However, I still think you have a problem with your tests.

The Baz class uses the DefaultAccessTypeAttribute to emit a value into the default-access attribute. Please note the type of this.

Surely the DefaultAccessAttribute is the only attribute that should emit values into the default-access attribute.

And there isn't anywhere in the XSD schema that defines an attribute called default-access-type to match the .NET class DefaultAccessType.

And yes "Int32" has no real meaning, so why not use a sensible value like "field.camelcase_underscore" which is what is really expected in that attribute.

To me, the test code is incorrect and misleading.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 15, 2006 9:46 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
The documentation wrote:
For a Name taking a System.Type, set the type with Name="xxx" (as string) or NameType=typeof(xxx); (add "Type" to "Name")


This is the case for "default-access" because it is extensible to user defined classes.

Now, the Baz class do not use a DefaultAccessTypeAttribute but a DefaultAccessType property which sets the DefaultAccess to the FQN of the specified type.

"DefaultAccessType=typeof(int)" is here only to test the DefaultAccessType property.

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 15, 2006 11:26 am 
Newbie

Joined: Wed Mar 29, 2006 4:42 am
Posts: 11
Location: Ware, Herts., UK
I understand what you are saying, even though it is not immediately clear when looking at the test code what is intended.

Thank you for spending the time to explain that issue.


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

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.