内部服务器错误,status = 500 - getHibernateTemplate()。delete(entity)

时间:2017-10-22 18:20:13

标签: java spring hibernate

在我的Springboot应用程序中,当调用deleteoneXTwo()时,我得到了 There was an unexpected error (type=Internal Server Error, status=500). Removing a detached instance .....entities OneXTwo#1

以下是我的代码 -

@Repository
public class OneXTwoDaoImpl extends HibernateDaoSupport implements OneXTwoDao {

    public OneXTwoDaoImpl(SessionFactory sessionFactory) {
        setSessionFactory(sessionFactory);
    }

    @Transactional
    public void deleteoneXTwo() {
        getHibernateTemplate().setCheckWriteOperations(false);
        OneXTwo oneXTwo = (OneXTwo) getHibernateTemplate().get(OneXTwo.class, 1);
        getHibernateTemplate().delete(oneXTwo);
    }
}

-

@SpringBootApplication
@EnableJpaRepositories(basePackages = {"ro"})
@EntityScan(basePackages = {"ro"})
@ComponentScan(basePackages = {"ro"})
public class BoostrapModules {
    public static void main(String[] args) {
        SpringApplication.run(BoostrapModules.class);
    }


            /*
            USE FOR SESSION FACTORY
             */
                @Autowired
                private EntityManagerFactory entityManagerFactory;

                @Bean
                public SessionFactory getSessionFactory() {
                    if (entityManagerFactory.unwrap(SessionFactory.class) == null) {
                        throw new NullPointerException("factory is not a hibernate factory");
                    }
                    return entityManagerFactory.unwrap(SessionFactory.class);
                }
}

0 个答案:

没有答案