Menu

type-mapping

Harry Gardner

There are a default set of database to java type mappings supported by DAL4j. To add additional types or over-ride how a database type is mappped, the XML configuration file used to drive code generation can be modified. To define custom type mappings, add the following to the XML configuration file between <entityBeanGenConfig> ... </entityBeanGenConfig>.

<entityBeanGenConfig>

...

 <types>
    <type>
       <databaseType>some_db_type</databaseType>
       <javaType>SomeJavaTypeWhichInheritsFromObject</javaType>
    </type>
    <type>
       <databaseType>some_db_type2</databaseType>
       <javaType>SomeJavaTypeWhichInheritsFromObject</javaType>
    </type>
 </types>

...

</entityBeanGenConfig>

If a database type with a specific size should have a mapping defined, define it as: db_type(X). Note that type mappings by size of a defined column are always resolved before type mappings w/out a size specified. So, it is possible to have tinyint(1) and tinyint mappings defined.

Here is an example to map tinyint(1) to a boolean and tinyint to Byte

 <types>
    <type>
       <databaseType>tinyint(1)</databaseType>
       <javaType>Boolean</javaType>
    </type>
    <type>
       <databaseType>tinyint</databaseType>
       <javaType>Byte</javaType>
    </type>
 </types>

NOTE: The tinyint type mappings above are supported by default.

The default type mappings supported by DAL4j are:

  DB_TYPE -> JavaTypeWhichInheritsFromObject

  "varchar" -> "String"
  "char" -> "String"
  "varchar2" -> "String"
  "text" -> "String"
  "int" -> "Integer"
  "int identity" -> "Integer"
  "smallint" -> "Integer"
  "number" -> "Integer"
  "tinyint" -> "Byte"
  "tinyint(1)" -> "Boolean"
  "bit" -> "Boolean"
  "bigint" -> "Long"
  "bigint identity" -> "Long"
  "datetime" -> "Date"
  "date" -> "Date"
  "Time" -> "Date"
  "smalldatetime" -> "Date"
  "timestamp" -> "Date"
  "float" -> "Float"
  "double" -> "Double"
  "decimal" -> "Double"
  "image" -> "byte []"
  "blob" -> "byte []"

Related

Wiki: Home

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.