5

I have a database on Oracle 11 XE and all my tables have primary keys that are NUMERIC(22,0). I have generated model classes with Hibernate tools in Eclipse. Unfortunately, all NUMERIC fields have been implemented as BigDecimals. Even fields representing INT columns are changed too. I tried some reverse engineering, but it seems not to work in my case.

How can I fix it?

xenteros
  • 15,586
  • 12
  • 56
  • 91

2 Answers2

1

You can customize the type mapping in Hibernate tools. Specify the mappings in the reveng.xml. Translate every JDBC type to a Hibernate type and run your generator again. E.g.

 <sql-type>jdbc-type="NUMERIC" precision="22" hibernate-type="Long"</sql-type>

see also: http://omtlab.com/java-hibernate-reverse-engineering-eclipse-tutorial/

wgitscht
  • 2,676
  • 2
  • 21
  • 25
1

You better use BIGINT instead of NUMERIC(22,0) for your IDs. Then re-generate the entities. The Java-IDs should be of type Long. If not you have to change the type manually. In general you should see generated entities more then a template which needs some modifications.

Reference: Mapping SQL and Java Types

Kai
  • 38,985
  • 14
  • 88
  • 103