@pashaa

Почему возникает ошибка?

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/tx
         http://www.springframework.org/schema/tx/spring-tx.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context.xsd
           http://www.springframework.org/schema/util
            http://www.springframework.org/schema/util/spring-util.xsd">

    <bean id="transactionManager"
          class="org.springframework.orm.hibernate5.HibernateTransactionManager"
          p:sessionFactory-ref="sessionFactory"/>
    <tx:annotation-driven/>
    <context:component-scan base-package="DAO"/>
    <bean id="sessionFactory"
          class="org.springframework.orm.hibernate5.LocalSessionFactoryBean"
          p:dataSource-ref="dataSource"
          p:packagesToScan="entity"
          p:hibernateProperties-ref="hibernateProperties"/>
    <util:properties id="hibernateProperties">
        <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
        <prop key="hibernate.max_fetch_depth">3</prop>
        <prop key="hibernate.jdbc.fetch_size">50</prop>
        <prop key="hibernate.jdbc.batch_size">10</prop>
        <prop key="hibernate.show_sql">true</prop>
        <prop key="org.hibernate.envers.audit_table_suffix">_H</prop>
        <prop key="org.hibernate.envers.revision_field_name">
            AUDIT_REVISION</prop>
        <prop key="org.hibernate.envers.revision_type_field_name">
            ACTION_TYPE</prop>
        <prop key="org.hibernate.envers.audit_strategy">
            org.hibernate.envers.strategy.ValidityAuditStrategy</prop>
        <prop key="org.hibernate.envers.audit_strategy_validity_end_rev_field_name">
            AUDIT_REVISION_END</prop>
        <prop key="org.hibernate.envers.audit_strategy_validity_store_revend_timestamp">True</prop>
        <prop key="org.hibernate.envers.audit_strategy_validity_revend_timestamp_field_name">AUDIT_REVISION_END_TS</prop>
    </util:properties>


    <bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"
          p:driverClassName="com.mysql.jdbc.Driver"
          p:url="jdbc:mysql://localhost:3306/tur"
          p:username="root"
          p:password="root"/>
</beans>

package entity;

import org.hibernate.annotations.Type;
import org.hibernate.envers.Audited;
import org.joda.time.DateTime;
import org.springframework.data.domain.Auditable;
import javax.persistence.*;
import java.io.Serializable;

/**
 * Created by D$DS$C on 19.01.2017.
 */
@NamedQueries({
        @NamedQuery(name = "findAllAudit",query = "from Hotel_Audit"),
        @NamedQuery(name = "findByIdAudit",query = "from Hotel_Audit h where h.id =:id")
})
@Entity
@Audited
@Table(name = "HOTEL_AUDIT")
public class Hotel_Audit implements Serializable,Auditable<String,Long> {

    @Column(name = "NAME_HOTEL")
    String name_hotel;
    @Column(name = "COUNTRY")
    String country;
    @Column(name = "CITY")
    String city;
    @Column(name = "ADRESS")
    String adress;

    @Id
    @Column(name = "ID")
    private Long id;
    @Version
    @Column(name = "VERSION")
    private int version;

    @Column(name = "CREATED_BY")
    private String createdBy;
    @Column(name = "CREATED_DATE")
    @Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
    private DateTime createdDate;
    @Column(name="LAST_MODIFIED_BY")
    private String lastModifiedBy;
    @Column(name="LAST_MODIFIED_DATE")
    @Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
    private  DateTime lastModifiedDate;

    public String getName_hotel() {
        return name_hotel;
    }

    public void setName_hotel(String name_hotel) {
        this.name_hotel = name_hotel;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getAdress() {
        return adress;
    }

    public void setAdress(String adress) {
        this.adress = adress;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Long getId()
    {return id;}

    public int getVersion() {
        return version;
    }

    public void setVersion(int version) {
        this.version = version;
    }


    @Override
    public String getCreatedBy()
    {
        return createdBy;
    }

    @Override
    public void setCreatedBy(String s) {
        createdBy=s;
    }

    @Override
    public org.joda.time.DateTime getCreatedDate() {
        return createdDate;
    }

    @Override
    public void setCreatedDate(org.joda.time.DateTime dateTime) {
        createdDate = dateTime;
    }

    @Override
    public String getLastModifiedBy() {
        return lastModifiedBy;
    }

    @Override
    public void setLastModifiedBy(String s) {
        lastModifiedBy = s;
    }

    @Override
    public org.joda.time.DateTime getLastModifiedDate() {
        return lastModifiedDate;
    }

    @Override
    public void setLastModifiedDate(org.joda.time.DateTime dateTime) {
            lastModifiedDate =dateTime;
    }

    @Override
    @Transient
    public boolean isNew() {
        if (id == null) {return true;}
            else {return false;}
        }

    @Override
    public String toString() {
        return "Hotel_Audit{" +
                "name_hotel='" + name_hotel + '\'' +
                ", country='" + country + '\'' +
                ", city='" + city + '\'' +
                ", adress='" + adress + '\'' +
                ", id=" + id +
                ", version=" + version +
                ", createdBy='" + createdBy + '\'' +
                ", createdDate=" + createdDate +
                ", lastModifiedBy='" + lastModifiedBy + '\'' +
                ", lastModifiedDate=" + lastModifiedDate +
                '}';
    }
}
package DAO;

import entity.Hotel_Audit;
import org.hibernate.SessionFactory;
import org.hibernate.envers.AuditReader;
import org.hibernate.envers.AuditReaderFactory;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.List;

/**
 * Created by D$DS$C on 19.01.2017.
 */

@Repository("HotelAuditDAO")
@Transactional
public class HotelAuditDAO implements DAO_interface.HotelAuditDAO {

    @Resource(name="sessionFactory")
    SessionFactory sessionFactory;

    public SessionFactory getSessionFactory() {
        return sessionFactory;
    }

    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @PersistenceContext
    private EntityManager entityManager;
    @Transactional(readOnly=true)
    @Override
    public List<Hotel_Audit> findAll() {
        return sessionFactory.getCurrentSession().
                createNamedQuery("findALLAudit").list();
    }
    @Transactional(readOnly=true)
    @Override
    public Hotel_Audit findByid(Long id) {
        return (Hotel_Audit) sessionFactory.getCurrentSession().
                createNamedQuery("findByIdAudit").uniqueResult();
    }

    @Override
    public Hotel_Audit save(Hotel_Audit hotel) {
        return (Hotel_Audit) sessionFactory.getCurrentSession().save(hotel);
    }
    @Transactional(readOnly=true)
    @Override
    public Hotel_Audit findAuditByRevision(Long id, int revision) {
        AuditReader auditReader = AuditReaderFactory.get(entityManager);
        return auditReader.find(Hotel_Audit.class, id, revision);
    }
}

package test;
import DAO_interface.HotelDAO;
import org.springframework.context.support.GenericXmlApplicationContext;

/**
 * Created by D$DS$C on 19.01.2017.
 */
public class test {
    public static void main(String[] args)
    {
        GenericXmlApplicationContext ctx = new GenericXmlApplicationContext();
        ctx.load("config/config.xml");
        ctx.refresh();
        HotelDAO contactDao = (HotelDAO) ctx.getBean("HotelAuditDAO");
    }
}

янв 19, 2017 9:12:00 PM org.springframework.context.support.GenericXmlApplicationContext refresh
WARNING: Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emf' defined in class path resource [config/config.xml]: Invocation of init method failed; nested exception is java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider org.jadira.usertype.dateandtime.joda.integrator.UserTypeJodaTimeHibernateIntegrator not found
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emf' defined in class path resource [config/config.xml]: Invocation of init method failed; nested exception is java.util.ServiceConfigurationError: org.hibernate.integrator.spi.Integrator: Provider org.jadira.usertype.dateandtime.joda.integrator.UserTypeJodaTimeHibernateIntegrator not found
  • Вопрос задан
  • 274 просмотра
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы