0

in my spring boot / hibernate application, I have a data access class "CusttableDao":

import com.mycompany.myproduct.data.models.Custtable;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Repository
@Transactional
public class CusttableDao {

    static final Logger LOG = LoggerFactory.getLogger(CusttableDao.class);

  public void update(Custtable custtable) {
    entityManager.merge(custtable);
    return;
  }

  public Custtable getById(Class<Custtable> class1, CusttableCompositeKey custtableCompositeKey) {
        Custtable ct = entityManager.find(Custtable.class, custtableCompositeKey);
        LOG.debug("customer.ct.accountNum:  " + ct.getAccountnum());
        return entityManager.find(Custtable.class, custtableCompositeKey);
    }
  @PersistenceContext
  private EntityManager entityManager;
}

When it comes to executing the getById method, I get this error:

org.hibernate.MappingException: Unknown entity: com.mycompany.myproduct.data.models.Custtable
    at org.hibernate.internal.SessionFactoryImpl.getEntityPersister(SessionFactoryImpl.java:1096)
    at org.hibernate.internal.SessionImpl.locateEntityPersister(SessionImpl.java:2565)

Here is the actual Custtable definition, which has the proper @Entity annotation:

import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Transient;
import com.mycompany.myproduct.data.models.CusttableCompositeKey;

@SuppressWarnings("serial")
@Entity
public class Custtable implements java.io.Serializable {

What should I change / add to avoid this error?

4
  • I could not add answer here since its duplicated, I have added answer here stackoverflow.com/a/32939165/3344829, could you check if it helps Commented Sep 10, 2016 at 17:08
  • I have made an edit to demonstrate the actual Custtable class, to show that I already have the @Entity annotation on my class Commented Sep 10, 2016 at 18:03
  • Have you read my answer fully? added EntityScan annotation with entities packages? Commented Sep 10, 2016 at 18:17
  • When I added @EntityScan({"com.mycompany.myproduct.data.models.Custtable"}) , I got this: IllegalStateException: Unable to configure LocalContainerEntityManagerFactoryBean from @EntityScan, ensure an appropriate bean is registered. Commented Sep 10, 2016 at 18:40

1 Answer 1

0

Did you annotate your entity with the @javax.persistence.Entity annotation like described here? org.hibernate.MappingException: Unknown entity

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

1 Comment

To solve this, I ended up adding the following line to application.properties: entitymanager.packagesToScan: com.myconpany.myproduct.data

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.