私はHibernateとSpringBootに新しいです。両方に+ 1、ベースモジュールの共通の2つの独立したモジュール(で構成されている検索エンジンで自分のプロジェクトディールIndexSetup
クラスが存在します)。
1つのインデックス(JavaFXの)ためのモジュールとWebブラウザ(春ブーツ)を介して検索するための他の一つはあります。
インデックスモジュールは、どのようなインデックスを作成する方法/の詳細を持っている「IndexSetup」クラスが含まれます。
@Entity
@Table(name = "IndexSetups")
@Access(AccessType.PROPERTY)
public class IndexSetup {
private final SimpleIntegerProperty id = new SimpleIntegerProperty();
@Id
@GeneratedValue(strategy = GenerationType.AUTO) // For H2 AUTO is required to auto increment the id
public int getId() {
return id.get();
}
//... other properties, getters and setters
}
それは素晴らしい作品ので、データがインデックス化され、索引付けモジュール内の検索メソッドを介して取得することができます。
しかし、私は春のブートサーバーを実行して、同じ検索I GET java.lang.IllegalArgumentExceptionがやるとき:未エンティティ:クラスをmy.package.IndexSetup
ところで何のビルドエラーが存在しない、とモジュールは、親ポンポンプロジェクトの一部だった前に、彼らは、サブフォルダ内のサーバクラスと同じプロジェクトにあった、それが働きました。私はdeveloppment時の利便性のためにそれらを分離するために、生産に2つの独立したモジュールを提供することを決めました。
すべてはモジュールが2つの異なるサブフォルダ内にあることを、今、同じNetBeansプロジェクトの下にあったとするとき、なぜそれが動作しなかった(が、同じグループIDパッケージ「my.package」に)私は、この「未実体」を取得し、私が何をすべきこれを解決するために、私はどこを見て必要がありますか?
してください注:私はすでに試したこれを(「nullポインタ例外は、データベースをロードすることはできません」)は、成功せず。
編集1:私はまた、追加しようとしました@EntityScan
、以下の本が、私はまだ取得Not an entity: class my.package.IndexSetup
:
@SpringBootApplication
@EntityScan( basePackages = {"my.package"} )
public class ServerApplication {
public static void main(String[] args) {
SpringApplication.run(ServerApplication.class, args);
}
}
編集2:プロジェクトのアーキテクチャは次のようです:
- Parent project (my.package)
-Module Base (with IndexSetup class)
-Module Indexing (that depends on Base)
-Module Server (that also depends on Base)
親のpom.xmlには、次のように読み取ります。
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>my.package</groupId>
<artifactId>MyApp</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!--According to https://stackoverflow.com/questions/10665936/maven-how-to-build-multiple-independent-maven-projects-from-one-project-->
<modules>
<module>Base</module> <!-- Common resources which is a dependency in Indexer and Server -->
<module>Indexer</module> <!-- Indexing part with JavaFx-->
<module>Server</module> <!-- Server (spring boot) part of -->
</modules>
<name>MyApp</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<bootclasspath>${sun.boot.class.path}${path.separator}${java.home}/lib/jfxrt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${java.home}/lib/jfxrt.jar</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugins>
</build>
編集3:表が指定されているを見てたときから、問題の発生元:
Root<IndexSetup> from = criteriaQuery.from(IndexSetup.class);
見てみると休止ソースは not an entity
いつでも投げられますentityType == null
。それは外SpringBootの作品に対しエンティティタイプがここにnullである理由を収集していない私はそう?
編集4:私は削除した場合SpringApplication.run(ServerApplication.class, args);
、問題の原因となった、すなわち、[サーバークラスのmainメソッドと同じ呼び出しから:
LocalDatabase.getInstance(false) // no GUI
.getAllIndexSetups();
今picobello動作します。私はまだ検索にSpringBootを必要とするので、もちろん、それは何も解決しません!だから、私にとってそれは春ブーツが休止状態の設定を理解していないことを意味します。私は開いて新しい質問より正確な問題を紹介するが。
すべてのヘルプは大歓迎しました、
私が正しくSpringBoot機能を使用していないことが起こったので。ここで私は、その後の手順があります。プロジェクトのアーキテクチャを覚えておいてください。
- Parent maven project (my.package)
|-Module Base (with IndexSetup class and [initialy] hibernate.cfg.xml in /resources. It also had in the beginning LocalDatabase class to access to the local db via hibernate)
|-Module Indexing (that depends on Base)
|-Module Server (that also depends on Base)
|-Database file (myLocalDB)
1)まず、Iを除去hibernate.cfg.xml
塩基から、およびインデックス・モジュールのリソースにそれを落としました。SpringBootは独自の構成メカニズムを持っているので、私はそれをやりました。私は(それがSpringBootによって必要とされないので)もベースからLocalDatabaseクラスを削除し、(それが実際に使用されている)インデックスモジュールでもそれを落としました。
2)この(後https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html] Iは、追加spring-boot-starter-data-jpa
サーバーモジュールのpom.xmlに。
3)続いて、このチュートリアル私はJPAリポジトリを作成したIndexSetupRepository
コードのほとんど一行で:
public interface IndexSetupRepository extends CrudRepository<IndexSetup, Integer> {
}
4)サーバーでapplication.properties
Iは、これらのラインを追加しました。
# Embedded database configuration
# The embedded database file is one level above the Server folder (ie directly within the parent project)
# we use the auto server mode to be able to use the database simultaneously in the indexer and the server
spring.datasource.url=jdbc:h2:file:../myLocalDB;AUTO_SERVER=TRUE
spring.datasource.username=myName
# This parameter helped me discover that SpringBoot was not targetting the right table name.
spring.jpa.hibernate.ddl-auto=validate
SpringBootが、それはという名前のテーブルを見つけることができなかった私に言ったので5) index_setup
(参照キャメルケースは_に変換)、私はapplication.propertiesに次の行を追加する必要がありました:
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
私は「エンティティ管理していない」しまったとして6)今、私は最終的に追加@EntityScan
あなたの多くがそうするように私に助言してサーバーのメインクラスに注釈を。
@EntityScan("my.package.Entities")
ご注意ください@EntityScan
つまりはエンティティクラスを含むフォルダではないエンティティクラス自身を指す必要があります@EntityScan("my.package.Entities.IndexSetup")
動作しませんでした。