@ManytoMany注释问题org.hibernate.MappingException:无法找到物理表`producto`

时间:2016-02-24 23:01:18

标签: hibernate spring-boot spring-data-jpa

我正在使用Spring Boot 1.3.1及其默认的hibernate版本4.3.11.Final。我试图映射@ManytoMany关联,但我得到以下异常:

  

org.springframework.beans.factory.BeanCreationException:错误   创建名为&entityManagerFactory'的bean在类路径中定义   资源   [组织/ springframework的/引导/自动配置/ ORM / JPA / HibernateJpaAutoConfiguration.class]:   调用init方法失败;嵌套异常是   javax.persistence.PersistenceException:[PersistenceUnit:default]   无法构建Hibernate SessionFactory   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)   〜[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)   〜[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)   〜[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)   〜[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at   org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)   〜[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)   〜[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at   org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)   〜[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at   org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054)   〜[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at   org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:829)   〜[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at   org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)   〜[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE] at   org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:118)   〜[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE] at   org.springframework.boot.SpringApplication.refresh(SpringApplication.java:766)   〜[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE] at   org.springframework.boot.SpringApplication.createAndRefreshContext(SpringApplication.java:361)   〜[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE] at   org.springframework.boot.SpringApplication.run(SpringApplication.java:307)   〜[spring-boot-1.3.2.RELEASE.jar:1.3.2.RELEASE] at   ec.com.asertec.ave360.Ave360beApplication.main(Ave360beApplication.java:60)   [bin /:na]引起:javax.persistence.PersistenceException:   [PersistenceUnit:default]无法构建Hibernate SessionFactory     在   org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:1249)   〜[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final] at   org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.access $ 600(EntityManagerFactoryBuilderImpl.java:120)   〜[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final] at   org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.perform(EntityManagerFactoryBuilderImpl.java:860)   〜[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final] at   org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.perform(EntityManagerFactoryBuilderImpl.java:850)   〜[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final] at   org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:425)   〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final] at   org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:849)   〜[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final] at   org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)   〜[spring-orm-4.2.4.RELEASE.jar:4.2.4.RELEASE] at   org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)   〜[spring-orm-4.2.4.RELEASE.jar:4.2.4.RELEASE] at   org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)   〜[spring-orm-4.2.4.RELEASE.jar:4.2.4.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)   〜[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] at   org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)   〜[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE] ... 14个常见帧   省略:org.hibernate.MappingException:无法找到   物理表:producto at   org.hibernate.cfg.Configuration $ MappingsImpl.getLogicalTableName(Configuration.java:3156)   〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final] at   org.hibernate.cfg.Configuration $ MappingsImpl.getLogicalTableName(Configuration.java:3149)   〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final] at   org.hibernate.cfg.annotations.CollectionBinder.bindManyToManySecondPass(CollectionBinder.java:1208)   〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final] at   org.hibernate.cfg.annotations.CollectionBinder.bindStarToManySecondPass(CollectionBinder.java:794)   〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final] at   org.hibernate.cfg.annotations.CollectionBinder $ 1.secondPass(CollectionBinder.java:729)   〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final] at   org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:70)   〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final] at   org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1697)   〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final] at   org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1426)   〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final] at   org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1846)   〜[hibernate-core-4.3.11.Final.jar:4.3.11.Final] at   org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl $ 4.perform(EntityManagerFactoryBuilderImpl.java:857)   〜[hibernate-entitymanager-4.3.11.Final.jar:4.3.11.Final] ... 22   常见帧省略

我的实体是:

PRODUCTO实体:

  @Entity
@Table(name="producto",schema="ave360")
@NamedQuery(name="Producto.findAll", query="SELECT p FROM Producto p")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Producto  extends EntidadBase implements Serializable {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Id
    @SequenceGenerator(name = "ID_producto", schema = "ave360", sequenceName = "producto_id_seq", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID_producto")
    @Column(unique = true, nullable = false)
    private Long id;

    @Column(unique = true, name = "nombre", length = 250, nullable = false)
    private String nombre;

    @OneToOne
    @JoinColumn(name = "id_nivel_organizacional")
    private NivelOrganizacional nivelOrganizacional;


     @ManyToMany(
                targetEntity=Ramo.class
            )
     @JoinTable(
             name="producto_ramo",
             joinColumns=@JoinColumn(name="id_producto",referencedColumnName="id"),
             inverseJoinColumns=@JoinColumn(name="id_ramo",referencedColumnName="id")
     )
    private Set<Ramo> ramos;

RAMO实体:

/**
 * The persistent class for the ramo database table.
 * 
 */
@Entity
@Table(name="ramo",schema="ave360")
@NamedQuery(name="Ramo.findAll", query="SELECT r FROM Ramo r")
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
public class Ramo extends EntidadBase implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @SequenceGenerator(name = "ID_ramo", schema="ave360", sequenceName = "ramo_id_seq", allocationSize = 1)
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator="ID_ramo")
    @Column(unique=true, nullable=false)
    private Long id;

    @Column(name="codigo_super", nullable=false,unique=true)
    private Integer codigoSuper;

    @Column(nullable=false, length=150,unique=true)
    private String nombre;

    @Column(length=450)
    private String descripcion;

    @Column(length=15,unique=true,nullable=false)
    private String siglas;

    @ManyToMany(
            mappedBy = "ramos",
            targetEntity = Producto.class
        )
    private Set<Producto> productos;

当我删除@ManyToMany映射时,它工作正常。我在其他实体中有ManytoOne映射和OneToOne映射,一切正常。

我试图寻找解决方案,但我无法找到它。

你能看一下代码和日志,并帮我看看它有什么问题吗?也许我在搞什么。

非常感谢你们所有人。

0 个答案:

没有答案