简体   繁体   English

春季-AWS(无春季启动):java.lang.IllegalArgumentException:不是托管类型

[英]Spring - AWS (no spring boot): java.lang.IllegalArgumentException: Not a managed type

I have an entity manager repository, set up as follows: 我有一个实体管理器存储库,设置如下:

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
    final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
    em.setDataSource(datasource());
    em.setJpaProperties(hibernateProperties(dynamicConfiguration));
    em.setPackagesToScan(new String[] {"<my model package>"});
    final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
    em.setJpaVendorAdapter(vendorAdapter);
    return em;
}

My entity class is defined as follows: 我的实体类定义如下:

@Entity
@Table(name = "model")
@Getter
@Setter
@NoArgsConstructor
public class Model {

@Column(name = "serialNumber")
private String serialNumber;

@Column(name = "region")
private String region;

@Column(name = "created")
private Date created;

@Column(name = "updated")
private Date updated;

@Column(name = "status")
private String status;


@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
@Column(name = "id")
private Long id;

}

My repository beans are like this: 我的存储库bean是这样的:

@Repository
public interface ModelRepository extends JpaRepository<Model, Long>, ModelCustomRepository<Model, Long> {

}

My custom repository 我的自定义存储库

@NoRepositoryBean
public interface ModelCustomRepository<E, L extends Number>{

List<Model> getModelsSkipUpdated();
}

My Custom repository implementation 我的自定义存储库实施

public class ModelCustomRepositoryImpl implements ModelCustomRepository<Model, Long> {

@Autowired
private DynamicConfiguration dynamicConfiguration;

@Qualifier("entityManageFactory")
@Autowired
private EntityManagerFactory entityManagerFactory;

@Override
public List<Model> getModelsForProvisioning() {
    Integer limit = dynamicConfiguration.getIntProperty("model.limit", 25).get();
    Query modelQuery = entityManagerFactory.createEntityManager().createNativeQuery(
                    "SELECT * FROM Model WHERE status = :status LIMIT :limit for update skip locked",
                    Model.class);
    modelQuery.setParameter("status", NOT_PROCESSED.name());
    modelQuery.setParameter("limit", limit);
    return modelQuery.getResultList();
}
}

I get the below error, I don't get why I am getting the error 我收到以下错误,我不明白为什么我收到错误

Caused by: java.lang.IllegalArgumentException: Not a managed type: class <package>.Model
at org.hibernate.metamodel.internal.MetamodelImpl.managedType(MetamodelImpl.java:472)
at org.springframework.data.jpa.repository.support.JpaMetamodelEntityInformation.<init>(JpaMetamodelEntityInformation.java:73)
at org.springframework.data.jpa.repository.support.JpaEntityInformationSupport.getEntityInformation(JpaEntityInformationSupport.java:66)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getEntityInformation(JpaRepositoryFactory.java:181)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:119)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactory.getTargetRepository(JpaRepositoryFactory.java:102)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:298)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.lambda$afterPropertiesSet$3(RepositoryFactoryBeanSupport.java:287)
at org.springframework.data.util.Lazy.getNullable(Lazy.java:141)
at org.springframework.data.util.Lazy.get(Lazy.java:63)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:290)
at org.springframework.data.jpa.repository.support.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:102)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1769)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1706)
... 54 more

I do not use spring-boot since this is an AWS lambda. 我不使用spring-boot,因为这是一个AWS Lambda。 Is there a way to work around this? 有办法解决这个问题吗? Hence no @EntityScan. 因此,没有@EntityScan。

My model class is not in the same package as the entity manager factory bean generation class. 我的模型类与实体管理器工厂bean生成类不在同一个包中。

On a side note, if there's a way to get the skip locked query within the @Repository bean, please let me know that as well. 附带说明一下,如果有一种方法可以在@Repository bean中获取跳过锁定的查询,请也告知我。

根据我对问题的评论:由于无法使用@EntityScan ,也许您需要提供一个描述实体的persistence.xml

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.lang.IllegalArgumentException:在Spring Boot应用程序中不是托管类型 - java.lang.IllegalArgumentException: Not a managed type in spring boot app java.lang.IllegalArgumentException:不是托管类型 - Spring Boot 中的多个数据库 - java.lang.IllegalArgumentException: Not a managed type - Multiple Databases in Spring Boot Spring Boot 异常“java.lang.IllegalArgumentException:不是托管类型:” - Spring Boot exception "java.lang.IllegalArgumentException: Not a managed type:" spring-data-solr java.lang.IllegalArgumentException:不是托管类型 - spring-data-solr java.lang.IllegalArgumentException: Not a managed type java.lang.IllegalArgumentException: Not a managed type With @Entity and @Repository Setup with Spring Boot 2 - java.lang.IllegalArgumentException: Not a managed type With @Entity and @Repository Setup with Spring Boot 2 春季-java.lang.IllegalArgumentException - Spring - java.lang.IllegalArgumentException 当实体类和Spring数据存储库位于同一包中时,“ java.lang.IllegalArgumentException:不是托管类型…” - “java.lang.IllegalArgumentException: Not a managed type …” when entity class and Spring data repository in same package spring boot:java.lang.IllegalArgumentException:object不是声明类的实例 - spring boot : java.lang.IllegalArgumentException: object is not an instance of declaring class Spring 启动 java.lang.IllegalArgumentException: URL 必须以 'jdbc' 开头 - Spring Boot java.lang.IllegalArgumentException: URL must start with 'jdbc' Spring boot:java.lang.IllegalArgumentException:驱动程序类名称需要jdbcUrl - Spring boot: java.lang.IllegalArgumentException: jdbcUrl is required with driverClassName
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM