Error Creating Bean with Name 'Entitymanagerfactory' Defined in Class Path Resource:Invocation of Init Method Failed

Error creating bean with name 'entityManagerFactory' defined in class path resource : Invocation of init method failed

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>

Error creating bean with name 'entityManagerFactory' defined in class path resource (Invocation of init method failed)

some day ago i am getting error message like required a bean named 'entityManagerFactory' that could not be found.

After lot of googling solve this problem. I set manual configuration for JPA.

@Bean 
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();

return sessionFactory;
}

but JPA by default search sessionFactory by name 'entityManagerFactory' so change my code as:

@Bean(name="entityManagerFactory")
public LocalSessionFactoryBean sessionFactory() {
LocalSessionFactoryBean sessionFactory = new LocalSessionFactoryBean();

return sessionFactory;
}

my previous answer


UPDATE
import proper calss

import javax.persistence.Id;

you try to join subject class with course without foreign key reference...
change your code according that image

Sample Image

Spring boot Error creating bean with name 'entityManagerFactory' defined in class path resource

Your comment:

**Here I'm trying to do a "spring-boot:run" and want to generate columns for all above 
five variables. But I'm getting this error :**

indicates that you want to have columns with the ids of the products and variants in your shopping table, however what you probably want to do is have a join table.

The error is telling you that your mapping is not understood, your use case should use a many to many relationship, and you will need a separate table to hold the foreign keys. Basically annotate the products and variants attributes with @ManyToMany and specify the join table, this is left as an exercise to you.

Check https://www.baeldung.com/jpa-many-to-many for an example

Error creating bean with name 'entityManagerFactory' defined in class path resource.No identifier specified for entity:

I had the same problem.
In my case,its because of wrong @Id annotation import.
It should be :- import javax.persistence.Id;

ref:-(https://stackoverflow.com/a/15323836/19262829)



Related Topics



Leave a reply



Submit