Hibernate 使用Maven从现有数据库生成JPA2实体
我想做同样的事情,但是使用maven构建Hibernate 使用Maven从现有数据库生成JPA2实体,hibernate,maven,jpa,Hibernate,Maven,Jpa,我想做同样的事情,但是使用maven构建 请推荐插件。当我在谷歌上搜索时,我发现了使用JPA注释实体生成的JPA元模型。没有找到任何与此问题相关的内容 您应该尝试MinuteProject:(它生成maven项目) 由于您使用的是hibernate,因此默认选项是,更具体地说,配置了true的hibernate3:hbm2java目标。它将生成带注释的POJO(大多数注释来自标准的javax.persistence包,但也可能包括定制的org.hibernate.annotations) 请访
请推荐插件。当我在谷歌上搜索时,我发现了使用JPA注释实体生成的JPA元模型。没有找到任何与此问题相关的内容 您应该尝试MinuteProject:(它生成maven项目)
由于您使用的是hibernate,因此默认选项是,更具体地说,配置了
true
的hibernate3:hbm2java
目标。它将生成带注释的POJO(大多数注释来自标准的javax.persistence
包,但也可能包括定制的org.hibernate.annotations
)
请访问查看示例配置 您可以使用。要使用它,您可以使用以下配置:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<h2.version>1.4.200</h2.version>
<hibernate-tools-maven-plugin.version>5.4.11.Final</hibernate-tools-maven-plugin.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-tools-maven-plugin</artifactId>
<version>${hibernate-tools-maven-plugin.version}</version>
<dependencies>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<!-- DB Driver of your choice -->
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>${h2.version}</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>Display Help</id>
<phase>validate</phase>
<goals>
<goal>help</goal>
</goals>
</execution>
<execution>
<id>Entity generation</id>
<phase>generate-sources</phase>
<goals>
<goal>hbm2java</goal>
</goals>
<configuration>
<ejb3>true</ejb3>
<jdk5>true</jdk5>
</configuration>
</execution>
<execution>
<id>Schema generation</id>
<phase>generate-resources</phase>
<goals>
<goal>hbm2ddl</goal>
</goals>
<configuration>
<delimiter>;</delimiter>
<haltOnError>true</haltOnError>
<format>true</format>
</configuration>
</execution>
</executions>
<configuration>
<revengFile>${project.basedir}/src/main/hibernate/hibernate.reveng.xml</revengFile>
<configFile>${project.basedir}/src/main/hibernate/hibernate.cfg.xml</configFile>
<detectManyToMany>true</detectManyToMany>
<detectOneToOne>true</detectOneToOne>
<detectOptimisticLock>true</detectOptimisticLock>
<createCollectionForForeignKey>true</createCollectionForForeignKey>
<createManyToOneForForeignKey>true</createManyToOneForForeignKey>
</configuration>
</plugin>
</plugins>
</build>
我们使用hibernate.reveng.xml
文件来定制映射类型配置,例如为了使用java.time
类型,我们可以使用:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering SYSTEM
"http://hibernate.org/dtd/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<type-mapping>
<sql-type jdbc-type="DATE" hibernate-type="java.time.LocalDate"/>
<sql-type jdbc-type="TIMESTAMP" hibernate-type="java.time.LocalDateTime"/>
</type-mapping>
</hibernate-reverse-engineering>
完整的项目将于年月日提供。实现这一目标的正式项目是。下面是一个博客,详细解释了如何集成插件
有没有一种日食式的方法可以做到这一点?netbeans/eclipse在内部做什么?Kalpesh,实际上您也可以使用HibernateMaven插件(它将使用这些设置生成干净的JPA实体)。我不确定是否有专门针对eclipselink的maven工具(这是一个好问题)。我也不确定Dali和Netbeans在内部做什么。我刚刚为此创建了一个博客:不幸的是wikispaces不再运行。你知道其他类似的工具吗?
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering SYSTEM
"http://hibernate.org/dtd/hibernate-reverse-engineering-3.0.dtd" >
<hibernate-reverse-engineering>
<type-mapping>
<sql-type jdbc-type="DATE" hibernate-type="java.time.LocalDate"/>
<sql-type jdbc-type="TIMESTAMP" hibernate-type="java.time.LocalDateTime"/>
</type-mapping>
</hibernate-reverse-engineering>