Are there any tools that auto-generate the hibernate POJOs by gathering information from the database?
I made a perl script to do this after the schema got changed for the third or fourth time in a project i'm working with and just wondered if there is any established tool that will do this for me as my script is rather crude and needs some tweaking of the generated .java
and .hbm.xml
files.
For example (based on what my script does), having a table statement
:
Object_Name Type_Name Base_Type Nulls Identity
------------ --------- --------- ----- --------
id id_int int no yes
id_user id_tiny tinyint no no
value float float no no
I would like the program to autogenerate the following java:
package com.some.company.schema;
import java.io.Serializable;
public class Statement implements Serializable {
private static final long serialVersionUID = 1227171190L;
private Integer id;
private User user;
private Float value;
public void setId(Integer id){
this.id = id;
}
public Integer getId(){
return this.id;
}
public void setUser(User user){
this.user = user;
}
public User getUser(){
return this.user;
}
public void setValue(Float value){
this.value = value;
}
public Float getValue(){
return this.value;
}
}
And the corresponding Hibernate mapping file:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.some.company.schema.Statement" table="statement">
<id name="id" column="id">
<generator class="native" />
</id>
<many-to-one name="user" class="com.some.company.schema.User" column="id_user" not-null="true" />
<property name="value" column="value" not-null="true" />
</class>
</hibernate-mapping>