[jboss-user] [JBoss Tools] - Re: Hibernate Tools question

Max Rydahl Andersen do-not-reply at jboss.com
Fri Sep 14 03:11:54 EDT 2012


Max Rydahl Andersen [https://community.jboss.org/people/maxandersen] created the discussion

"Re: Hibernate Tools question"

To view the discussion, visit: https://community.jboss.org/message/759541#759541

--------------------------------------------------------------
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 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
[https://community.jboss.org/message/759541#759541]

Start a new discussion in JBoss Tools at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2128]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120914/3d18b9ee/attachment.html 


More information about the jboss-user mailing list