Help

Built with Seam

You can find the full source code for this website in the Seam package in the directory /examples/wiki. It is licensed under the LGPL.

When using MS Sql Server or MySQL database servers, for example, it is possible that the primary key of your table is an identity column and thus auto-generated (i.e. auto-incremented during insert transactions).

When using seam-gen (or more specifically hbm2java tool via 'seam generate-entities' cmd line command), your resulting reverse engineered JPA entity class will not have a @GeneratedValue annotation by default.

In order to better handle this situation so you don't have to manually modify the constructors and add the @GeneratedValue yourself post-revengr process, try the following:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering SYSTEM "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>

  <!-- This file is intentionally generated empty by seam-gen -->
  <!-- You can add any filtering/setup you want for your app -->
  
  <!-- do not include EquipmentRecovery.sys.* objects from sys schema! -->
  
  <schema-selection match-schema="dbo"/>
    
  <table catalog="EquipmentRecovery"
         schema="dbo"
         name="ApplicationPermission">         
	  <primary-key>  
	      <generator class="identity"/>  
	  </primary-key>
  </table>
    
  <table catalog="EquipmentRecovery"
           schema="dbo"
           name="ApplicationRole">         
  	  <primary-key>  
  	      <generator class="identity"/>  
  	  </primary-key>
  </table>
  
  <table catalog="EquipmentRecovery"
             schema="dbo"
             name="ApplicationSetting">         
    	  <primary-key>  
    	      <generator class="identity"/>  
    	  </primary-key>
   </table>
  
  <table catalog="EquipmentRecovery"
             schema="dbo"
             name="ApplicationSettingChangeLog">         
    	  <primary-key>  
    	      <generator class="identity"/>  
    	  </primary-key>
  </table>
  
  <!-- you get the idea! -->
  

</hibernate-reverse-engineering>

Refer to the following section of the Hibernate Tools doc: My Link

Refer to this thread in Hibernate forum regarding this topic: My Link

It would be nice if hbm2java was able to auto-matically include these modifications/additions to our JPA entity classes without our explicit instructions (i.e. if hbm2java detects via the JDBC driver's database metadata info that the PK is an identity column with identity seed, then modify the constructors appropriately and add the @GeneratedValue annotation to the PK getter method).

Refer to the following section of the Hibernate Tools doc for more details on how to achieve this. According to Max Anderson in the thread above, it requires a custom implementation of org.hibernate.cfg.reveng.dialect.MetaDataDialect interface.

6.4. Custom Database Metadata

By default the reverse engineering is performed by reading using the JDBC database metadata API. This is done via the class org.hibernate.cfg.reveng.dialect.JDBCMetaDataDialect which is an implementation of org.hibernate.cfg.reveng.dialect.MetaDataDialect.

The default implementation can be replaced with an alternative implementation by setting the property hibernatetool.metadatadialect to a fully qualified classname for a class that implements JDBCMetaDataDialect.

This can be used to provide database specific optimized metadata reading. If you create an optimized/better metadata reading for your database it will be a very welcome contribution.