Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database 如何从ElementCollection中提取数据_Database_Spring_Spring Data Jpa - Fatal编程技术网

Database 如何从ElementCollection中提取数据

Database 如何从ElementCollection中提取数据,database,spring,spring-data-jpa,Database,Spring,Spring Data Jpa,我试图从StandartFont中包含的ElementCollection中提取数据 public class DBFonts { @Id @GeneratedValue(strategy= GenerationType.AUTO) private long id; private String nameFont; @ElementCollection @CollectionTable( name="StandartFont", joinColumns=@J

我试图从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; }
公共类dbfont{
@身份证
@GeneratedValue(策略=GenerationType.AUTO)
私人长id;
私有字符串名称字体;
@元素集合
@收集表(
name=“StandartFont”,
joinColumns=@JoinColumn(name=“font\u id”)
@Lob@Basic(fetch=FetchType.LAZY)
@列(长度=100000)
私有列表标准字体;}
存储库:

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]
公共接口FontRepo扩展了JpaRepository{
列出findByStandartFonts(长字体);
}
HH000400:使用方言:org.hibernate.dialogue.mysql5dialogue
Hibernate:alter table font add constraint FKPCPPLR5IXRMH5LBJX0E6PEOQO4外键(用户id)引用usr(id)
Hibernate:alter table standart_font添加约束FKQ7NXY6请参见56TP2Y997FWMSEWQ外键(fonts_id)引用字体(id)
2018-12-06 16:15:54.338信息6168---[restartedMain]j.LocalContainerEntityManagerFactoryBean:初始化了持久化单元“默认”的JPA EntityManagerFactory
2018-12-06 16:15:54.884警告6168---[重新启动主站]ConfigServletWebServerApplicationContext:在上下文初始化期间遇到异常-取消刷新尝试:org.springframework.beans.factory.unsatifiedDependencyException:创建名为“addFont”的bean时出错:通过字段“fontRepo”表示的未满足的依赖项;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“fontRepo”的bean时出错:调用init方法失败;嵌套异常为java.lang.IllegalArgumentException:无法创建方法公共抽象java.util.List spring_mvc.entity.fontRepo.findByStandartFonts(java.lang.Long)的查询!无法找到具有给定名称的属性[standartFonts]在此ManagedType上[spring\u mvc.entity.DBFonts]
2018-12-06 16:15:54.884信息6168---[restartedMain]j.LocalContainerEntityManagerFactoryBean:关闭持久化单元“默认”的JPA EntityManagerFactory
2018-12-06 16:15:54.886信息6168---[restartedMain]com.zaxxer.hikari.HikariDataSource:hikaripol-1-已启动关机。。。
2018-12-06 16:15:54.896信息6168---[restartedMain]com.zaxxer.hikari.HikariDataSource:hikaripol-1-关闭完成。
2018-12-06 16:15:54.898信息6168---[restartedMain]o.apache.catalina.core.StandardService:停止服务[Tomcat]
2018-12-06 16:15:54.916信息6168---[restartedMain]条件评估报告日志监听器:
启动ApplicationContext时出错。若要显示条件报告,请在启用“调试”的情况下重新运行应用程序。
2018-12-06 16:15:54.928错误6168---[restartedMain]o.s.boot.SpringApplication:应用程序运行失败
org.springframework.beans.factory.unsatifiedPendencyException:创建名为“addFont”的bean时出错:通过字段“fontRepo”表示的未满足依赖项;嵌套异常为org.springframework.beans.factory.BeanCreationException:创建名为“fontRepo”的bean时出错:调用init方法失败;嵌套异常为java.lang。IllegalArgumentException:无法为方法public abstract java.util.List spring_mvc.entity.FontRepo.findByStandartFonts(java.lang.Long)创建查询!无法在此ManagedType[spring_mvc.entity.DBFonts]上找到具有给定名称[standartFonts]的属性
在org.springframework.beans.factory.annotation.AutoWiredNotationBeanPostProcessor$AutoWiredFeldElement.inject(AutoWiredNotationBeanPostProcessor.java:586)~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
在org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)[spring-boot-devtools-2.0.5.RELEASE.jar:2.0.5.RELEASE]
原因:org.springframework.beans.factory.BeanCreationException:创建名为“fontRepo”的bean时出错:调用init方法失败;嵌套异常为java.lang.IllegalArgumentException:未能为方法公共抽象java.util.List spring_mvc.entity.fontRepo.findByStandartFonts(java.lang.Long)创建查询!在此ManagedType[spring\u mvc.entity.DBFonts]上找不到具有给定名称[standartFonts]的属性
在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1699)~[spring-beans-5.0.9.RELEASE.jar:5.0.9.RELEASE]
它不工作,如何正确提取数据

能用吗?: 从标准字体中选择标准字体,其中字体id=?
如何在@Query

中编写此代码Spring在类
DBFonts
中找不到名为
standartFonts
的属性,这就是为什么它无法使用
存储库创建BEN

在上找不到具有给定名称[standartFonts]的属性 此ManagedType[spring\u mvc.entity.DBFonts]

Spring使用反射从您的存储库中获取方法名称(
findByStandartFonts
),并对其进行解析:
findBy
其方法
选择
StandartFonts
Spring解析为
StandartFonts
,并尝试在您的
@实体中查找此字段

另外,在
id
字段中,请使用
Long
而不是
Long
。这是一个很好的做法。
并在java代码中使用
camelCase

您能扩展它吗?请将字段“StandartFonts”重命名为“StandartFonts”WARN 8412---[nio-8080-exec-4]。m.m.a.ExceptionHandlerExceptionResolver:由处理程序执行引起的已解决异常:org.springframework.dao.InvalidDataAccessApiUsageException:参数值[2]与预期类型[[B(n/a)]不匹配;嵌套异常为java.lang.IllegalArgumentException:参数值[2]与预期类型[[B(n/a)]不匹配您能给出完整的stacktrace吗?已满!!!!!警告8412---[nio-8080-exec-4].m.m.a.ExceptionHandlerExceptionResolver:由处理程序执行引起的已解决异常:org.springframework.dao.Invalid