Reputation: 23
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.
Upvotes: 0
Views: 397
Reputation: 2484
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.
Upvotes: 1