by @kodeazy
Entity cannot be resolved to a type in SpringBoot using gradle
I was tryint to create a crud operations program using SPRINGBOOT getting below error.
Entity cannot be resolved to a type
Table cannot be resolved to a type
while trying to create an entity
or table
annotation
with below exception.
java.lang.NoClassDefFoundError: javax/persistence/EntityManagerFactory
at org.springframework.data.jpa.util.BeanDefinitionUtils.<clinit>(BeanDefinitionUtils.java:57) ~[spring-data-jpa-2.7.5.jar:2.7.5]
below is my build.gradle
file
plugins {
id 'java'
id 'org.springframework.boot' version '2.7.3'
id 'io.spring.dependency-management' version '1.1.0'
}
group = 'com.example'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'
repositories {
mavenCentral()
}
dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.data:spring-data-jpa:2.7.5'
testImplementation 'com.h2database:h2:2.0.204'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
}
tasks.named('test') {
useJUnitPlatform()
}
To resolve the error add the below dependency in build.gradle file
implementation 'org.hibernate:hibernate-core:6.1.3.Final'
As the gradle file does not have hibernate dependency
it is unable to identify entity
or table
annotation
.
Now try running by clicking gradle refresh
button.