Error creating bean with name 'entityManagerFactory' defined in class path resource. Resolved this error by adding a Bean to the main application class.
The complete example of getting EntityManager using the custom configuration in Spring Boot. Open eclipse and create maven project, Don't forget to check 'Create a simple project (skip)'click on next. Fill all details(GroupId – entitymanager, ArtifactId – entitymanager and name – entitymanager) and click on finish.
Several entity manager factories can be prepared for connecting to different data stores. JPA EntityManager is used to access a database in a particular application. It is used to manage persistent entity instances, to find entities by their primary key identity, and to query over all entities.
I would start by adding the following dependency:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.4.Final</version>
</dependency>
and
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.3.Final</version>
</dependency>
UPDATE: Or simply add the following dependency.
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
People using Java 9 include this dependency:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
Adding dependencies didn't fix the issue at my end.
The issue was happening at my end because of "additional" fields that are part of the "@Entity" class and don't exist in the database.
I removed the additional fields from the @Entity class and it worked.
Goodluck.
I suspect that the jar files of hibernate-core
and hibernate-entitymanager
dependencies are corrupted or were not installed properly on your machine.
I suggest that you just delete the folders named hibernate-core
and hibernate-entitymanager
from your Maven local repository and Maven will reinstall them.
The default location for Maven local repository is C:\Documents and Settings\[USERNAME]\.m2
in windows or ~/.m2
in Linux/Mac.
I've jdk-12.0.2.jdk, 've found solution to the problem, add dependencies to pom.xml:
<!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.javassist/javassist -->
<dependency>
<groupId>org.javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.25.0-GA</version>
</dependency>
In my case, deleting any of the below annotations cause the error message 'entityManagerFactory' to show, for example.
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
or
@ManyToMany(targetEntity=listOfObject_x.class)
The error message disappears after adding the missing annotation(s).
package mypackage_unameit;
import javax.persistence.PrePersist;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import lombok.Data;
@Data
@Entity
public class Someclasss {
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
@NotNull
@Size(min=5, message="Name must be at least 5 characters long")
private String name;
private Date createdAt;
@ManyToMany(targetEntity=listOfObject_x.class)
@Size(min=1, message="You must choose at least 1 ingredient")
private List<listOfObject_x> = new ArrayList<>();
@PrePersist
void createdAt() {
this.createdAt = new Date();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With