从休眠映射文件生成类
问题描述:
我有一个映射文件即, student.hbm.xml ..我需要从相同的生成Student.java。该文件是如下: -从休眠映射文件生成类
<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping>
<class name="org.hibernate.entity.ClassRoom" table="class_room">
<id name="roomId" column="room_id" type="int"/>
<property name="roomClass" column="room_class" type="string"/>
<property name="floor" column="floor" type="int"/>
<property name="roomMaster" column="room_mast" type="string"/>
</class>
</hibernate-mapping>
有没有什么办法可以创建从上述file.please帮助类文件...
答
您需要Hibernate Tools(将其安装在eclipse中)。
OR
开发定制的Maven插件...(以下提供的示例代码)
/**
* Generate POJO from *.hbm.xml
* Example Usage: mvn prefix:hbm2pojo OR
* mvn prefix:hbm2pojo -Dexec.args="com.comp.Product,com.comp.Item"
*
* @goal hbm2pojo
*/
public class GenerateHibernatePojoMojo extends AbstractMojo
{
/** Directory for hibernate mapping files
* @parameter expression="${basedir}/src/main/resources"
* @required
*/
private File hbmDirectory;
/** Output directory for POJOs
* @parameter expression="${project.build.sourceDirectory}"
* @required
*/
private File outputDirectory;
/** set to true if collections need to use generics. Default is false.
* @parameter expression="${jdk5}" default-value="false"
* @optional
*/
private String jdk5;
public void execute() throws MojoExecutionException, MojoFailureException
{
POJOExporter exporter = new POJOExporter();
exporter.setOutputDirectory(outputDirectory);
Configuration config = new Configuration();
config.setProperty("jdk5", jdk5);
String args = System.getProperty("exec.args");
if (args != null && !"".equals(args))
{
String[] entityNames = args.split(",");
for(String entityName : entityNames)
{
File hbmFile = new File(hbmDirectory + "/" + entityName.replace('.', '/') + ".hbm.xml");
config.addFile(hbmFile);
}
}
else
{
config.addDirectory(hbmDirectory);
}
exporter.setConfiguration(config);
exporter.start();
// TODO this guy also generates unwanted POJOs like POJO of component
// TODO Add support for Java 5 Generic
}
}
- SE
+0
你能告诉我从哪里得到maven jar。 – 2010-06-08 13:02:39
+0
你能否详细说明你的问题? 顺便说一句,你可以从http://repo1.maven.org/maven2/获得所有大多数的罐子。 - - SE – dira 2010-06-09 04:43:49
的可能重复[POJO来自HBM文件](http://*.com/questions/ 2711408/pojo-from-hbm-file) – naXa 2014-12-02 13:30:44