Sping Boot 和JPA with a H2 Database,Not a managed type我的实体出错

olhwl3o2  于 2023-08-06  发布在  其他
关注(0)|答案(1)|浏览(106)

我挣扎了3天以来与以下问题。我即将在大学里为我的班级做一个项目,使用Sping Boot ,JPA和h2数据库作为一个活动网站。
现在唯一的问题是,我似乎无法摆脱这个错误,以便能够自动创建我的表...
这里是我的文件概述:
NewEvent.java实体)

package com.projekt.projekt;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "Event", schema="EVENT")
public class NewEvent {

u/Id
u/GeneratedValue(strategy = GenerationType.IDENTITY)
public Long eventID;
u/Column(name = "id")
private String cid;
u/Column(name = "title")
private String ctitle;
u/Column(name = "location")
private String clocation;
u/Column(name = "email")
private String cemail;
u/Column(name = "phone")
private String cphone;
u/Column(name = "date")
private String cdate;
u/Column(name = "time")
private String ctime;
u/Column(name = "description")
private String cdescription;
u/Column(name = "test")
private String test;

private String title;
private String location;
private String email;
private String phone;
private java.sql.Date date;
private java.sql.Time time;
private String description;

public Long getEventID() {
return eventID;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public java.sql.Date getDate() {
return date;
}
public void setDate(java.sql.Date date) {
this.date = date;
}
public java.sql.Time getTime() {
return time;
}
public void setTime(java.sql.Time time) {
this.time = time;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}

}

字符串
NewEventRepository.java repository):

package com.projekt.projekt;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

u/Repository
public interface NewEventRepository extends JpaRepository<NewEvent, Long> {
// Add custom query methods if needed
}

ProjektApplication.java(Application File):

package com.projekt.projekt;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
u/SpringBootApplication
u/EnableJpaRepositories("com.projekt.*")
u/ComponentScan(basePackageClasses=controller.class)
u/EntityScan("com.projekt.*")
u/EnableAutoConfiguration
u/EnableConfigurationProperties
public class ProjektApplication {
public static void main(String[] args) {
SpringApplication.run(ProjektApplication.class, args);
}
}


我的依赖项(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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.1.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.projekt</groupId>
<artifactId>projekt</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>projekt</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<!-- <dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>2.2.3</version>
</dependency> -->
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>javax.persistence-api</artifactId>
<version>2.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>


我的应用程序属性:

spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.defer-datasource-initialization=true
spring.h2.console.enabled=true
spring.datasource.url=jdbc:h2:file:/data/demo
spring.h2.console.path=/h2-console
spring.h2.console.settings.trace=false
spring.h2.console.settings.web-allow-others=true
spring.jpa.hibernate.ddl-auto=update
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.tool.hbm2ddl=DEBUG
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.properties.hibernate.use_sql_comments=true
spring.jpa.properties.hibernate.format_sql=true


下面是我的文件结构:
Filestructure
Sping Boot JPA不是一个托管类型的错误让我无法继续我的项目,你现在基本上可以忽略php,因为它不会被使用,也不会被删除,因为我的小组做了它。
我会很高兴,如果任何人都可以帮助我摆脱这个错误“不受管理的类型”不知何故,我觉得如果尝试了几乎每一个教程和resources我发现。我会很高兴,如果任何人都可以帮助我摆脱这个错误“不受管理的类型”不知何故,我觉得如果尝试了几乎每一个教程和resources我发现。
我试着折射,改变进口,从头开始设置新的,遵循教程,给它新的名字,三重检查包。下面是我现在得到的一个错误消息示例:

Caused by: java.lang.IllegalArgumentException: Not a managed type: class com.projekt.projekt.NewEvent


我不想把我的整个消息,因为我的完整的文件结构是在那里

相关问题