在命名空间(,)中找到多个表 - 使用Spring,Hibernate和JPA

时间:2016-11-16 13:38:13

标签: spring oracle hibernate jpa exceptionhandler

我正在使用Spring 4&amp; Hibernate 5与JPA和Oracle数据库,我检查了我的所有代码,只有一个实体和一个名为LANGUE的表,我的项目仍然拒绝编译,因为这个错误,有人可以帮助我... ...,< / p>

的applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:faces="http://www.springframework.org/schema/faces"
xmlns:int-security="http://www.springframework.org/schema/integration/security"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:sec="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/integration/security http://www.springframework.org/schema/integration/security/spring-integration-security-2.0.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd
    http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces-2.0.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

<context:component-scan base-package="com.collecteJ.crud" />
<context:component-scan base-package="com.collecteJ.crud.entities" />
<context:component-scan base-package="com.collecteJ.crud.test.entities" />    
<context:component-scan base-package="com.collecteJ.crud.dao"/>
<context:component-scan base-package="com.collecteJ.crud.test.dao" />
<context:component-scan base-package="com.collecteJ.crud.service"/>    
<context:component-scan base-package="com.collecteJ.crud.test.service"/>
<context:component-scan base-package="com.collecteJ.crud.test"/>
<context:component-scan base-package="com.collecteJ.business.compte"/>
<context:component-scan base-package="com.collecteJ.business.compte.impl" /> 
<context:component-scan base-package="com.collecteJ.business.service"/>
<context:component-scan base-package="com.collecteJ.business.service.impl" /> 
<context:component-scan base-package="com.collecteJ.business.test" />


<aop:config proxy-target-class="true"/>

<bean 
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location"> 
            <value> database.properties</value>
        </property> 
    </bean>


<bean id="pooledDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" >  
        <property name="driverClass" value="${jdbc.driverClassName}" />
        <property name="jdbcUrl" value="${jdbc.url}"/>  
        <property name="user" value="${jdbc.username}"/>  
        <property name="password" value="${jdbc.password}"/>
        <property name="acquireIncrement" value="1"/>   
        <property name="maxPoolSize" value="10" />
        <property name="maxStatements" value="0" />
        <property name="minPoolSize" value="5" />  
</bean>

<bean id="JDBCDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource" >
    <property name="driverClassName" value="${jdbc.driverClassName}"/>
    <property name="url" value="${jdbc.url}"/>
    <property name="username" value="${jdbc.username}"/>
    <property name="password" value="${jdbc.password}"/> 
</bean>

<bean id="entityManagerFactory"
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" > 
            <property name="generateDdl" value="true" />                                                           
            <property  name="showSql" value="true"/> 
        </bean>
    </property>
    <property name="loadTimeWeaver">
        <bean class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
    </property>                
    <property name="dataSource" ref="pooledDataSource" />
    <property name="persistenceUnitName" value="collecteJCrudSpringPU"/> 
</bean>

<bean name="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />     
</bean>

<tx:annotation-driven />

<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

    <bean class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor" />

</beans>

persitence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="collecteJCrudSpringPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>com.collecteJ.crud.entities.Account</class>
<class>com.collecteJ.crud.entities.Agence</class>
<class>com.collecteJ.crud.entities.Collecte</class>
<class>com.collecteJ.crud.entities.Collecteur</class>
<class>com.collecteJ.crud.entities.CollecteurCompte</class>
<class>com.collecteJ.crud.entities.Compte</class>
<class>com.collecteJ.crud.entities.Comptecollecte</class>
<class>com.collecteJ.crud.entities.Devise</class>
<class>com.collecteJ.crud.entities.EtatCivil</class>
<class>com.collecteJ.crud.entities.Role</class>
<class>com.collecteJ.crud.entities.TypeTransaction</class>
<class>com.collecteJ.crud.entities.Utilisateur</class>
<class>com.collecteJ.crud.test.entities.Testtable</class> 
</persistence-unit>
</persistence>

堆栈跟踪

run:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further     details.
log4j:WARN No appenders could be found for logger (org.jboss.logging).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in URL [file:/C:/Users/hpcc/Documents/GoldTelecom/NetBeansProjects/collecteJCrud/build/classes/com/collecteJ/crud/config/applicationContext.xml]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: collecteJCrudSpringPU] Unable to build Hibernate SessionFactory
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1054)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:829)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:538)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
at com.collecteJ.crud.main.MainTest2.main(MainTest2.java:32)
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: collecteJCrudSpringPU] Unable to build Hibernate SessionFactory
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.persistenceException(EntityManagerFactoryBuilderImpl.java:954)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:882)
at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 12 more
Caused by: org.hibernate.tool.schema.extract.spi.SchemaExtractionException:  More than one table found in namespace (, ) : LANGUE
at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.processGetTableResults(InformationExtractorJdbcDatabaseMetaDataImpl.java:381)
at org.hibernate.tool.schema.extract.internal.InformationExtractorJdbcDatabaseMetaDataImpl.getTable(InformationExtractorJdbcDatabaseMetaDataImpl.java:279)
at org.hibernate.tool.schema.extract.internal.DatabaseInformationImpl.getTableInformation(DatabaseInformationImpl.java:105)
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigrationToTargets(SchemaMigratorImpl.java:162)
at org.hibernate.tool.schema.internal.SchemaMigratorImpl.doMigration(SchemaMigratorImpl.java:60)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:133)
at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:101)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:470)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
... 17 more
Java Result: 1
BUILD SUCCESSFUL (total time: 14 seconds)

Language.java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.collecteJ.crud.entities;

import java.io.Serializable;
import java.math.BigInteger;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author Cyrille benito
 */
@Entity
@Table(name = "LANGUE")
@NamedQueries({
@NamedQuery(name = "Langue.findAll", query = "SELECT l FROM Langue l"),
@NamedQuery(name = "Langue.findByCodeLangue", query = "SELECT l FROM Langue l WHERE l.codeLangue = :codeLangue"),
@NamedQuery(name = "Langue.findByReference", query = "SELECT l FROM Langue l WHERE l.reference = :reference"),
@NamedQuery(name = "Langue.findByLibelle", query = "SELECT l FROM Langue l WHERE l.libelle = :libelle"),
@NamedQuery(name = "Langue.findByFormatDateCourte", query = "SELECT l FROM Langue l WHERE l.formatDateCourte = :formatDateCourte"),
@NamedQuery(name = "Langue.findByFormatDateLongue", query = "SELECT l FROM Langue l WHERE l.formatDateLongue = :formatDateLongue"),
@NamedQuery(name = "Langue.findByFormatHeure", query = "SELECT l FROM Langue l WHERE l.formatHeure = :formatHeure"),
@NamedQuery(name = "Langue.findByFormatNumerique", query = "SELECT l FROM Langue l WHERE l.formatNumerique = :formatNumerique"),
@NamedQuery(name = "Langue.findByTaillePartieDecimale", query = "SELECT l FROM Langue l WHERE l.taillePartieDecimale = :taillePartieDecimale"),
@NamedQuery(name = "Langue.findBySeparateurMillier", query = "SELECT l FROM Langue l WHERE l.separateurMillier = :separateurMillier"),
@NamedQuery(name = "Langue.findBySeparateurPartieDecimale", query = "SELECT l FROM Langue l WHERE l.separateurPartieDecimale = :separateurPartieDecimale"),
@NamedQuery(name = "Langue.findByUtilisateuridModif", query = "SELECT l FROM Langue l WHERE l.utilisateuridModif = :utilisateuridModif"),
@NamedQuery(name = "Langue.findByUtilisateuridCrea", query = "SELECT l FROM Langue l WHERE l.utilisateuridCrea = :utilisateuridCrea"),
@NamedQuery(name = "Langue.findByDateCreation", query = "SELECT l FROM Langue l WHERE l.dateCreation = :dateCreation"),
@NamedQuery(name = "Langue.findByDateModification", query = "SELECT l FROM Langue l WHERE l.dateModification = :dateModification")})
public class Langue implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "CODE_LANGUE")
    private String codeLangue;
    @Basic(optional = false)
    @Column(name = "REFERENCE")
    private String reference;
    @Basic(optional = false)
    @Column(name = "LIBELLE")
    private String libelle;
    @Column(name = "FORMAT_DATE_COURTE")
    private String formatDateCourte;
    @Column(name = "FORMAT_DATE_LONGUE")
    private String formatDateLongue;
    @Column(name = "FORMAT_HEURE")
    private String formatHeure;
    @Column(name = "FORMAT_NUMERIQUE")
    private String formatNumerique;
    @Column(name = "TAILLE_PARTIE_DECIMALE")
    private BigInteger taillePartieDecimale;
    @Column(name = "SEPARATEUR_MILLIER")
    private String separateurMillier;
    @Column(name = "SEPARATEUR_PARTIE_DECIMALE")
    private String separateurPartieDecimale;
    @Column(name = "UTILISATEURID_MODIF")
    private BigInteger utilisateuridModif;
    @Column(name = "UTILISATEURID_CREA")
    private BigInteger utilisateuridCrea;
    @Column(name = "DATE_CREATION")
    @Temporal(TemporalType.DATE)
    private Date dateCreation;
    @Column(name = "DATE_MODIFICATION")
    @Temporal(TemporalType.DATE)
    private Date dateModification;

    public Langue() {
}

public Langue(String codeLangue) {
    this.codeLangue = codeLangue;
}

public Langue(String codeLangue, String reference, String libelle) {
    this.codeLangue = codeLangue;
    this.reference = reference;
    this.libelle = libelle;
}

public String getCodeLangue() {
    return codeLangue;
}

public void setCodeLangue(String codeLangue) {
    this.codeLangue = codeLangue;
}

public String getReference() {
    return reference;
}

public void setReference(String reference) {
    this.reference = reference;
}

public String getLibelle() {
    return libelle;
}

public void setLibelle(String libelle) {
    this.libelle = libelle;
}

public String getFormatDateCourte() {
    return formatDateCourte;
}

public void setFormatDateCourte(String formatDateCourte) {
    this.formatDateCourte = formatDateCourte;
}

public String getFormatDateLongue() {
    return formatDateLongue;
}

public void setFormatDateLongue(String formatDateLongue) {
    this.formatDateLongue = formatDateLongue;
}

public String getFormatHeure() {
    return formatHeure;
}

public void setFormatHeure(String formatHeure) {
    this.formatHeure = formatHeure;
}

public String getFormatNumerique() {
    return formatNumerique;
}

public void setFormatNumerique(String formatNumerique) {
    this.formatNumerique = formatNumerique;
}

public BigInteger getTaillePartieDecimale() {
    return taillePartieDecimale;
}

public void setTaillePartieDecimale(BigInteger taillePartieDecimale) {
    this.taillePartieDecimale = taillePartieDecimale;
}

public String getSeparateurMillier() {
    return separateurMillier;
}

public void setSeparateurMillier(String separateurMillier) {
    this.separateurMillier = separateurMillier;
}

public String getSeparateurPartieDecimale() {
    return separateurPartieDecimale;
}

public void setSeparateurPartieDecimale(String separateurPartieDecimale) {
    this.separateurPartieDecimale = separateurPartieDecimale;
}

public BigInteger getUtilisateuridModif() {
    return utilisateuridModif;
}

public void setUtilisateuridModif(BigInteger utilisateuridModif) {
    this.utilisateuridModif = utilisateuridModif;
}

public BigInteger getUtilisateuridCrea() {
    return utilisateuridCrea;
}

public void setUtilisateuridCrea(BigInteger utilisateuridCrea) {
    this.utilisateuridCrea = utilisateuridCrea;
}

public Date getDateCreation() {
    return dateCreation;
}

public void setDateCreation(Date dateCreation) {
    this.dateCreation = dateCreation;
}

public Date getDateModification() {
    return dateModification;
}

public void setDateModification(Date dateModification) {
    this.dateModification = dateModification;
}

@Override
public int hashCode() {
    int hash = 0;
    hash += (codeLangue != null ? codeLangue.hashCode() : 0);
    return hash;
}

@Override
public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof Langue)) {
        return false;
    }
    Langue other = (Langue) object;
    if ((this.codeLangue == null && other.codeLangue != null) || (this.codeLangue != null && !this.codeLangue.equals(other.codeLangue))) {
        return false;
    }
    return true;
}

@Override
public String toString() {
    return "com.collecteJ.crud.entities.Langue[ codeLangue=" + codeLangue + " ]";
}

}

1 个答案:

答案 0 :(得分:2)

尝试更改行

<property name="generateDdl" value="true" />   

为:

<property name="generateDdl" value="false" />