Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/368.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从数据库模式生成Java类而不使用持久性单元_Java_Intellij Idea_Spring Boot_Spring Data Jpa - Fatal编程技术网

从数据库模式生成Java类而不使用持久性单元

从数据库模式生成Java类而不使用持久性单元,java,intellij-idea,spring-boot,spring-data-jpa,Java,Intellij Idea,Spring Boot,Spring Data Jpa,我正在使用SpringBoot,我想从IntelliJ中的数据库模式生成Java注释类 我进入了Persistence->Generate Persistence Mapping->By Database Schema,但是我无法生成类,因为我没有Persistence.xml文件,所以我得到了错误: JPA注释映射至少需要一个持久性单元 我穿的是春装,所以。。。我该怎么做呢?如果您使用的是Maven,那么可以使用hibernate3 Maven插件以及.reveng.xml文件和Hiberna

我正在使用SpringBoot,我想从IntelliJ中的数据库模式生成Java注释类

我进入了
Persistence->Generate Persistence Mapping->By Database Schema
,但是我无法生成类,因为我没有Persistence.xml文件,所以我得到了错误:

JPA注释映射至少需要一个持久性单元


我穿的是春装,所以。。。我该怎么做呢?

如果您使用的是Maven,那么可以使用
hibernate3 Maven插件
以及
.reveng.xml
文件和
Hibernate
连接属性来完成

以下是我几个月前在以下网站上发表的一篇博客中的一个例子:

pom.xml

...
<properties>
...
  <postgresql.version>9.4-1206-jdbc42</postgresql.version>
...
</properties>
...
<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>hibernate3-maven-plugin</artifactId>
  <version>2.2</version>
    <configuration>
      <components>
        <component>
          <name>hbm2java</name>
          <implementation>jdbcconfiguration</implementation>
          <outputDirectory>target/generated-sources/hibernate3</outputDirectory>
        </component>
      </components>
      <componentProperties>
        <revengfile>src/main/resources/reveng/db_dvdrental.reveng.xml</revengfile>
        <propertyfile>src/main/resources/reveng/db_dvdrental.hibernate.properties</propertyfile>
        <packagename>com.asimio.dvdrental.model</packagename>
        <jdk5>true</jdk5>
        <ejb3>true</ejb3>
      </componentProperties>
    </configuration>
    <dependencies>
    <dependency>
      <groupId>cglib</groupId>
      <artifactId>cglib-nodep</artifactId>
      <version>2.2.2</version>
    </dependency>
    <dependency>
      <groupId>org.postgresql</groupId>
      <artifactId>postgresql</artifactId>
      <version>${postgresql.version}</version>
    </dependency>              
  </dependencies>
</plugin>
...
...
<hibernate-reverse-engineering>
  <schema-selection match-schema="public" />
</hibernate-reverse-engineering>
生成实体

hibernate.connection.driver_class=org.postgresql.Driver
hibernate.connection.url=jdbc:postgresql://localhost:5432/db_dvdrental
hibernate.connection.username=user_dvdrental
hibernate.connection.password=changeit
mvn hibernate3:hbm2java
JPA实体在target/generated sources/hibernate3生成,生成的包需要复制到src/main/java

同样,提供了更好的说明和演示源代码,以完成从现有模式生成JPA实体