英文:
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.
{"@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
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.<init>(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 '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
tat o.s.b.f.s.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1796)
at o.s.b.f.s.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFac...
"}
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="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;
}
The repository looks like this:
@Repository
public interface AibasRepository extends JpaRepository<ValidAibasProducts, String> {
List<String> getValidAibasProducts();
}
The configuration class looks like this:
@Configuration
@EnableJpaRepositories(basePackages = "//path to the repository",
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("//path to the entity")
.persistenceUnit("aibas")
.properties(aibasJpaProperties.getProperties())
.build();
}
@Bean
public PlatformTransactionManager aibasTransactionManager(
@Qualifier("aibasEntityManagerFactory") 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论