---
title: "hibernate3-maven-plugin 配置"
author: "kabuka"
date: "2012-04-06T17:17:28Z"
tags: []
categories: ["编程语言"]
slug: "hibernate3-maven-plugin"
draft: false
lastmod: "2012-04-06T17:17:28Z"
id: 1477594
url: "https://kabuka.iteye.com/blog/1477594"
---

使用hibernate3-maven-plugin 可根据hibernate 或JPA的配置导出建表脚本，根据表结构导出java类，如下是根据JPA的配置信息导出建表脚本的例子：

 

 

```
<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>hibernate3-maven-plugin</artifactId>
				<version>2.2</version>
				<executions>
					<execution>
						<goals>
							<goal>hbm2ddl</goal>
						</goals>
					</execution>
				</executions>
				<configuration>
					<components>
						<component>
							<name>hbm2ddl</name>
							<implementation>jpaconfiguration</implementation>
							<outputDirectory>src/main/db</outputDirectory>
						</component>
					</components>
					<componentProperties>
						<persistenceunit>PersistenceUnit</persistenceunit>
						<outputfilename>schema.ddl</outputfilename>
						<drop>false</drop>
						<create>true</create>
						<export>false</export>
						<format>true</format>
					</componentProperties>
				</configuration>
			</plugin>
```

 

其中persistenceunit 与persistence.xml文件的持久单元名称保持一致。

 

运行时使用 mvn:hibernate3:hbm2ddl