Hibernate搜索:NoSuchMethod org.hibernate.engine.transaction.spi.TransactionEnvironment.getJtaPlatform()?

Pra*_*ede 0 spring hibernate jpa hibernate-search

我有一个使用spring和hibernate的java项目.我正在集成hibernate搜索以进行全文搜索.由于我已经集成了hibernate搜索,因此无法保存我的实体.我收到以下错误:

org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.engine.transaction.spi.TransactionEnvironment.getJtaPlatform()Lorg/hibernate/engine/transaction/jta/platform/spi/JtaPlatform;
Run Code Online (Sandbox Code Playgroud)

完整的堆栈跟踪在这里http://pastebin.com/GTthsRv6

这里是我的弹簧控制器,当我想为用户保存项目时:

   @RequestMapping(value="/saveproject", method = RequestMethod.POST)
    public ModelAndView saveProject(@ModelAttribute Project  project,HttpSession session){
         User user = (User) session.getAttribute(USER);
         user.getProjects().add(project);
         ModelAndView modelAndView = new ModelAndView();
         modelAndView.setViewName("projectSuccess");
         modelAndView.addObject("project", project);
         userServices.updateUser(user);
         return modelAndView;
    } 
Run Code Online (Sandbox Code Playgroud)

这里是services部分中的updateUser方法实现:

@Transactional(propagation= Propagation.REQUIRED, readOnly=false)
@Service
public class UserServicesImpl implements UserServices {

@Autowired
    private UserDao userDao;

    public void updateUser(User user) {
            userDao.updateUser(user);

        }
..other methods
}
Run Code Online (Sandbox Code Playgroud)

这是@Repository的更新用户方法:

@Repository
public class UserDaoImpl extends AbstractDaoImpl<User, Long> implements UserDao {

    protected UserDaoImpl() {
        super(User.class);
    }
    @Override
        public void updateUser(User user) {
            saveOrUpdate(user);

        }
...other methods
}
Run Code Online (Sandbox Code Playgroud)

AbstractDaoImpl:

    public abstract class AbstractDaoImpl<E, I extends Serializable> implements AbstractDao<E,I> {

        private Class<E> entityClass;

        protected AbstractDaoImpl(Class<E> entityClass) {
            this.entityClass = entityClass;
        }

        @Autowired
        private SessionFactory sessionFactory;

        public Session getCurrentSession() {
            return sessionFactory.getCurrentSession();
        }


        @Override
        public void saveOrUpdate(E e) {
            getCurrentSession().saveOrUpdate(e);
        }

    ... others methods


        public void indexDatabase(){
            Session session  = getCurrentSession();
            FullTextSession fullTextSession = Search.getFullTextSession(session);  
            try {
                fullTextSession.createIndexer().startAndWait();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 
        }

}
Run Code Online (Sandbox Code Playgroud)

在我的hibernate.cfg.xml中配置索引:

filesystem E:\ workspace\indexes

我使用hibernate 4.2和hibernate search 4.5.我不明白问题出在哪里.

Mik*_*unu 6

Hibernate ORM的错误版本与Hibernate Search 4.5一起使用.方法getJtaPlatform存在,但返回类型不同.

在Hibernate 4.2方法中,TransactionEnvironment.getJtaPlatform()返回
org.hibernate.service.jta.platform.spi.JtaPlatform

在Hibernate 4.3中它返回:
org.hibernate.engine.transaction.jta.platform.spi.JtaPlatform

Hibernate Search 4.5需要Hibernate 4.3.例如,这里记录了这一点:

您将需要hibernate-core-4.3.1.Final.jar及其传递依赖项