Spring Bean tenantEntityManager error: Unable to find column with Logical name

Asked

Viewed 143 times

0

am having an error while trying to run my JSF application with Spring, more specifically:

-I have a method to do a badge search on certain repositories and change them after running method on a controller;

-the error started to appear after I was creating the various classes in which they have employee badges and should be changed;

-I was creating them in the order: class first, then the repository of the class itself, injecting it into the controller responsible for the exchange with the annotation @Autowired;

-the error did not make much sense to me due to the fact that simply while creating a class even without doing a @Joincolumn referring to table that apparently is causing the error, it occurs;

there’s the mistake:

----------
2019-03-20 13:20:05.569  INFO 11056 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2019-03-20 13:20:05.569  INFO 11056 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2019-03-20 13:20:05.580  WARN 11056 --- [  restartedMain] org.hibernate.orm.deprecation            : HHH90000006: Attempted to specify unsupported NamingStrategy via setting [hibernate.ejb.naming_strategy]; NamingStrategy has been removed in favor of the split ImplicitNamingStrategy and PhysicalNamingStrategy; use [hibernate.implicit_naming_strategy] or [hibernate.physical_naming_strategy], respectively, instead.
2019-03-20 13:20:05.807  INFO 11056 --- [  restartedMain] org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
2019-03-20 13:20:05.967  WARN 11056 --- [  restartedMain] org.hibernate.cfg.AnnotationBinder       : HHH000139: Illegal use of @Table in a subclass of a SINGLE_TABLE hierarchy: XPROJECT.REP
2019-03-20 13:20:05.977  WARN 11056 --- [  restartedMain] ationConfigEmbeddedWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tenantEntityManager' defined in class path resource [X/Y/Z/configuration/MultiTenancyJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Unable to find column with logical name fun_empresa in table CADFUN
Related cause: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'tenantEntityManager': Requested bean is currently in creation: Is there an unresolvable circular reference?
2019-03-20 13:20:05.978  INFO 11056 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'master'
2019-03-20 13:20:05.979  INFO 11056 --- [  restartedMain] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Close initiated...
2019-03-20 13:20:06.855  INFO 11056 --- [  restartedMain] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Closed.
2019-03-20 13:20:06.858  INFO 11056 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2019-03-20 13:20:06.877  INFO 11056 --- [  restartedMain] utoConfigurationReportLoggingInitializer : 

Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2019-03-20 13:20:06.881 ERROR 11056 --- [  restartedMain] o.s.boot.SpringApplication               : Application startup failed

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tenantEntityManager' defined in class path resource [X/Y/Z/configuration/MultiTenancyJpaConfiguration.class]: Invocation of init method failed; nested exception is org.hibernate.MappingException: Unable to find column with logical name fun_empresa in table CADFUN
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) ~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) ~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078) ~[spring-context-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:857) ~[spring-context-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:543) ~[spring-context-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
    at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:693) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
    at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:360) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1118) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1107) [spring-boot-1.5.7.RELEASE.jar:1.5.7.RELEASE]
    at X.Y.Z.MyApplication.main(MyApplication.java:10) [classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_121]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_121]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_121]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_121]
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-1.5.7.RELEASE.jar:1.5.7.RELEASE]
Caused by: org.hibernate.MappingException: Unable to find column with logical name fun_empresa in table CADFUN
    at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.getPhysicalColumnName(InFlightMetadataCollectorImpl.java:997) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.getPhysicalColumnName(InFlightMetadataCollectorImpl.java:966) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.cfg.BinderHelper.findPropertiesByColumns(BinderHelper.java:380) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:261) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:100) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processEndOfQueue(InFlightMetadataCollectorImpl.java:1786) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processFkSecondPassesInOrder(InFlightMetadataCollectorImpl.java:1730) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.boot.internal.InFlightMetadataCollectorImpl.processSecondPasses(InFlightMetadataCollectorImpl.java:1617) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:278) ~[hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.metadata(EntityManagerFactoryBuilderImpl.java:847) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:874) ~[hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) ~[spring-orm-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370) ~[spring-orm-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359) ~[spring-orm-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) ~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) ~[spring-beans-4.3.11.RELEASE.jar:4.3.11.RELEASE]
    ... 21 common frames omitted

EDIT 1: the logical column fun_company does exist in the cadfun table:inserir a descrição da imagem aqui

inserir a descrição da imagem aqui

-EMPLOYEE MAPPING(CADFUN):

package X.Y.Z.model.tenancy;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedEntityGraph;
import javax.persistence.NamedEntityGraphs;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.ObjectUtils;

import br.com.mhfsistemas.util.BoolUtils;
import br.com.mhfsistemas.util.StrUtils;

@Entity
@Table(name="CADFUN")
@NamedEntityGraphs({
    @NamedEntityGraph(name = "Funcionario.AllAttributes", includeAllAttributes = true)
})

public class Funcionario implements Serializable {

private static final long serialVersionUID = 3284546527564750294L;

public static final String TIPO_FUNCIONARIO = "F";
public static final String TIPO_ADMINISTRADOR = "A";

@Id
@Column(name = "fun_cracha")
private Double cracha;

@Column(name = "fun_descricao", length = 70, nullable = false)
private String nome;

@Column(name = "fun_nome_reduzido", length = 20)
private String nomeReduzido;

@Column(name = "fun_email", length = 254, unique = true)
private String email;

@Column(name = "fun_cpf_numero", length = 20)
private String cpf;

@Column(name = "fun_rg_numero", length = 12)
private String rg;

@Column(name = "fun_data_nascimento")
private Date dataNascimento;    

@Column(name = "fun_codigo", nullable = false)
private Float registro;

@Column(name = "fun_digito")
private Float digitoRegistro;

@Column(name = "fun_pis_float")
private Long pis;

@Column(name = "fun_pis_numero", length = 20)
private String pisString;

@Column(name = "fun_data_de_admissao", nullable = false)
private Date dataAdmissao;

@ManyToOne
@JoinColumn(name = "fun_empresa", nullable = false)
private Empresa empresa;

@ManyToOne
@JoinColumn(name = "fun_cargo")
private Cargo cargo;

@Column(name = "fun_departamento")
private Float departamento;

@Column(name = "fun_setor")
private Float setor;

@Column(name = "fun_secao")
private Float secao;    

@ManyToOne
@JoinColumn(name = "fun_contrato_trabalho", nullable = false)
private ContratoTrabalho contratoTrabalho;

@ManyToOne
@JoinColumn(name = "fun_prioridades", nullable = false)
private Prioridade prioridade;

@ManyToOne
@JoinColumn(name = "fun_categoria")
private Categoria categoria;

@Column(name = "c80")
private Double crachaGestor;    

@Column(name = "fun_cracha_alfa")
private String codAux;

@Column(name = "fun_senha_terminal")
private Integer senhaRep;

@Column(name = "fun_salario")
private BigDecimal salario;

@Column(name = "fun_administrador_rep")
private String admRep;

@Column(name = "fun_habilitar_teclado")
private String habilitarTeclado;

@Column(name = "fun_rg_emissao")
private Date dataRg;

@Column(name = "fun_rg_orgao", length = 10)
private String orgaoRg;

@Column(name = "fun_ctps_numero", length = 15)
private String numeroCtps;

@Column(name = "fun_ctps_serie", length = 6)
private String serieCtps;

@Column(name = "fun_ctps_orgao", length = 10)
private String orgaoCtps;

@Column(name = "fun_habilitacao_prof", length = 20)
private String habilitacaoProfissional;

@Column(name = "fun_telefone", length = 30)
private String telefone;

@Column(name = "fun_endereco", length = 40)
private String endereco;

@Column(name = "fun_cidade", length = 20)
private String cidade;

@Column(name = "fun_estado", length = 2)
private String estado;

@Column(name = "fun_cep", length = 9)
private String cep;

@Column(name = "fun_envia_relatorios_email")
private String enviaRelatoriosEmail;

@Column(name = "fun_email_relatorios", length = 100)
private String emailRelatorios;

@Column(name = "fun_tipo_usuario_flexweb", length = 1)
private String tipoUsuarioWeb;

@Column(name = "fun_horas_extras", length = 1)
private String horasExtras;

@Column(name = "fun_tipo_de_funcionario", length = 1)
private String tipoDeFuncionario;

@Column(name = "fun_regime", length = 1)
private String regime;

@Transient
private boolean gestor; 

EDIT 2: here is an example of a class in which I refer to FUNCIONARIO (CADFUN) even using the fun_empresa column normally:

package x.y.z.model.tenancy;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "ORDCMP")
public class ComponenteOrdemServico implements Serializable {

private static final long serialVersionUID = 1459696828398449480L;
@Id
@Column(name = "orc_sequencia", nullable = false)
private Integer id;

@ManyToOne
@JoinColumns({
    @JoinColumn(name = "orc_empresa", referencedColumnName = "fun_empresa", nullable = false),
    @JoinColumn(name = "orc_funcionario", referencedColumnName = "fun_codigo", nullable = false) })
private Funcionario funcionario;

@Column(name = "orc_ordem_servico")
private String ordemServico;

public Integer getId() {
    return id;
}

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

public Funcionario getFuncionario() {
    return funcionario;
}

public void setFuncionario(Funcionario funcionario) {
    this.funcionario = funcionario;
}

public String getOrdemServico() {
    return ordemServico;
}

public void setOrdemServico(String ordemServico) {
    this.ordemServico = ordemServico;
}

@Override
public String toString() {
    return String.format("%s[codigo=%d]", getClass().getSimpleName(), getId());
}   

}

EDIT 3: a comment.. as quoted above, I was adding class by class that the employee badge should be edited, but when it came to a certain amount it started to give this error.. if I delete for example the @Entity annotation of this Componenteordemservico that I posted, the application works again, so if I add this annotation again it gives the error.. so it doesn’t make any sense at least to me (OBS: I moved with spring boot for less than two months)

  • The mistake is very clear: Unable to find column with logical name fun_empresa in table CADFUN in the CADFUN table there is no such column that is mapped in its class. if you can post the entity code together with the DDL of the CADFUN table.

  • Yes I am aware that this error is very explicit, so I said it made no sense to me since the fun_company column exists... posted the images in EDIT 1

2 answers

1


So, on this block

@ManyToOne
@JoinColumns({
@JoinColumn(name = "orc_empresa", referencedColumnName = "fun_empresa", nullable = false),
@JoinColumn(name = "orc_funcionario", referencedColumnName = "fun_codigo", nullable = false) })
private Funcionario funcionario;

references the existence of two key columns in the Employee entity, okay! I believe that at this moment JPA is already aware of the existence of the column "fun_company" and its reference.

However in the Function entity Voce references again the column

@ManyToOne
@JoinColumn(name = "fun_empresa", nullable = false)
private Empresa empresa;

Pointing to another entity, so in my view it was a bit confused, I could not capture what it is trying to accomplish, but I believe that this is the point of the problem.

Apologies for not only being able to comment, because I still have few points so I had to create an answer, thank you if you can answer so we can help you more.

  • good! thanks for the opinion, but explaining why I refer to both: in the class that references orc_empresa and orc_funcionario, it is because in the system an employee has a unique badge independent of the company that he belongs to, and also has a record, which may be the same if the employee is from different companies

0

Solved, simply removed all @JoinColumns and I just left @JoinColumn referencing only the employee code, without the company.

Thank you Jonathan! It was very helpful your reply .

Browser other questions tagged

You are not signed in. Login or sign up in order to post.