0

in my D1 model:

import javax.persistence.Column;
import javax.persistence.Id;
public class D1 
{
    @Id
    @Column(name = "id_client")
    private BigDecimal id_contrats;

    @Column(name = "name_client")
    private Timestamp dat_deb_dwh;

}

In D1Repository

import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.Date;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import io.A1.B1.api.P1.data.model.D1;

@Entity(name = "tmp.c1")
@Table(name = "c1", schema="tmp") 
public interface D1Repository 
{
    @Query(value = "SELECT * FROM #{#entityName} )
    T getId(@Param("id_client") BigDecimal id_client);

}

I'm getting this error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.AnnotationException: No identifier specified for entity: io.A1.B1.api.P1.repository.D1Repository
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1778) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:593) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:142) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1260) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1248) [spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
    at io.A1.B1.api.App.main(App.java:13) [classes/:na]

Caused by: org.hibernate.AnnotationException: No identifier specified for entity: io.A1.B1.api.P1.repository.D1Repository
    at org.hibernate.cfg.InheritanceState.determineDefaultAccessType(InheritanceState.java:266) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    at org.hibernate.cfg.InheritanceState.getElementsToProcess(InheritanceState.java:211) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:775) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    at org.hibernate.boot.model.source.internal.annotations.AnnotationMetadataSourceProcessorImpl.processEntityHierarchies(AnnotationMetadataSourceProcessorImpl.java:250) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess$1.processEntityHierarchies(MetadataBuildingProcess.java:231) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:274) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:904) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:935) ~[hibernate-core-5.3.9.Final.jar:5.3.9.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:57) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:365) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:390) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:377) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.afterPropertiesSet(LocalContainerEntityManagerFactoryBean.java:341) ~[spring-orm-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1837) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1774) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
    ... 16 common frames omitted

Please if you can help please don't hesitate.

Thank you

5
  • Take a look at the stacktrace, it says "nested exception is org.hibernate.AnnotationException: No identifier specified for entity: io.A1.B1.api.P1.repository.D1Repository" Commented May 28, 2020 at 9:04
  • 1
    Does this answer your question? Org.Hibernate.AnnotationException: No Identifier Specified For Entity I don't have a id in my table Commented May 28, 2020 at 9:05
  • @f1sh Thank you for your response, i edited my original post to be more specific, please have a look :) Commented May 28, 2020 at 9:16
  • Your D1Repository is not an entity, so it shouldn't be annotated as such, and D1 is, so it should be annotated. Commented May 28, 2020 at 9:45
  • [1] To those voting to close this as a duplicate, the linked duplicate has ten answers none of which were accepted. Given that, how does closing this question as a duplicate actually help the OP here with their problem? [2] More generally, just because a question mentions the same error as an existing question, that does not automatically make it a duplicate. [3] If you vote to close this question as a duplicate please also specify which answer is relevant in the linked duplicate. Commented May 28, 2020 at 21:04

1 Answer 1

1

You need to add @Entity to specify this is an entity and @Table(name = "insert_table_name") to specify it's relation with the database table on top of your class.

@Entity
@Table(name = "c1", schema="tmp") 
public class D1 
{
    @Id
    @Column(name = "id_client")
    private BigDecimal id;

    @Column(name = "name_client")
    private Timestamp dat_deb_dwh;

}

public interface D1Repository extends CrudRepository<D1, BigDecimal>
{

    D1 findById(BigDecimal id_client);

}
Sign up to request clarification or add additional context in comments.

5 Comments

Thank you for your response. Entity and table are added also and the error persists. I have edited my original post , please have a look
You need to add the annotations to your entity (D1), not the repository.
I added this rows before D1 model and still have the error import javax.persistence.Entity; import javax.persistence.Table; @Entity(name = "tmp.c1") @Table(name = "c1", schema="tmp")
yes i did it also @ntholi and i have added import javax.persistence.Entity; import javax.persistence.Table; @Entity(name = "tmp.c1") @Table(name = "c1", schema="tmp") before my D1 model class but still got the same error
I have updated my original answer with some corrections, removed name parameter from entity annotation, extended CrudRepository in your reposityory and changed the query to reflect Spring Data JPA standards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.