JBoss Community

Re: Hibernate Tools question

created by Max Rydahl Andersen in JBoss Tools - View the full discussion

Any particular reason your columns doesn't have not-null set ?

 

in hbm.xml you can add a "default-value" meta-attribute.

 

<property name="content" type="string" length="10000">  
  <meta attribute="default-value"></meta>
 </property>

 

that will make it generate:

 

content = ""

 

For reverse engineering this is trickier, but there are two options.

 

Create a reveng.xml file that sets <meta> for the columns you need it for.

Example of that can be found at https://github.com/hibernate/hibernate-tools/blob/master/src/test/org/hibernate/tool/test/jdbc2cfg/overridetest.reveng.xml#L58

 

Mind you that reveng.xml is "additative" meaning you can just specify the column name, everything else will come from jdbc.

 

If that is not enough you would need to implement a ReverseEngineeringStrategy that has a method similar to:

 

public Map columnToMetaAttributes(TableIdentifier identifier, String column) {
                    Map result = new HashMap<String, MetaAttribute>();
  
                    MetaAttribute ma = new MetaAttribute("default-value");
  
                    String defaultValue = logicToFigureOutValueBasedonTableColumn(identifier, column);
  
                    ma.addValue(defaultValue);
                    result.put("default-value", ma);
                    return result;
 }

Reply to this message by going to Community

Start a new discussion in JBoss Tools at Community