NotNavigableException原因

时间:2019-04-02 09:55:53

标签: hibernate-mapping

每当我运行休眠连接Java代码时,就会收到此异常org.hibernate.metamodel.NotNavigableException:com.javaa2z.hibernate.Customer不可导航(托管类型或集合)

我已经编写了hibernate.cfg.xml代码和Customer.hbm.xml。 我正在使用Mysql8.0

org.hibernate.metamodel.NotNavigableException:com.javaa2z.hibernate.Customer不可导航(托管类型或集合)     在org.hibernate.metamodel.spi.AbstractRuntimeModel.getEntityDescriptor(AbstractRuntimeModel.java:129)     在org.hibernate.internal.SessionImpl.getEntityDescriptor(SessionImpl.java:1492)     在org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)     在org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:190)     在org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:36)     在org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:175)     在org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:30)     在org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:71)     在org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:682)     在org.hibernate.internal.SessionImpl.save(SessionImpl.java:674)     在org.hibernate.internal.SessionImpl.save(SessionImpl.java:669)     在com.javaa2z.hibernate.Lab1A.main(Lab1A.java:14)

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,因为尚未在数据源中设置模型包:

@Bean
    public LocalSessionFactoryBean sessionFactory() {
        System.out.println("Creating entity Manager");
        logger.info("DATASOURCE :"+dataSource());
        LocalSessionFactoryBean factoryBean=new LocalSessionFactoryBean();
        factoryBean.setDataSource(dataSource());
        factoryBean.setPackagesToScan(new String[]{"You model package will set here"});
        factoryBean.setHibernateProperties(additionalProperties());
        return factoryBean;
    }