How can I create (if I can) a template file for my hbm.xml files to use while they are being created from JAVA class?
I am using Jboss Hibernate Tools 3.5.1 and Eclipse Indigo
You can find a detailed description below.
Thanks for your help.
My JAVA classes are coded carefully to represent the sql table. they all have the same syntax.
for instance lets say I have the following table in my db:
Tests (id int primary key, TestData varchar(255), Type int)
a class referring to this table is:
public class TestData {
int id;
String testData;
int type;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getTestData() {
return testData;
}
public void setTestData(String testData) {
this.testData = testData;
}
public int getType() {
return type;
}
public void setType(int type) {
this.type = type;
}
}
When I create an automated hbm.xml file for this class it comes out as:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 12.Ara.2013 12:33:42 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="com.entegrator.framework.persistent.TestData" table="TESTDATA">
<id name="id" type="int">
<column name="ÝD" />
<generator class="assigned" />
</id>
<property name="testData" type="java.lang.String">
<column name="TESTDATA" />
</property>
<property name="type" type="int">
<column name="TYPE" />
</property>
</class>
</hibernate-mapping>
as you can see, my first problem is encoding. what else I want to do is
- property column names and class table name should be converted appropriately
- id generator class should be "identity"
You have to change them manually if you are creating
hbm
file using eclipse.Other options are you can use annotations or create files our own to remove this extra headache.!!!
you can get more about the same at Hibernate