-->
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: New NHibernate.Mapping.Attributes questions
PostPosted: Sun Sep 18, 2005 4:20 am 
Newbie

Joined: Sun Sep 18, 2005 4:11 am
Posts: 11
Hi,

I have used Hibernate and Xdoclet for a while, and I'm learning how to use their .NET counterparts. Here's a few questions on the new NHibernate.Mapping.Attributes implementation included in NHibernateContrib 0.9.1:
1. Why do we need a int position in attribute constructor? It seems that it is only used when there're more than one attribute on an element.
2. Why does HbmWriter and HbmSerializer use a lot of static methods and properties? This makes it hard to extend them or config them in Spring.
3. What's the best way to customize id column name by classes' table name: I have an id property in base class, and I would like id column's name to be "${table_name}_ID" where ${table_name} is the name of the domain class's table name. (Edit: XSLT seems to be the only way to handle this)
4. How to use Component:
-- I have a value type ChangeRecord which will be used in multiple entities
-- In order to organize the entities, I used a base class BaseEntity, which has a property of type ChangeRecord:
Code:
public class BaseEntity
{
    private ChangeRecord _record;

    public ChangeRecord ChangeRecord
    {
        get{ return _record; } set { _record = value; }
    }
}
[Class]
public class Entity1 : BaseEntity
{
    ...
}

-- Note BaseEntity is not marked by Class attribute, since it's the base class; Entity1 is marked as Class.
-- Now the question is how to use Component attribute on this setup? I searched the forum, but it seems that the suggested solution is to create a subclass of ChangeRecord for each entity class marked by Class attribute (for example, Entity1). This clearly is not an optimal solution, since the whole point of pulling ChangeRecord property up to BaseEntity is to avoid putting it in subclasses.
-- HbmWriter seems to only allow component class as a nested class inside the parent class, this restriction is annoying especially considering the point of using a component is for reuse.

Thanks

Jim


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 19, 2005 11:38 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
1. To keep the attributes ordered.
2. Most NHMA code is generated and HbmSerializer has static methods because I didn't see any reason to do another way... But you can easily change that if you want.
What kind of extending/configuration are you doing with Spring?

4. The way <component> is handled in NHMA is based on the fact that it is generated... I may find out a solution, but haven't take the time for...
Adding
Code:
[Component] private class SubYourComponent : YourComponent {}

for each class, is annoying; but I think that it is reasonnable (there is no duplication/overhead) :wink:

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


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 21, 2005 1:15 am 
Newbie

Joined: Sun Sep 18, 2005 4:11 am
Posts: 11
I see most of the problems rooted from the fact that the code is generated... While we can work around these problems, I think some impovements are definitely due once NHibernate matures.

I considered extending HbmWriter to solve problem #3, but the method for writing the Id element is both static and private, which makes it impossible. I'd also like to set HbmSerializer's properties in Spring.NET so that I can customize the map xml generated (namespace, default cascade, etc), and pass an instance of the serializer to my session factory factory (which will generate xml on the fly based on attributes and create a session factory based on it, basically a substitute before NHibernate can support attribute directly). Besides, by making Error property static, we have to clear it before each use, which is bad.

For the component problem, yes, I did see the work around, but this would really become a maintenance nightmare if used extensively. I guess until a better way is found to generate the attributes, XSLT is our only hope...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 23, 2005 2:11 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
ok ok, I started working on all that... Should be available in the next version :wink:

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


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 24, 2005 5:48 am 
Newbie

Joined: Sun Sep 18, 2005 4:11 am
Posts: 11
Ok, thanks! There's no need to be in a hurry, as long as you recognize them as something that could use an improvement, I'm happy :)


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 24, 2005 8:14 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Done :)

I added: DiscriminatorValueObject and DiscriminatorValueEnumFormat for NH-373 and [ComponentPropertyAttribute] for NH-374.

I will update the doc later...

Do you know any other property which may take an object (like <discriminator-value>?)

Because you can't build a full graph with .NET Attributes, there are few constraints in NHMA... (I will add them to the doc)

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


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 27, 2005 10:44 am 
Newbie

Joined: Sun Sep 18, 2005 4:11 am
Posts: 11
That's great, I'll take a look at the new changes.

I haven't encounter other limitations of the attributes yet, these two are the most obvious ones when I'm working on my domain objects...


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