0

Jdk 1.8.0_82, Springboot 1.3.8 and JPA.

I want insert new rows made from existing object value.

I Just call

List<LogSchemaFieldModel> newFields = Lists.newArrayList(); for(LogSchemaFieldModel f : fields){ newFields.add(new LogSchemaFieldModel(){{ setFieldName( f.getFieldName() ); setFieldType( f.getFieldType() ); setFieldOpt( Field.Mode.NULLABLE.toString() ); setDescription( f.getDescription() ); setSampleValue( f.getSampleValue() ); setCommon(true); setRequired(null); }}); } repo.save(newFields); 

but it throws this exception.

org.springframework.dao.InvalidDataAccessApiUsageException: Unknown entity: com......service.LogDefineService$6; nested exception is java.lang.IllegalArgumentException: Unknown entity: com......service.LogDefineService$6 at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:384) ~[spring-orm-4.2.8.RELEASE.jar:4.2.8.RELEASE] at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:227) ~[spring-orm-4.2.8.RELEASE.jar:4.2.8.RELEASE] at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:436) ~[spring-orm-4.2.8.RELEASE.jar:4.2.8.RELEASE] at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:59) ~[spring-tx-4.2.8.RELEASE.jar:4.2.8.RELEASE] at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:213) ~[spring-tx-4.2.8.RELEASE.jar:4.2.8.RELEASE] at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:147) ~[spring-tx-4.2.8.RELEASE.jar:4.2.8.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.8.RELEASE.jar:4.2.8.RELEASE] at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:131) ~[spring-data-jpa-1.9.5.RELEASE.jar:na] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.8.RELEASE.jar:4.2.8.RELEASE] at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.2.8.RELEASE.jar:4.2.8.RELEASE] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.2.8.RELEASE.jar:4.2.8.RELEASE] at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:208) ~[spring-aop-4.2.8.RELEASE.jar:4.2.8.RELEASE] at com.sun.proxy.$Proxy119.save(Unknown Source) ~[na:na] at com.my... 

1 Answer 1

5

finally, I found solution.

remove double brace initialize.

List<LogSchemaFieldModel> newFields = Lists.newArrayList(); for(LogSchemaFieldModel f : fields){ LogSchemaFieldModel nf = new LogSchemaFieldModel(); nf.setFieldName( f.getFieldName() ); nf.setFieldType( f.getFieldType() ); nf.setFieldOpt( Field.Mode.NULLABLE.toString() ); nf.setDescription( f.getDescription() ); nf.setSampleValue( f.getSampleValue() ); nf.setCommon(true); nf.setRequired(null); newFields.add(nf); } repo.save(newFields); 

But I don`t knwow why it works. is it java8 double brace initialization bug?

Sign up to request clarification or add additional context in comments.

2 Comments

Had same issue. Removing double brace initialisation solved it for me. Does anyone know why this is an issue?
I had to the problem with Spring boot and H2 database

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.