j.l.IllegalArgumentException: 不是受管理的类型

huangapple go评论70阅读模式
英文:

j.l.IllegalArgumentException: Not a managed type

问题

以下是您提供的内容的翻译:

我在使用Spring Boot + JPA启动应用程序时遇到了问题。

{
  "@timestamp": "2020-08-17T14:51:10.837+03:00",
  "loglevel": "ERROR",
  "thread_id": "main",
  "service": "le-migration-service",
  "class": "org.springframework.boot.SpringApplication",
  "message": "Application run failed",
  "stack_trace": "j.l.IllegalArgumentException: Not a managed type: class ro.raiffeisen.athena.lemigration.domain.entity.aibas.ValidAibasProducts\nat o.h.m.i.MetamodelImpl.managedType(MetamodelImpl.java:582)\nat o.h.m.i.MetamodelImpl.managedType(MetamodelImpl.java:85)\r\n\tat o.s.d.j.r.s.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:74)\nat o.s.d.j.r.s.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:66)\nat o.s.d.j.r.s.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:211)\nat o.s.d.j.r.s.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:161)\nat o.s.d.j.r.s.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:144)at o.s.d.j.r.s.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:69)\nat o.s.d.r.c.s.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:312)\nat o.s.d.r.c.s.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297)\nat o.s.data.util.Lazy.getNullable(Lazy.java:212)\nat o.s.data.util.Lazy.get(Lazy.java:94)\nat o.s.d.r.c.s.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300)\nat o.s.d.j.r.s.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:121)\nat o.s.b.f.s.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)\nat o.s.b.f.s.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)\n... 44 common frames omitted\nWrapped by: o.s.b.f.BeanCreationException: Error creating bean with name 'aibasRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class ro.raiffeisen.athena.lemigration.domain.entity.aibas.ValidAibasProducts\ntat o.s.b.f.s.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)\nat o.s.b.f.s.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFac...\n"
}

我有一个名为 "entity" 的类,它看起来像这样。实际上,它是一个简单的POJO,没有实体注解,因为我正在尝试将Oracle SQL连接的结果映射到非实体Java类。连接将返回一个字符串列表,我试图将其放入 "ValidAibasProducts" 类的 "integrationIdList" 字段中。

@MappedSuperclass
@Data
@SqlResultSetMapping(
        name="ValidAibasProducts",
        classes={
                @ConstructorResult(
                        targetClass=ValidAibasProducts.class,
                        columns={
                                @ColumnResult(name="integrationIdList")
                        }
                )
        }
)
@NamedNativeQuery(name="ValidAibasProducts", query="select t1.integration_id from ocrm_stg.s_org_ext t1 inner join ocrm_stg.s_asset t2 on t2.owner_accnt_id = t1.row_id where t2.prod_id in ('P-8JIA79', 'P-8JIA5Y') and t2.status_cd = 'Active'", resultSetMapping="ValidAibasProducts")
public class ValidAibasProducts {
    private List<String> integrationIdList;
}

仓库类如下所示:

@Repository
public interface AibasRepository extends JpaRepository<ValidAibasProducts, String> {
    List<String> getValidAibasProducts();
}

配置类如下所示:

@Configuration
@EnableJpaRepositories(basePackages = "//仓库路径",
        entityManagerFactoryRef = "aibasEntityManagerFactory",
        transactionManagerRef = "aibasTransactionManager"
)
public class AibasJpaBeansConfig {
    @Bean
    @ConfigurationProperties(prefix = "aibas.jpa")
    public JpaProperties aibasJpaProperties() {
        return new JpaProperties();
    }

    @Bean
    @ConfigurationProperties(prefix = "aibas.datasource")
    public DataSource aibasDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean
    public LocalContainerEntityManagerFactoryBean aibasEntityManagerFactory(
            final EntityManagerFactoryBuilder builder,
            @Qualifier("aibasDataSource") final DataSource aibasDataSource,
            @Qualifier("aibasJpaProperties") final JpaProperties aibasJpaProperties) {
        return builder
                .dataSource(aibasDataSource)
                .packages("//实体路径")
                .persistenceUnit("aibas")
                .properties(aibasJpaProperties.getProperties())
                .build();
    }

    @Bean
    public PlatformTransactionManager aibasTransactionManager(
            @Qualifier("aibasEntityManagerFactory") final EntityManagerFactory aibasEntityManagerFactory) {
        return new JpaTransactionManager(aibasEntityManagerFactory);
    }
}

我还想提到,我对此进行了一些研究,并尝试了不同的解决方案,例如在配置文件中添加注解 @EntityScan("//实体包路径"),或者尝试直接在存储库接口中查询连接,而不是使用 @SqlResultSetMapping。

它们都没有起作用。

目标是我希望能够在内存中以某种方式保存字符串列表,以便在开发中进一步使用。任何帮助将不胜感激。

英文:

I use Spring boot+JPA and having an issue when starting the app.

{&quot;@timestamp&quot;:&quot;2020-08-17T14:51:10.837+03:00&quot;,&quot;loglevel&quot;:&quot;ERROR&quot;,&quot;thread_id&quot;:&quot;main&quot;,&quot;service&quot;:&quot;le-migration-service&quot;,&quot;class&quot;:&quot;org.springframework.boot.SpringApplication&quot;,&quot;message&quot;:&quot;Application run failed&quot;,&quot;stack_trace&quot;:&quot;j.l.IllegalArgumentException: Not a managed type: class ro.raiffeisen.athena.lemigration.domain.entity.aibas.ValidAibasProducts
at o.h.m.i.MetamodelImpl.managedType(MetamodelImpl.java:582)
at o.h.m.i.MetamodelImpl.managedType(MetamodelImpl.java:85)\r\n\tat o.s.d.j.r.s.JpaMetamodelEntityInformation.&lt;init&gt;(JpaMetamodelEntityInformation.java:74)
at o.s.d.j.r.s.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:66)
at o.s.d.j.r.s.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:211)
at o.s.d.j.r.s.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:161)
at o.s.d.j.r.s.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:144)at o.s.d.j.r.s.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:69)
at o.s.d.r.c.s.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:312)
at o.s.d.r.c.s.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$5(RepositoryFactoryBeanSupport.java:297)
at o.s.data.util.Lazy.getNullable(Lazy.java:212)
at o.s.data.util.Lazy.get(Lazy.java:94)
at o.s.d.r.c.s.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:300)
at o.s.d.j.r.s.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:121)
at o.s.b.f.s.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1855)
at o.s.b.f.s.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1792)
... 44 common frames omitted
Wrapped by: o.s.b.f.BeanCreationException: Error creating bean with name &#39;aibasRepository&#39;: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Not a managed type: class ro.raiffeisen.athena.lemigration.domain.entity.aibas.ValidAibasProducts
tat o.s.b.f.s.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
at o.s.b.f.s.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFac...
&quot;}

I've got an "entity" that looks like this. It's actually a simple POJO without the entity annotation because I am trying to map the results of an oracle sql join to a non-entity java class. The join will return a list of strings which I am trying to put into the "ValidAibasProducts" class, in the "integrationIdList" field.

@MappedSuperclass
@Data
@SqlResultSetMapping(
        name=&quot;ValidAibasProducts&quot;,
        classes={
                @ConstructorResult(
                        targetClass=ValidAibasProducts.class,
                        columns={
                                @ColumnResult(name=&quot;integrationIdList&quot;)
                        }
                )
        }
)
@NamedNativeQuery(name=&quot;ValidAibasProducts&quot;, query=&quot;select t1.integration_id from ocrm_stg.s_org_ext t1 inner join ocrm_stg.s_asset t2 on t2.owner_accnt_id = t1.row_id where t2.prod_id in (&#39;P-8JIA79&#39;, &#39;P-8JIA5Y&#39;) and t2.status_cd = &#39;Active&#39;&quot;, resultSetMapping=&quot;ValidAibasProducts&quot;)

public class ValidAibasProducts {

    private List&lt;String&gt; integrationIdList;
}

The repository looks like this:

@Repository
public interface AibasRepository extends JpaRepository&lt;ValidAibasProducts, String&gt; {

    List&lt;String&gt; getValidAibasProducts();
}

The configuration class looks like this:

@Configuration
@EnableJpaRepositories(basePackages = &quot;//path to the repository&quot;,
        entityManagerFactoryRef = &quot;aibasEntityManagerFactory&quot;,
        transactionManagerRef = &quot;aibasTransactionManager&quot;
)
public class AibasJpaBeansConfig {

    @Bean
    @ConfigurationProperties(prefix = &quot;aibas.jpa&quot;)
    public JpaProperties aibasJpaProperties() {
        return new JpaProperties();
    }

    @Bean
    @ConfigurationProperties(prefix = &quot;aibas.datasource&quot;)
    public DataSource aibasDataSource() {
        return DataSourceBuilder.create().build();
    }

    @Bean
    public LocalContainerEntityManagerFactoryBean aibasEntityManagerFactory(
            final EntityManagerFactoryBuilder builder,
            @Qualifier(&quot;aibasDataSource&quot;) final DataSource aibasDataSource,
            @Qualifier(&quot;aibasJpaProperties&quot;) final JpaProperties aibasJpaProperties) {

        return builder
                .dataSource(aibasDataSource)
                .packages(&quot;//path to the entity&quot;)
                .persistenceUnit(&quot;aibas&quot;)
                .properties(aibasJpaProperties.getProperties())
                .build();
    }

    @Bean
    public PlatformTransactionManager aibasTransactionManager(
            @Qualifier(&quot;aibasEntityManagerFactory&quot;) final EntityManagerFactory aibasEntityManagerFactory) {
        return new JpaTransactionManager(aibasEntityManagerFactory);
    }

}

I also want to mention that I did some research on this and tried different solutions like adding the annotation @EntityScan("//path to the entity package") in the config file; or tried to query the join directly in the repository interface instead of using @SqlResultSetMapping.

None of them worked.

The goal is that I can somehow save the String list in-memory so that I can use it further in the development. Any help would be appreciated.

答案1

得分: 1

如果您倾向于将查询结果映射到非实体对象,则可以简单地使用 jpa Projection。创建一个名为 ValidAibasProducts 的接口,其中包含相关的属性方法。

英文:

If You tend to map a query result to non-entity object, you can simply use jpa Projection. create an interface ValidAibasProducts with
related property method.

huangapple
  • 本文由 发表于 2020年8月17日 20:28:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/63450817.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定