title: Hibernate NamingStrategy implementation that maintains state between calls
body: <p>I'm working on a project where we use Hibernate and JBoss 5.1. We need our entity classes to be mapped to Oracle tables that follow a certain naming convention. I'd like to avoid having to specify each table and column name in annotations. Therefore, I'm currently considering implementing a custom implementation of <code>org.hibernate.cfg.NamingStrategy</code>.</p>
  
  <p>The SQL naming conventions require the name of columns to have a suffix that is equivalent to a prefix of the table name. If there is a table "T100_RESOURCE", the ID column would have to be named "RES_ID_T100".</p>
  
  <p>In order to implement this in a <code>NamingStrategy</code>, the implementation would have to maintain state, i.e. the current class name it is creating the mappings for. It would rely on Hibernate</p>
  
  <ul>
  <li>to always call <code>classToTableName()</code> before <code>propertyToColumnName()</code></li>
  <li>and to determine all column names by calling  <code>propertyToColumnName()</code> before the next call to <code>classToTableName()</code></li>
  </ul>
  
  <p>Is it safe to do that or are there situations where Hibernate will mix things up? I am not thinking of problems through multiple threads here (which can be solved by keeping the last class name in a <code>ThreadLocal</code>) but also of Hibernate deliberately calling this out of order in certain circumstances. For example Hibernate asking for mappings of three properties of class A, then one of class B, then again more attributes of class A.</p>