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

43

180

When I compile my spring project, I got the following error.

Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed

I am using STS Eclipse and MySql Database

My Connection string in Application.Properties is

spring.datasource.url=jdbc:mysql://localhost:3306/stgdb
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.jpa.hibernate.ddl-auto=update

The detailed error is given below

=================================================

2016-10-15 15:34:38.875[0;39m [31mERROR[0;39m [35m3700[0;39m [2m---[0;39m [2m[           main][0;39m [36mo.s.boot.SpringApplication              [0;39m [2m:[0;39m Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1076) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:851) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541) ~[spring-context-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:761) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:371) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1186) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1175) [spring-boot-1.4.1.RELEASE.jar:1.4.1.RELEASE]
    at com.s2g.testrestapplication.TestRestApplication.main(TestRestApplication.java:10) [classes/:na]
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:373) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:362) ~[spring-orm-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1642) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1579) ~[spring-beans-4.3.3.RELEASE.jar:4.3.3.RELEASE]
    ... 16 common frames omitted
Caused by: org.hibernate.exception.GenericJDBCException: Unable to obtain JDBC Connection
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.ExtractionContextImpl.getJdbcConnection(ExtractionContextImpl.java:65) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.ExtractionContextImpl.getJdbcDatabaseMetaData(ExtractionContextImpl.java:75) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.locateTableInNamespace(InformationExtractorJdbcDatabaseMetaDataImpl.java:339) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.getTable(InformationExtractorJdbcDatabaseMetaDataImpl.java:241) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.getTableInformation(DatabaseInformationImpl.java:105) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:162) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:60) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:134) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:101) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:472) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) ~[hibernate-entitymanager-5.0.11.Final.jar:5.0.11.Final]
    ... 22 common frames omitted
Caused by: com.atomikos.jdbc.AtomikosSQLException: Connection pool exhausted - try increasing 'maxPoolSize' and/or 'borrowConnectionTimeout' on the DataSourceBean.
    at com.atomikos.jdbc.AtomikosSQLException.throwAtomikosSQLException(AtomikosSQLException.java:46) ~[transactions-jdbc-3.9.3.jar:na]
    at com.atomikos.jdbc.AbstractDataSourceBean.throwAtomikosSQLException(AbstractDataSourceBean.java:90) ~[transactions-jdbc-3.9.3.jar:na]
    at com.atomikos.jdbc.AbstractDataSourceBean.throwAtomikosSQLException(AbstractDataSourceBean.java:85) ~[transactions-jdbc-3.9.3.jar:na]
    at com.atomikos.jdbc.AbstractDataSourceBean.getConnection(AbstractDataSourceBean.java:347) ~[transactions-jdbc-3.9.3.jar:na]
    at com.atomikos.jdbc.AbstractDataSourceBean.getConnection(AbstractDataSourceBean.java:394) ~[transactions-jdbc-3.9.3.jar:na]
    at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:180) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    at org.hibernate.tool.schema.extract.internal.ExtractionContextImpl.getJdbcConnection(ExtractionContextImpl.java:62) ~[hibernate-core-5.0.11.Final.jar:5.0.11.Final]
    ... 33 common frames omitted
==============================
Pom.xml file
<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.s2g.testrestapplication</groupId>
    <artifactId>testrestapplication</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>TestRestApplication</name>
    <description>Demo project for Spring Boot</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.4.1.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.2.2</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.2.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-security</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <scope>runtime</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.opensaml</groupId>
            <artifactId>opensaml-saml-api</artifactId>
            <version>3.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-lang3</artifactId>
            <version>3.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jersey</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jta-atomikos</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>


</project>
Opalescent answered 15/10, 2016 at 10:40 Comment(1)
Clearly the "error" you got was actually "Caused by: com.atomikos.jdbc.AtomikosSQLException: Connection pool exhausted - try increasing 'maxPoolSize' and/or 'borrowConnectionTimeout' on the DataSourceBean."Aberrant
B
122

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>
Bulky answered 15/10, 2016 at 12:6 Comment(14)
@georges-van I've encountered the same error, and the 2 dependencies which you have mentioned are already present in spring-boot-starter-data-jpa I get the following error. anotepad.com/notes/wpjr5gLeucomaine
@georgesvan i already have the above jars which u mentioned imported from spring boot. What u think can be the reason for this exact same error. I face the exact same problem when I add any hibernate related dependencies. When i use java files from javax.persistence package everything is fine, but when I use any java files from org.hibernate package this exact same error pops up.Compliancy
@Compliancy javax and Hibernate are different . read this #9882111Bulky
Just use the same versions which mentioned in post.Prem
@ShahabA Had the right answer. Using versions 4.14 and 5.23 worked for me.Hurl
@georges, thevikasdube is already using spring-boot-starter-data-jpa dependency that includes Hibernate. Any reason he should be including hibernate dependencies explicitly ??Mosa
FYI hibernate-entitymanager is now deprecated. Use (only) hibernate-core instead.Eskimo
i have the same issue after i add mysql jdbc its solved without adding any hibernate-*Dodi
I could not figure out what the hell is wrong for a few hours until this post lolChetchetah
thanks, I added this and it worked- <dependency> <groupId>javax.xml.bind</groupId> <artifactId>jaxb-api</artifactId> <version>[2.3.0,]</version> </dependency>Benedicto
Adding the first two dependencies solved this issue but now I am getting another error saying: Consider defining a bean named 'entityManagerFactory' in your configuration.Breadnut
May I ask how you understood this from (which parts of) the stack trace?Larrylars
You shouldn't need to add those dependencies, that is brutal. There is a missing property for JPA -> spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialectUtricle
What is the Jakarta version of this?Lucienlucienne
D
91

People using Java 9 include this dependency:

<dependency>
    <groupId>javax.xml.bind</groupId>
    <artifactId>jaxb-api</artifactId>
    <version>2.3.0</version>
</dependency>
Dugas answered 7/4, 2018 at 12:20 Comment(4)
For those interested in why versions post Java 8 require this explicit inclusion, there is an interesting article here; baeldung.com/java-9-jaxbexception , basically its related to Java 9s introduction of the modular system and an attempt to slim down all the libs that aren't essential...Unbuckle
This worked for me even though I am using Java 8, thanks.Mella
What might this be for gradle?Reorder
implementation("javax.xml.bind:jaxb-api")Barto
E
41

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.

Eroticism answered 12/3, 2018 at 9:35 Comment(8)
Wat do yu mean by additional fields?? Could you give more info on this.? i have same issue nowGamone
I meant additional properties that do not exist in the database, such as private / public integers..etcEroticism
Worked.! In my Entity class, there were two constructors (arg, no-arg)., i removed those and it worked. Thanks @JAD. happy coding.Gamone
Yes, this issue can be related to an issue in any of the entity classes.Houseline
Worked! The error was not dependency or entity manager configuration problem. The problem was the one of my entity class. After I created my entity classes with help of persistence manager the problem is been solved. Thanks.Pelasgian
+1 I've been trying to solve this for a while and this was the trick. I had a typo in a column name in my entity classOmnifarious
I fixed it by adding Entity on one of my class that was missing.Biconvex
Worked! Spent 5 hours to resolve the issue. Checked so many posts before your suggestion. Thank you :)Trivium
M
14

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>
Merc answered 11/11, 2019 at 1:25 Comment(4)
Thank you, I use JDK 12 too and this is the only one that works for me.Window
Can anyone explain why adding these dependencies resolved the error for some of us?Calling
This fixed mine. Thank you.Keeney
Thanks. this fixed my issue when i switched from java 8 to java 11Aseptic
B
12

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.

Baneberry answered 20/8, 2017 at 6:8 Comment(2)
It worked for me, I had updated the spring boot version from 1.5 to 2.3 and was getting this error.Mispleading
I deleted my full repository and it works. It resolved this and a lot of other errors with spring bootAlinaaline
H
9

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();
  }
}
Houseline answered 28/1, 2019 at 3:9 Comment(0)
D
6

I solved mine by updating spring dependencies versions from 2.0.4 to 2.1.6

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.0.4.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
</parent>

to

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
</parent>
Dichotomize answered 24/8, 2019 at 11:48 Comment(1)
I tried all above solutions but only this works for me! Save my day!!!Pseudonym
H
5

For those who use Gradle instead of Maven, add this to the dependencies in your build file:

compile('javax.xml.bind:jaxb-api:2.3.0')
Hyacinth answered 9/10, 2018 at 17:4 Comment(0)
S
5

For my case it was due to Intellij IDEA by default set Java 11 as default project SDK, but project was implemented in Java 8. I've changed "Project SDK" in File -> Project Structure -> Project (in Project Settings)

Sayre answered 17/10, 2019 at 7:15 Comment(2)
This was also my problem, when you try to open an old project that uses Java8 with new downloaded IntellijIDEA this is the solution.Muscid
For installing Java8 on macOS - brew cask install adoptopenjdk/openjdk/adoptopenjdk8Muscid
F
5

For those who are not using JPA and instead prefer to exclude the entityManagerFactory and use Spring Data JDBC or Spring JDBC can exclude the bean to avoid the exception

@SpringBootApplication(exclude = {HibernateJpaAutoConfiguration.class})
Foran answered 31/12, 2019 at 8:51 Comment(0)
T
4

You can try to change the MySql Dialect.

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect

Or

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL8Dialect

pom dependency:

    <dependency>
        <groupId>com.mysql</groupId>
        <artifactId>mysql-connector-j</artifactId>
    </dependency>
Teeterboard answered 28/11, 2022 at 21:43 Comment(0)
B
3

This error may be also related to the fact that you have an error in your "spring.datasource.url" when you gave a wrong db name for example

Bosquet answered 5/5, 2019 at 23:18 Comment(0)
O
3

Adding dependencies didn't fix the issue at my end as well.

The issue was happening at my end because database myapplication in spring.datasource.url=jdbc:mysql://localhost:3306/myapplication didn't exist in mysql.

I created the db manually, restarted the application and it worked.

Obeah answered 25/3, 2022 at 21:18 Comment(0)
E
2

I was able to fix the problem by changing the maximum-pool size value from one to two

spring.datasource.hikari.maximum-pool-size=2

Epitomize answered 15/2, 2018 at 12:52 Comment(0)
S
2

When we map a column, we have to pay attention to the name of the opposite column that is being mapped, for example:

/*users*/
@OneToMany(mappedBy = "partModel")
private List<UsersModel> usersModels;


/*parts*/
@ManyToOne
private PartModel partModel;

Check out postModel here.***

Shult answered 15/10, 2021 at 20:0 Comment(0)
E
1

Try to annotate the class with @EnableTransactionManagement. I was facing the same issue and it got resolved by adding this.

@EnableTransactionManagement
public class ConfigurationBean {
}
Elizaelizabet answered 22/4, 2018 at 11:59 Comment(0)
A
1

If you use JDK 1.8.0_201 or latest try it with older JDK.

I have same issue with JDK1.8.0_201, however it works with JDK1.8.0_101 without any code change.

Axinomancy answered 13/3, 2019 at 21:50 Comment(0)
P
1

I resolved this issue by Adding implements Serializable in the Model.

@Entity
@Table(name="Model_Rest")
@IdClass(Model_Rest.class)
public class Model_Rest implements Serializable {

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    /**
     * 
     */
    //@GeneratedValue(strategy = GenerationType.AUTO)
    //@Column(columnDefinition="id")

    @Id
    private String login;
    @Id
    private String password;




    @Autowired
    public String getLogin() {
        return login;
    }

    @Autowired
    public void setLogin(String login) {
        this.login = login;
    }

    @Autowired
    public String getPassword() {
        return password;
    }

    @Autowired
    public void setPassword(String password) {
        this.password = password;
    }

    public Model_Rest() {
        // TODO Auto-generated constructor stub
    }

    public Model_Rest(String login, String password) {
        this.login = login;
        this.password = password;
    }

    @Override
    public String toString() {
        return "Model_Rest [login=" + login + ", password=" + password + "]";
    }
  }
Pessary answered 11/4, 2019 at 10:59 Comment(0)
S
1

For me, it was a result of another error

org.postgresql.util.PSQLException: FATAL: password authentication failed for user

Which means you just need to review your authentication credentials

Shawnna answered 10/7, 2019 at 9:48 Comment(0)
S
1

I had the same issue on my Eclipse Luna. I figure out that I am using JDK12 and Java 1.8. I changed JDK to JDK8 and the problem was solved. If you want to check your JDK in Eclipse go to

Window-> Preferences-> Java- >Installed JREs 

and check if they are compatible with your project. Good luck!

Selfregulated answered 9/2, 2020 at 21:8 Comment(1)
the same, i found i was using JDK 12 and just switched back to JDK 8 and worked finePartner
A
1

For me it was the name of the database on application.properties. When I provided the correct name it worked ok.

Apomict answered 25/2, 2020 at 14:42 Comment(0)
T
1

Whoever still having the same issue. Please add the following line in application.properties

# The SQL dialect makes Hibernate generate better SQL for the chosen database
## I am using Mysql8 so I have declared MySQL8Dialect if you have other versions just add ## that version number
spring.jpa.properties.hibernate.dialect =  org.hibernate.dialect.MySQL8Dialect

Threap answered 10/4, 2020 at 17:49 Comment(0)
V
1

In my case the issue was multiparted and related to AWS:

  1. as @Tareq Islam pointed out setting the dialect in application.properties helped. I used for MySQL 5.6:

    spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL55Dialect

  2. the second issue after this was that the JDBC was not able to connect to the server due to change in SSL connection encryption. I fixed it with help of

SSLHandShakeException No Appropriate Protocol

But I needed to enable TLS1.0 by setting to /etc/java-11-openjdk/security/java.security

jdk.tls.disabledAlgorithms=SSLv3, RC4, DES, MD5withRSA, DH keySize < 1024, EC keySize < 224, 3DES_EDE_CBC, anon, NULL
Vereen answered 2/5, 2021 at 8:18 Comment(0)
F
1

In my case, I have set ddl-auto as validate, in application.properties file

spring.jpa.hibernate.ddl-auto=validate

Here, the issue occurs when property hibernate.hbm2ddl.auto is set to validate. Everything works fine when it is set to none. I think validator doesn't take into account that when primary key is defined as GENERATED BY DEFAULT AS IDENTITY.

Far answered 7/5, 2021 at 15:44 Comment(0)
R
1

In my case i add the following line in application.properties ,the issue was in Oracle 11g DB Driver

spring.jpa.database-platform=org.hibernate.dialect.OracleDialect
Roentgenograph answered 11/8, 2021 at 12:24 Comment(0)
T
0

use @Id .Worked for me.Otherwise it i will throw error.It depends on is there anything missing in your entity class or repository

Transmigrate answered 21/2, 2019 at 7:31 Comment(0)
R
0

My error was solved after adding this dependency.

<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-validator -->
    <dependency>
        <groupId>org.hibernate.validator</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>6.0.16.Final</version>
    </dependency>
Ramirez answered 23/7, 2019 at 8:29 Comment(0)
M
0

Try changing spring version. I had the same issue and that worked for me

Miscarry answered 28/11, 2019 at 16:41 Comment(0)
G
0

I resolved mine by defining reverse-relationship annotation for an additional field

Giovannagiovanni answered 30/3, 2020 at 18:56 Comment(0)
F
0

In my case I got this error when trying to make Proguard + Spring Boot 2 work.

Adding -dontusemixedcaseclassnames to proguard.conf fixes it.

Funereal answered 13/11, 2020 at 22:30 Comment(0)
C
0

In our case, we had some extra lines in the .properties file which was not needed with the new image.

spring.jpa.properties.hibernate.cache.use_second_level_cache=true

Obviously with didn't had that Entity what it tried to load.

Convection answered 15/2, 2021 at 10:34 Comment(0)
S
0

If nothing work then I have one solution @Access(value=AccessType.FIELD) add this line in under model class after you used @Entity then followed by the class and after class when you defining id and all that time you use above line.

Singularity answered 21/2, 2021 at 17:4 Comment(0)
K
0
Make sure you have successfully build dependent maven/gradle based project with the correct mention version. Similarly you can add the dependent project in config like below.

        @Bean
        @Primary
        public LocalContainerEntityManagerFactoryBean entityManager() {
            EntityManagerFactoryBuilder builder = new 
            EntityManagerFactoryBuilder(adapter, jpaProperties.getProperties(),
                persistenceUnitManager);
            return builder
                .dataSource(dataSources()).packages("com.ABCApi.entity",
                    "com.PQRApi.entity", "com.XYZApi.entity")
                .persistenceUnit("entityManager").build();
        }
Keratitis answered 12/8, 2021 at 13:17 Comment(0)
R
0

I had the same problem, already after I finished the project, and did not understand what happened, because no change was made to the code. I realized that there were probably two processes running, I stopped the process I did not need and the second process I ran, and it solved my problem of not syncing to DB.

The 2 processes I had: enter image description here

Retraction answered 14/2, 2022 at 13:10 Comment(0)
A
0

In my case, I have mistakenly configured relations in my model class

Please check your relations (oneToOne, oneToMany ...) in your model. It might be the issue.

Austria answered 31/3, 2022 at 9:28 Comment(0)
N
0

I was Facing the similiar error,but when i selected appropriate dialect for my DB in application.properties Issue resolved.

Niklaus answered 23/6, 2022 at 3:57 Comment(0)
J
0

I faced the same issue and found out that, it was a problem with the database schema not being correctly created.

I managed to solve this by creating a schema.

Steps:

  • Delete the database
  • Run the SQL script to create a schema
Jesher answered 18/10, 2022 at 6:41 Comment(0)
A
0

Check the database relationships, you might miss one of the following:

@OneToMany
@ManyToOne

etc ...
Atomism answered 27/10, 2022 at 20:9 Comment(0)
S
0

For me, there were two versions of HikariCP in my classpath, removed the older version and now the app is working fine.

Smashing answered 11/1 at 7:3 Comment(0)
S
-1

I have gone through similar error. The error was not coming earlier, but recently I reinstall my oracle db and change the instance name from 'xe' to 'orcl', but forget to change this piece of code in property file:

spring.datasource.driver-class-name=oracle.jdbc.driver.OracleDriver
spring.datasource.url=jdbc:oracle:thin:@localhost:1521:***xe***
spring.datasource.username=system
spring.datasource.password=manager

Once I change it from 'xe' to 'orcl' everything is fine.

Seizing answered 25/6, 2018 at 13:52 Comment(0)
S
-1

The problem might be because of package conflicts. When you use @Id annotation in an entity, it might use the @Id of Spring framework; however, it must use @Id annotation of persistence API.

So use @javax.persistence.Id annotation in entities.

Subsonic answered 18/8, 2018 at 10:36 Comment(2)
If you access class, it refers to the specific class with the package reference via import. If you do, it is a compile time error and is caught during any process at the first place. So, there is no chance to have conflict with @Id with JPA and Spring.Freytag
I'm not sure what question this attempts to answer, but it is not this question. Having annotated (or not) with @Id will not result in an error stacktrace saying "Connection pool exhausted - try increasing 'maxPoolSize' and/or 'borrowConnectionTimeout' on the DataSourceBean."Appalachia
A
-1

I had a similar error message and resolved it by updating hibernate core from 4.1.4.Final to 6.1.7.Final. I also updated hibernate entity manager from 5.2.3.Final to 5.6.15.Final. These updates where suggested by Intellij through the yellow wiggly lines in the pom.xml file. I restarted Intellij and ran the app. The error messages were gone after thatenter image description here

Attu answered 31/12, 2023 at 20:33 Comment(1)
Even if Intellij is suggesting this. Mixing different major versions of hibernate is really not a good idea. The hibernate-entitiymanager package moved into the core. You can see this if you search for the package on mvnrepository.com/search?q=hibernate-entitymanagerSlating
C
-2

Try adding the following dependencies.

<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
   <groupId>com.h2database</groupId>
   <artifactId>h2</artifactId>
</dependency> 
Cheeseburger answered 8/8, 2017 at 6:9 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.