-->
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: Custom ReverseEngineeringStrategy & Optimistic Lock colu
PostPosted: Thu Feb 01, 2007 7:18 am 
Newbie

Joined: Tue Nov 28, 2006 8:50 am
Posts: 12
Location: Dublin, Ireland
Hi!
I am trying to extend the reverse engineering strategy in order to include "UPDATE_DT" as column name to be used for optimistic locking.
Extending the DelegatingReverseEngineeringStrategy as described below, I would expect that a "@Version" annotation for UPDATE_DT columns would be generated in my entity beans, but this does not seem to work.
My CustomReverseEngineeringStrategy gets called correctly and the entity beans are generated correctly except for the fact the the "@Version" annotations are missing for the UPDATE_DT columns.
Am I correct in assuming that if the method useColumnForOptimisticLock for a column of a table returns true, then the "@Version" annotation should be generated?
Hope some guru can help me! ;)
Kind regards,
Xserty

CustomReverseEngineeringStrategy class:
Code:
public class CustomReverseEngineeringStrategy extends DelegatingReverseEngineeringStrategy {
   private ReverseEngineeringSettings settings;

   private static Set<String> AUTO_OPTIMISTICLOCK_COLUMNS;
   static {
      AUTO_OPTIMISTICLOCK_COLUMNS = new HashSet<String>();
      AUTO_OPTIMISTICLOCK_COLUMNS.add("UPDATE_DT");
   }

   public CustomReverseEngineeringStrategy(ReverseEngineeringStrategy delegate) {
      super(delegate);
   }

   public void setSettings(ReverseEngineeringSettings settings) {
      System.out.println("settings.getDetectOptimsticLock(): " + settings.getDetectOptimsticLock());
      System.out.println("settings.getDetectManyToMany():    " + settings.getDetectManyToMany());
      System.out.println("settings.getDefaultPackageName(): " + settings.getDefaultPackageName());
      this.settings = settings;      
   }

   public boolean useColumnForOptimisticLock(TableIdentifier identifier, String column) {
      if (settings.getDetectOptimsticLock()) {
         if (AUTO_OPTIMISTICLOCK_COLUMNS.contains(column.toUpperCase())) {
            System.out.println("Column '" + column  + "' for table '" + identifier.getName() + "' should be used for Optimistic Locking");
            return true;
         } else {
            return false;
         }
      } else {
         return false;
      }
   }


Ant reverse engineering output excerpt:
Code:
[hibernatetool] Executing Hibernate Tool with a JDBC Configuration (for reverse engineering)
[hibernatetool] 1. task: hbm2java (Generates a set of .java files)
[hibernatetool] settings.getDetectOptimsticLock(): true
[hibernatetool] settings.getDetectManyToMany():    true
[hibernatetool] settings.getDefaultPackageName(): example.datalayer.model
[hibernatetool] Column 'UPDATE_DT' for table 'INTERNET_USERS' should be used for Optimistic Locking
[hibernatetool] Column 'UPDATE_DT' for table 'SYSTEM_USERS' should be used for Optimistic Locking


Generated entity bean excerpt:
Code related to the UPDATE_DT column:
Code:
    @Column(name="UPDATE_DT", length=7)
    public Date getUpdateDt() {
        return this.updateDt;
    }
   
    public void setUpdateDt(Date updateDt) {
        this.updateDt = updateDt;
    }


Hibernate Tools version: 3.2.0.b9

DB: Oracle 10g

Note: I'm not using/generating mapping files (*.hbm.xml).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 7:29 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes it *should*...maybe there is a bug in the annotation generation.

you can check that by generating annotated pojos from a hbm.xml with a version in it...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 8:24 am 
Newbie

Joined: Tue Nov 28, 2006 8:50 am
Posts: 12
Location: Dublin, Ireland
Hi Max,
Thanks for your prompt reply! :)
I tried generating the hbm.xml files and the UPDATE_DT columns have been correctly marked as:
Code:
<timestamp name="updateDt" column="UPDATE_DT" />

Then I tried what you suggested (generating annotated pojos from the hbm.xml) but got no @Version annotation in it.
I am currently setting up a project (using Eclipse) from the source code I've got from http://anonsvn.jboss.org/repos/hibernate/trunk (or should I use /branches/branch_3_2 for the latest?)... Could you please give me some advise on how to fix this? Please take into account that I'm new to al Hibernate! Are there any docs explaining how HibernateTool works?
Kind regards,
Xserty

max wrote:
yes it *should*...maybe there is a bug in the annotation generation.

you can check that by generating annotated pojos from a hbm.xml with a version in it...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 8:45 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ok so we have a bug/missing feature in our annotation generation.

For hibernate core you should use the branch_3_2

note that hibernate *tools* core are located in HibernateExt/tools

..and the plugins are in jbosside cvs.

look at tools.hibernate.org for docs and build instructions.


but for this specific bug it should be enough to look at fixing the templates in tools core.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 9:06 am 
Newbie

Joined: Tue Nov 28, 2006 8:50 am
Posts: 12
Location: Dublin, Ireland
Hi Max,
I was browsing Hibernate JIRA and just found out that this issue has been already submitted as a bug: HBX-688.
Thanks for all the information... will let you how I get on with it and maybe submit my first patch!! ;)
Thanks for your help!
Kind regards,
Xserty

max wrote:
ok so we have a bug/missing feature in our annotation generation.

For hibernate core you should use the branch_3_2

note that hibernate *tools* core are located in HibernateExt/tools

..and the plugins are in jbosside cvs.

look at tools.hibernate.org for docs and build instructions.


but for this specific bug it should be enough to look at fixing the templates in tools core.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 01, 2007 9:15 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yup, HBX-688 would be great to get a patch for

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 06, 2007 8:56 am 
Newbie

Joined: Tue Nov 28, 2006 8:50 am
Posts: 12
Location: Dublin, Ireland
Patch has been submitted to JIRA for evaluation...
Hopefully it will be included in the next release.
Kind regards,
Xserty


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.