Ошибка создания бина с именем localContainerEntityManagerFactorryBean, определенного в ресурсе пути к классу hibernateconfig.class

Я получаю сообщение об ошибке при создании компонента с именем localContainerEntityManagerFactorryBean, определенным в ресурсе пути к классу hibernateconfig.class. вложенное исключение - javax.persistence.persistenceException: невозможно построить фабрику сеансов гибернации: внешний ключ, ссылающийся на органайзер из событий, имеет неправильный номер столбца, должен быть равен 2.

My pom file is 

    <?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
        <modelVersion>4.0.0</modelVersion>

        <groupId>com.EventToday</groupId>
        <artifactId>EventToday</artifactId>
        <version>1.0-SNAPSHOT</version>
        <packaging>war</packaging>

        <name>EventToday</name>
        <description>projects for events</description>

        <parent>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-parent</artifactId>
            <version>1.4.1.RELEASE</version>
            <relativePath/> <!-- lookup parent from repository -->
        </parent>

        <properties>
            <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
            <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
            <java.version>1.8</java.version>
            <springframework.version>4.0.6.RELEASE</springframework.version>
            <hibernate.version>4.3.6.Final</hibernate.version>
            <mysql.version>5.1.31</mysql.version>
            <joda-time.version>2.3</joda-time.version>
            <testng.version>6.9.4</testng.version>
            <mockito.version>1.10.19</mockito.version>
            <h2.version>1.4.187</h2.version>
            <dbunit.version>2.2</dbunit.version>
        </properties>

        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter</artifactId>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-test</artifactId>
                <scope>test</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
                </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-web</artifactId>
            </dependency>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
                <scope>provided</scope>
            </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-orm</artifactId>
            </dependency>

            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-data-jpa</artifactId>
            </dependency>

             <dependency>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-jasper</artifactId>
                <scope>provided</scope>
            </dependency> 
            <!-- Hibernate -->
            <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.hibernate</groupId>
                    <artifactId>ejb3-persistence</artifactId>
                    </exclusion>
                    <exclusion>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-annotations</artifactId>
            </exclusion>
        </exclusions>               
    </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-core</artifactId>
    </dependency>

            <!-- jsr303 validation -->
            <dependency>
            <groupId>javax.validation</groupId>
            <artifactId>validation-api</artifactId>
            <version>1.0.0.GA</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>4.0.2.GA</version>
        </dependency>

            <!-- MySQL -->
            <dependency>
                <groupId>mysql</groupId>
                <artifactId>mysql-connector-java</artifactId>
            </dependency>
            <dependency>
                <groupId>org.mariadb.jdbc</groupId>
                <artifactId>mariadb-java-client</artifactId>
                </dependency>
            <dependency>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context-support</artifactId>
            </dependency>
            <dependency>
                <groupId>com.google.guava</groupId>
                <artifactId>guava</artifactId>
                <version>18.0</version>
            </dependency>
            <!-- Joda-Time -->      
            <dependency>
                <groupId>joda-time</groupId>
                <artifactId>joda-time</artifactId>
                </dependency>

            <!-- To map JodaTime with database type -->         
            <dependency>
                <groupId>org.jadira.usertype</groupId>
                <artifactId>usertype.core</artifactId>
                <version>3.0.0.CR1</version>
            </dependency>


            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>javax.servlet-api</artifactId>
                </dependency>
            <dependency>
                <groupId>javax.servlet.jsp</groupId>
                <artifactId>javax.servlet.jsp-api</artifactId>
                <version>2.3.1</version>
            </dependency>
            <dependency>
                <groupId>javax.servlet</groupId>
                <artifactId>jstl</artifactId>
            </dependency>
            <dependency>
                <groupId>org.hibernate</groupId>
                <artifactId>hibernate-jpamodelgen</artifactId>
                <scope>compile</scope>
                <optional>true</optional>
             </dependency>
             <dependency>
                  <groupId>javax.transaction</groupId>
                  <artifactId>jta</artifactId>
                  <version>1.1</version>
            </dependency>

        </dependencies>


        <build>
            <plugins>
                <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-war-plugin</artifactId>
                        <version>2.4</version>
                        <configuration>
                            <warSourceDirectory>src/main/webapp</warSourceDirectory>
                            <warName>EventToday</warName>
                            <failOnMissingWebXml>false</failOnMissingWebXml>
                        </configuration>
                    </plugin>
                <plugin>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-maven-plugin</artifactId>
                </plugin>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <useSystemClassLoader>false</useSystemClassLoader>
                        <compilerArgs>
                                 <arg>-Aopenjpa.metamodel=true</arg>
                        </compilerArgs>
                    </configuration>
                </plugin>
            </plugins>
        </build>
    </project>

и гибернация конфигурации

    @Configuration
    @EnableTransactionManagement
    @EnableJpaRepositories("com.EventToday.event.repository")
    @ComponentScan({ "com.EventToday.event" })
    @PropertySource(value = { "classpath:application.properties" })
    public class hibernateconfig {

            @Autowired
            private Environment environment;

            @Bean
            public LocalContainerEntityManagerFactoryBean localContainerEntityManagerFactoryBean() {
                HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
                vendorAdapter.setDatabase(Database.MYSQL);
                //vendorAdapter.setGenerateDdl(generateDDL);
                vendorAdapter.setShowSql(true);

                LocalContainerEntityManagerFactoryBean beanFactory = new LocalContainerEntityManagerFactoryBean();
                beanFactory.setJpaVendorAdapter(vendorAdapter);

                beanFactory.setPackagesToScan("com.EventToday.event.model");

                beanFactory.setDataSource(dataSource());

                //beanFactory.afterPropertiesSet();
                beanFactory.setJpaProperties(hibernateProperties());

                return beanFactory;
             }



            @Bean
            public DataSource dataSource() {
                DriverManagerDataSource dataSource = new DriverManagerDataSource();
                dataSource.setDriverClassName(environment.getRequiredProperty("spring.datasource.driverClassName"));
                dataSource.setUrl(environment.getRequiredProperty("spring.datasource.url"));
                dataSource.setSchema(environment.getRequiredProperty("spring.datasource.schema"));
                dataSource.setUsername(environment.getRequiredProperty("spring.datasource.username"));
                dataSource.setPassword(environment.getRequiredProperty("spring.datasource.password"));
                return dataSource;
            }

            private Properties hibernateProperties() {
                Properties properties = new Properties();
                properties.put("spring.jpa.properties.hibernate.dialect", environment.getRequiredProperty("spring.jpa.properties.hibernate.dialect"));
                properties.put("spring.jpa.show_sql", environment.getRequiredProperty("spring.jpa.show-sql"));
                properties.put("spring.jpa.properties.hibernate.format_sql", environment.getRequiredProperty("spring.jpa.properties.hibernate.format_sql"));
                return properties;        
            }

            @Bean
            public EntityManagerFactory entityManagerFactory(){
                return localContainerEntityManagerFactoryBean().getObject();
            }


            @Bean
            public EntityManager entityManager(){
                return entityManagerFactory().createEntityManager();
            }

            @Bean
            PlatformTransactionManager transactionManager(){
                JpaTransactionManager manager = new JpaTransactionManager();
                manager.setEntityManagerFactory(entityManagerFactory());
                return manager;
            }

            @Bean
            public HibernateExceptionTranslator hibernateExceptionTranslator(){
                return  new HibernateExceptionTranslator();
            }       
    }

организатор

@Entity
@Table(name="organizer")
public class Organizer extends BaseEntity{

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private int roid;

    @Column(name="orgNname", nullable=false)
    private String organizerName;

    @Column(name = "org_contact", nullable = false)
    private String orgTelephone;

    @Column(name = "org_altcontact", nullable = false)
    private String orgContact;

    @Column(name = "org_mail_address", nullable = false)
    private String mailAddress;

    @Column(name = "org_address", nullable = false)
    private String orgAddress;

     @OneToMany(mappedBy = "organizer")
      private Set<events> evts;




    public Set<events> getEvts() {
        return evts;
    }

    public void setEvts(Set<events> evts) {
        this.evts = evts;
    }

    public Organizer() {

    }

    //getters and setters

}

#events
@Entity
@Table(name="event")
public class events extends BaseEntity{

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Integer id;

    @ManyToOne
    @JoinColumn(name = "roid")
    private Organizer organizer;

    public events() {

    }

    @Column(name = "event_name", nullable = false)
    private String eventname;

    @Column(name = "event_date", nullable = false)
    @DateTimeFormat(pattern="dd/MM/yyyy")
    @Type(type="org.jadira.usertype.dateandtime.joda.PersistentLocalDate")
    private LocalDate date;


    @NotNull
    @Digits(integer=8, fraction=2)
    @Column(name = "ticket_price", nullable = false)
    private BigDecimal price;

    @Column(name="event_location", nullable=false)
    private String location;

    @Column(name="happening_city", nullable=false)
    private String Address;

    @Column(name="contact_no", nullable=false)
    private String contact_no;

    @Column(name="alt_contact_no", nullable=false)
    private String alternate_contact;

    @Column(name="mail_address")
    private String mail_address;

    //getters and setters

}

0 ответов

Другие вопросы по тегам