Hi all,
I'm quite new to hibernate and I'm using Hibernate tool with reveng strategy to start learning it.
Here is my situation:
I have a table on mysql database similar to this:
CREATE TABLE `Player` (
`id` int(10) NOT NULL auto_increment,
`base_str` int(10) NOT NULL default '5' COMMENT 'strength',
`base_int` int(10) NOT NULL default '5' COMMENT 'intelligence',
...);
As you can see the id row is an autoincrement, while other columns are integer with a default value.
What I want to do is to insert new data using default values when not specified.
To do so i looked into the forum and found the following working solution.
1) map all INTEGER to java.lang.Integer instead of base 'int' so that values can have 'null' value. (Put an excetopn for id colum to keep autoincrement working)
2) declare class Player with dynamic-insert="true" option so that null values are omitted from the insert.
3) Decalre all Integer columns with not-null="false" to allow null values.
This solutions works fine and let me insert a new row without having to specify all fields manually.
What I'm trying to do now is to implement all this logic inside my hibernate.reveng.xml file to keep using automatic class/mapping generation with hibernate tools.
Sadly i noticed that using the following syntax:
Code:
<type-mapping>
<sql-type jdbc-type="INTEGER" hibernate-type="java.lang.Integer" not-null="false"/>
</type-mapping>
...
<table catalog="mikesac" name="Player">
<column name="id" type="int">
<meta attribute="not-null">true</meta>
</column>
</table>
Hibernate tools do not create the pojo correctly!
without using "not null" attibute into sql-type all is generated fine: id is int all other columns are Integer.
but if i add the not-null="false" attribute then all columns are generated as int :-(
moreover i see that Hibernate tool generate mapping files with not-null="true" attribute by default on every column, while i need to override it to false.
Code:
<property name="baseInt" type="int">
<column name="base_int" not-null="true">
</column>
</property>
can someone give me some hint on how to proceed?
the the first problem look like an Hibernate tool bug, did someone already got it?
The not-null attribute on type mapping is explicitly allowed also by the eclipse graphical interface, so I can't understand whit it mess everything up. :-(((
I think the second problem is strictly related to the first one but maybe some workaround could solve it.
thanks in advance for every suggestion.
regards
Michele