2

I have started to work on a new Spring Boot using Hibernate application started by another person and I have the following problem: during the application startup I obtain the following error:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'placeSearcherController': Unsatisfied dependency expressed through field 'mainSearchServices'; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'mainSearchServicesImpl': Unsatisfied dependency expressed through field 'accomodationDAO'; 
nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'accomodationDAOImpl': Unsatisfied dependency expressed through field 'sessionFactory'; 
nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [com/betrivius/config/DatabaseConfig.class]: Invocation of init method failed; 
nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [id] in table [accomodation]; found [bigint (Types#BIGINT)], but expecting [integer (Types#INTEGER)]

So, the last exacption into this exceptions chain is:

nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: wrong column type encountered in column [id] in table [accomodation]; found [bigint (Types#BIGINT)], but expecting [integer (Types#INTEGER)]

I think that it only means that on the database table I have a BigInt value for the id column of the accomodation table but on the Accomodation class that maps this table I have:

@Entity
@Table(name = "accomodation")
public class Accomodation implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Integer id;

    ..........................................................
    ..........................................................
    ..........................................................
}

Is it the problem? So what is the correct Java type for MySql BigInt data type? Reading online I fount that somoene use Long and someone else use BigInteger. What is the best choice?

Another important doubt is related about how to correctly read the previous excepeptions chain:

It first show an error into the placeSearcherController bean (it is thrown an UnsatisfiedDependencyException).

From what I have understand it means that the error into the placeSearcherController bean depends by the same exception that is thrown into the mainSearchServicesImpl bean (used by placeSearcherController) and so on untile came to the first place where this exception was thrown that is the AccomodationDAOImpl instance (where the query is performed).

Is this interpretation correct?

halfer
  • 19,824
  • 17
  • 99
  • 186
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596

3 Answers3

3

I fount that somoene use Long and someone else use BigInteger. What is the best choice?

Compare them and decide based on your needs. Long is sufficient for most cases, but not all. The answer on this question is helpful: Long vs BigInteger

From what I have understand it means that the error into the placeSearcherController bean depends by the same exception that is thrown into the mainSearchServicesImpl bean (used by placeSearcherController) and so on untile came to the first place where this exception was thrown that is the AccomodationDAOImpl instance (where the query is performed).

Is this interpretation correct?

Yes, though it's not a query per se. Hibernate is validating that it can work with the existing db schema, and finding it cannot.

Community
  • 1
  • 1
Taylor
  • 3,942
  • 2
  • 20
  • 33
1

I had this problem and the cause was having the entity's primary key in a primitive type. By changing it to a wrapper, my problem was solved.

@Id
private Integer userId;
Ahmed Tawila
  • 988
  • 2
  • 13
  • 20
1

I was having the same issue. Please try defining @ColumnDefinition

You can get the complete detail for this error -> HERE

Example:

for table.

CREATE TABLE event (
    id NUMERIC(19,0) IDENTITY NOT NULL, 
    PRIMARY KEY (id)
)

Entity will be.

@Id
@GeneratedValue(
    strategy = GenerationType.IDENTITY
)
@Column(
    columnDefinition = "NUMERIC(19,0)"
)
private Long id;
Vlad Mihalcea
  • 142,745
  • 71
  • 566
  • 911
GauRang Omar
  • 861
  • 9
  • 20