-->
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: Reverse Engineering dynamic-update="true"
PostPosted: Mon Jun 02, 2008 4:32 pm 
Newbie

Joined: Mon Jun 02, 2008 4:20 pm
Posts: 4
Hello,


I have been having trouble trying to get the Hibernate tools reverse engineering to generate my hbm.xml files with dynamic-update="true". I am trying to implement optimistic locking and according to the hibernate docs, dynamic-update has to be set to true. Can someone help me out here?

Here's my custom ReverseEngineeringStrategy.

Code:
package com.voyager.vpd.hibernate.reveng;


import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.cfg.reveng.DelegatingReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.ReverseEngineeringStrategy;
import org.hibernate.cfg.reveng.TableIdentifier;

public class VPDReverseEngineeringStrategy extends DelegatingReverseEngineeringStrategy {
  private static Logger log = Logger.getLogger(VPDReverseEngineeringStrategy.class);
  private static final String COL_OPTIMISTIC_LOCK = "ModifiedDate";
 
  public VPDReverseEngineeringStrategy (ReverseEngineeringStrategy delegate) {
    super(delegate);
  }
 
  /**
   * Overrides the default generation strategy from assigned to native.
   */
  @Override
  public String getTableIdentifierStrategyName(TableIdentifier tableIdentifier) {
    String configuredName = super.getTableIdentifierStrategyName(tableIdentifier);
    if (configuredName == null) {
      configuredName = "native";
      log.debug("Used default strategy of " + configuredName);     
    }else {
      log.debug("Used configured strategy of " + configuredName);
    }
    return configuredName;
  }

  /**
   * Overrides the default collection name generation.
   * Fixes generation of names like 'AccessKeyies', 'Surveyies', etc...
   */
  @Override
  public String foreignKeyToCollectionName(String keyname, TableIdentifier fromTable, List fromColumns,
      TableIdentifier referencedTable, List referencedColumns, boolean uniqueReference) {
    String collectionName = fromTable.getName();
   
    if (collectionName.matches(".*[a,e,i,o,u]y$")) {   
      collectionName += "s";
      log.debug("Set name configured as " + collectionName);
    }else {
      collectionName = super.foreignKeyToCollectionName(keyname, fromTable, fromColumns, referencedTable, referencedColumns, uniqueReference);
      log.debug("Set name configured as " + collectionName + "(hibernate tools default)");
    }
   
    return collectionName;
  }
 
  @Override
  public boolean useColumnForOptimisticLock(TableIdentifier identifier, String column) {
    if (column.equals(COL_OPTIMISTIC_LOCK)) {
      log.debug("using " + column + " for optimistic locking");
      return true;
    }else {
      return false;
    }       
  }

  @Override
  public String getOptimisticLockColumnName(TableIdentifier identifier) {
    log.debug("called getOptimisticLockColumnName on table: " + identifier.getName());
       
    return COL_OPTIMISTIC_LOCK;
  }

}


Thanks

_________________
- wooglin280


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 03, 2008 3:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I suggest you adjust your mapping files manually.

We don't support ever conceivable mapping via reverse engineering.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2008 2:59 pm 
Newbie

Joined: Mon Jun 02, 2008 4:20 pm
Posts: 4
Thanks for the reply. I will update my mapping files manually. However, i believe this to be a bug. If the wizard for Reverse Engineering has a check box to automatically detect optimistic locking it should also enable dynamic update, otherwise, optimistic locking is not truly enabled.

Any thoughts???

_________________
- wooglin280


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 05, 2008 8:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
huh ?

optimstic locking works perfectly fine without dynamic update.

When the docs say optimistic locking it is talking about <timestamp/> and/or <version/> not about field based optimstic locking.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 05, 2008 11:28 am 
Newbie

Joined: Mon Jun 02, 2008 4:20 pm
Posts: 4
Here is an excerpt from the Hibernate Core documentation.

Quote:
If you enable dynamic-update, you will have a choice of optimistic locking strategies:
• version check the version/timestamp columns
• all check all columns
• dirty check the changed columns, allowing some concurrent updates
• none do not use optimistic locking
We very strongly recommend that you use version/timestamp columns for optimistic locking with Hibernate.
This is the optimal strategy with respect to performance and is the only strategy that correctly handles modifications
made to detached instances (ie. when Session.merge() is used).


I've also done some tests on my own to verify. The column i'm using for my <timestamp> is ModifiedDate.

If dynamic-update is not set to true the SQL generated is something like this:
Code:
UPDATE ... FROM ... WHERE id = ?


If dynamic-update is set to true the SQL generated is something like this:
Code:
UPDATE ... FROM ... WHERE id = ? and ModifiedDate = ?


Am i misunderstanding the documentation and/or what optimistic locking is all about? Can you explain?

Thanks

_________________
- wooglin280


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 05, 2008 5:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
The docs you refer to is saying you get *all* of the options enabled if you do that.

dynamic-update is not a requirment for version/timpstamp columns.

Look in the unit tests for hibernate - there are tons of <version> tags where dynamic-update="false" or simply just not set.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 10, 2008 3:34 pm 
Newbie

Joined: Mon Jun 02, 2008 4:20 pm
Posts: 4
Thanks Max. After reviewing the hibernate unit tests and double checking my test with dynamic-update="true" or "false", it appears that it does add the and modifiedDate = ? in either case.

_________________
- wooglin280


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.