我试图从standartfont中包含的elementcollection中提取数据。

public class DBFonts {

@Id
@GeneratedValue(strategy= GenerationType.AUTO)
private long id;
private String nameFont;


@ElementCollection
@CollectionTable(
        name="StandartFont",
        joinColumns=@JoinColumn(name="Fonts_id")
@Lob @Basic(fetch = FetchType.LAZY)
@Column(length=100000)
private List<byte[]> StandartFonts; }

存储库:
public interface FontRepo extends JpaRepository<DBFonts,Long> {
   List<byte[]> findByStandartFonts(Long fonsId);
}

 HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect
Hibernate: alter table font add constraint FKpcplr5ixrmh5lbjx0e6peoqo4 foreign key (user_id) references usr (id)
Hibernate: alter table standart_font add constraint FKq7nxy6see56tp2y997fwmsewq foreign key (fonts_id) references font (id)
2018-12-06 16:15:54.338  INFO 6168 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2018-12-06 16:15:54.884  WARN 6168 --- [  restartedMain] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'addFont': Unsatisfied dependency expressed through field 'fontRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fontRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List spring_mvc.entity.FontRepo.findByStandartFonts(java.lang.Long)! Unable to locate Attribute  with the the given name [standartFonts] on this ManagedType [spring_mvc.entity.DBFonts]
2018-12-06 16:15:54.884  INFO 6168 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2018-12-06 16:15:54.886  INFO 6168 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2018-12-06 16:15:54.896  INFO 6168 --- [  restartedMain] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.
2018-12-06 16:15:54.898  INFO 6168 --- [  restartedMain] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2018-12-06 16:15:54.916  INFO 6168 --- [  restartedMain] ConditionEvaluationReportLoggingListener :

    Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
    2018-12-06 16:15:54.928 ERROR 6168 --- [  restartedMain] o.s.boot.SpringApplication               : Application run failed

    org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'addFont': Unsatisfied dependency expressed through field 'fontRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fontRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List spring_mvc.entity.FontRepo.findByStandartFonts(java.lang.Long)! Unable to locate Attribute  with the the given name [standartFonts] on this ManagedType [spring_mvc.entity.DBFonts]
        at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:586) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]

at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49) [spring-boot-devtools-2.0.5.RELEASE.jar:2.0.5.RELEASE]
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fontRepo': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract java.util.List spring_mvc.entity.FontRepo.findByStandartFonts(java.lang.Long)! Unable to locate Attribute  with the the given name [standartFonts] on this ManagedType [spring_mvc.entity.DBFonts]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699) ~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]

它不工作,如何正确提取数据?
能用吗?:
从standart_font where fonts_id=?中选择standart_字体。
如何在@query中编写

最佳答案

spring在您的类中找不到名为standartFonts的属性,这就是它不能用您的DBFonts创建been的原因。
在上找不到具有给定名称[standartfonts]的属性
此managedType[spring\mvc.entity.dbfonts]
spring使用反射从存储库中获取方法名(repository)并解析它:findByStandartFonts它的意思是findByselectspring parse asStandartFonts,它试图在standartFonts中找到这个字段。
注意,在@Entity字段中,请使用id而不是Long。这是很好的做法。
在Java代码中使用long

07-25 23:53