2017-01-09 6 views
0

私はSpring Bootを使用しており、IntelliJのデータベーススキーマからJava注釈付きクラスを生成したいとします。永続性ユニットなしでデータベーススキーマからJavaクラスを生成

私はPersistence -> Generate Persistence Mapping -> By Database Schemaに行くが、私はpersistence.xmlのファイルを持っていないので、私はクラスを生成することができないので、私はエラーを取得する:

JPA annotation mappings require at least one Persistence Unit

私は春ブーツにいるので...どのようにすることができます私がやる?

答えて

1

Mavenを使用している場合は、.reveng.xmlファイルとHibernate接続プロパティとともにhibernate3-maven-pluginを使用してMavenを使用できます。 http://tech.asimio.net/2016/08/04/Integration-Testing-using-Spring-Boot-Postgres-and-Docker.html#generating-jpa-entities-from-database-schema

db_dvdrental.reveng.xml

の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> 

db_dvdrental.hibernate.prop erties

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エンティティは、ターゲット/生成-ソース/ Hibernate3のと結果のパッケージで生成されたエンティティを生成するのsrc /メイン/ javaのにコピーする必要があります。

また、http://tech.asimio.net/2016/08/04/Integration-Testing-using-Spring-Boot-Postgres-and-Docker.htmlは、既存のスキーマからJPAエンティティを生成するためのより良い命令とデモのソースコードを提供します。

関連する問題