前提・実現したいこと
Modelクラスに@Entityを追加したところ、
クラスパスリソースで定義された 'entityManagerFactory'という名前のBeanの作成エラー:initメソッドの呼び出しに失敗しました
というメッセージが表示されました。
こちらの解決方法をご存じの方はいらっしゃいますでしょうか。
発生している問題・エラーメッセージ
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: com.example.demo.domain.model.Product Caused by: org.hibernate.AnnotationException: No identifier specified for entity: com.example.demo.domain.model.Product
該当のソースコード
Model
1package com.example.demo.domain.model; 2 3import javax.persistence.Column; 4import javax.persistence.Entity; 5import javax.persistence.Id; 6import javax.persistence.Table; 7 8import lombok.Data; 9 10@Entity 11@Data 12@Table(name = "product") 13public class Product { 14 15 @Id 16 @Column(name = "productCode") 17 private String productCode; //商品コード 18 19 @Column(name = "productName") 20 private String productName; //商品名 21 22 private int price; //価格 23} 24
xml
1<?xml version="1.0" encoding="UTF-8"?> 2<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 3 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> 4 <modelVersion>4.0.0</modelVersion> 5 <parent> 6 <groupId>org.springframework.boot</groupId> 7 <artifactId>spring-boot-starter-parent</artifactId> 8 <version>2.2.7.RELEASE</version> 9 <relativePath/> <!-- lookup parent from repository --> 10 </parent> 11 <groupId>com.example</groupId> 12 <artifactId>SpringSample</artifactId> 13 <version>0.0.1-SNAPSHOT</version> 14 <name>SpringSample</name> 15 <description>Demo project for Spring Boot</description> 16 17 <properties> 18 <java.version>1.8</java.version> 19 </properties> 20 21 <dependencies> 22 <dependency> 23 <groupId>org.springframework.boot</groupId> 24 <artifactId>spring-boot-starter-data-jpa</artifactId> 25</dependency> 26 <dependency> 27 <groupId>org.springframework.boot</groupId> 28 <artifactId>spring-boot-starter-data-jdbc</artifactId> 29 </dependency> 30 <dependency> 31 <groupId>org.springframework.boot</groupId> 32 <artifactId>spring-boot-starter-jdbc</artifactId> 33 </dependency> 34 <dependency> 35 <groupId>org.springframework.boot</groupId> 36 <artifactId>spring-boot-starter-jersey</artifactId> 37 </dependency> 38 <dependency> 39 <groupId>org.springframework.boot</groupId> 40 <artifactId>spring-boot-starter-thymeleaf</artifactId> 41 </dependency> 42 <dependency> 43 <groupId>org.springframework.boot</groupId> 44 <artifactId>spring-boot-starter-web</artifactId> 45 </dependency> 46 <dependency> 47 <groupId>org.springframework.boot</groupId> 48 <artifactId>spring-boot-starter-web-services</artifactId> 49 </dependency> 50 <dependency> 51 <groupId>org.springframework.boot</groupId> 52 <artifactId>spring-boot-starter-webflux</artifactId> 53 </dependency> 54 <dependency> 55 <groupId>org.springframework.boot</groupId> 56 <artifactId>spring-boot-starter-websocket</artifactId> 57 </dependency> 58 <dependency> 59 <groupId>org.springframework.boot</groupId> 60 <artifactId>spring-boot-devtools</artifactId> 61 <scope>runtime</scope> 62 <optional>true</optional> 63 </dependency> 64 <dependency> 65 <groupId>com.h2database</groupId> 66 <artifactId>h2</artifactId> 67 <scope>runtime</scope> 68 </dependency> 69 <dependency> 70 <groupId>org.projectlombok</groupId> 71 <artifactId>lombok</artifactId> 72 <optional>true</optional> 73 </dependency> 74 <dependency> 75 <groupId>org.springframework.boot</groupId> 76 <artifactId>spring-boot-starter-test</artifactId> 77 <scope>test</scope> 78 <exclusions> 79 <exclusion> 80 <groupId>org.junit.vintage</groupId> 81 <artifactId>junit-vintage-engine</artifactId> 82 </exclusion> 83 </exclusions> 84 </dependency> 85 <dependency> 86 <groupId>io.projectreactor</groupId> 87 <artifactId>reactor-test</artifactId> 88 <scope>test</scope> 89 </dependency> 90 91 <!-- webjars:JQuery --> 92 <dependency> 93 <groupId>org.webjars</groupId> 94 <artifactId>jquery</artifactId> 95 <version>1.11.1</version> 96 </dependency> 97 <!-- webjars:Bootstrap --> 98 <dependency> 99 <groupId>org.webjars</groupId> 100 <artifactId>bootstrap</artifactId> 101 <version>3.3.7-1</version> 102 </dependency> 103 </dependencies> 104 105 <dependencyManagement> 106 <dependencies> 107 108 </dependencies> 109 </dependencyManagement> 110 111 <build> 112 <plugins> 113 <plugin> 114 <groupId>org.springframework.boot</groupId> 115 <artifactId>spring-boot-maven-plugin</artifactId> 116 </plugin> 117 </plugins> 118 </build> 119 120</project> 121
あなたの回答
tips
プレビュー