[hibernate-issues] [Hibernate-JIRA] Commented: (HBX-752) Add meta attribute property-code, pre/post conditions code

David Leal (JIRA) noreply at atlassian.com
Sun Sep 17 09:59:24 EDT 2006


    [ http://opensource.atlassian.com/projects/hibernate/browse/HBX-752?page=comments#action_24523 ] 

David Leal commented on HBX-752:
--------------------------------

Max and other,

With the Max help I have found the solution via template modification, you can see the discussion on forum about that:

http://forum.hibernate.org/viewtopic.php?t=964523#2321689 

any way this solution, on my opinion has some disavantages:

1. If you have n-pre/post conditions for your classes, you have to define at least n meta-properties.

2. All such preconditions are agglutinated on a template file, so when some one looks into *.hbm file (usually we work on in a team), he/she has to assume that such property is used on a template file (another sintax language: free marker and understand it), unless you document at every place, please look into the following template file in order to finally see what precondition is that.

3. The *.hbm files therefore are not self consistent, you have to look also into some additional template file in order to understand your business particularity about setting a given property, your business is located also on a template file.

Now about my approach:

1. You don't have to define n-meta properties if hibernatetools provides the properties: pre-condition, post-condition.

2. All your busines is defined on: *.hbm file. It is self consistent.

3. It is a natural extension to meta attribute class-code, but for the methods.

4. You can add your pre/post condition using only Java, you don't need to know FreeMarker for adding so simple modification to the generated code.

5. It seems to be easy to implement, in a similar way to getExtraClassCode()} method.

Note: I can see the contains of POJOClass.java on:
http://anonhibernate.labs.jboss.com/trunk/HibernateExt/tools/src/java/org/hibernate/tool/hbm2x/pojo/
you get an HTML file instead of java)

It is more a conceptual issue about the hibernate tools philosofy rather than a tecnical limitation about implementing this feature. On my opinion if you open the door in order to allow users can add additional source code for classes you should consider also the posibility of adding some minimal modification to the accessor methods (for example pre/post conditions, assert conditions, etc)

Thanks for your interest on my suggestion,

David

P.D.: If I have persuaded to you, it seems to be a hard task, :-), please let me know how to help your for the implementation. Thanks.


> Add meta attribute property-code, pre/post conditions code
> ----------------------------------------------------------
>
>          Key: HBX-752
>          URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-752
>      Project: Hibernate Tools
>         Type: Improvement

>   Components: hbm2java
>     Versions: 3.2beta7
>     Reporter: David Leal
>     Priority: Minor

>
>
> Just to suggest to add a new meta attribute like class-code, but for properties. Some times you need to add some pre-condition or post-condition for a set/get method. For example a particular property has to be possitive, not all databases could control this condition, so you have to control it via source code, for example to add a pre-condition on a set operation. 
> The hbm2java allow to add additional methods/imports, for example via class-code meta attribute, but for the generation properties the user doesn't have any control about the generated code.
> My suggestion is to add three possible meta-attributes:
> property-get/set-code: For setting the hole generated code for a particular property, with a non-default set/get code generation.
> pre-get/set-code: Just add a precondition code to the generated source code.
> post-get/set-code: Just add a postcondition code, at the end of the code generation, for a particular property.
> All three properties can be specified for get/set operation.
> About this topic I have asked to the forum, 
> http://forum.hibernate.org/viewtopic.php?t=964523#2321689
> but the solution was to modify the template, wich in my humble opinion is a kind of brute force for this simple modification.
> Thanks in advance,
> David Leal

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list