javahibernatejhipsterjdl

OneToMany relationship generated with JHipster causes Exceptions


I have written the following JDL:

enter code here

entity A {
  name String required
}

entity B {
  name String unique required,
}

relationship OneToMany {
  B{children} to A{owner}
}

application {
  config {
    applicationType monolith
    databaseType sql
  }
  entities *
  dto * with mapstruct
  service * with serviceClass
}

However the code generated throws the following:

/src/main/java/foo/service/mapper/A.java:13: Warnung: Unmapped target children: "children, removeChildren". Mapping from property "BDTO owner" to "B owner". Occured at 'E toEntity(D dto)' in 'EntityMapper'. public interface A extends EntityMapper<ADTO, A> { ^ /src/main/java/foo/service/mapper/AMapper.java:13: Warnung: Unmapped target properties: "children, removeChildren". Mapping from property "BDTO owner" to "B owner". Occured at 'void partialUpdate(E entity, D dto)' in 'EntityMapper'. public interface AMapper extends EntityMapper<ADTO, A> { ^ /src/main/java/foo/service/mapper/BMapper.java:13: Warnung: Unmapped target properties: "children, removeChildren". Occured at 'E toEntity(D dto)' in 'EntityMapper'. public interface BMapper extends EntityMapper<BDTO, B> { ^ /src/main/java/foo/service/mapper/BMapper.java:13: Warnung: Unmapped target properties: "children, removeChildren". Occured at 'void partialUpdate(E entity, D dto)' in 'EntityMapper'. public interface ModelMapper extends EntityMapper<BDTO, B> { ^ 4 Warnungen

Likewise whne trying to access the corresponding endpoint, an exception is thrown from Hibernate:

ERROR 30510 --- [ XNIO-1 task-3] foo.service.AService : Exception in findAll() with cause = 'org.hibernate.exception.SQLGrammarException: could not prepare statement' and exception = 'could not prepare statement; SQL [select a0_.id as id1_1_, a0_.name as name2_1_, a0_.owner_id as owner_id4_1_, a0_.value as value3_1_ from a a0_]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement' org.springframework.dao.InvalidDataAccessResourceUsageException: could not prepare statement; SQL [select a0_.id as id1_1_, a0_.name as name2_1_, a0_.owner_id as owner_id4_1_, a0_.value as value3_1_ from a a0_]; nested exception is org.hibernate.exception.SQLGrammarException: could not prepare statement at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:259) at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:233) at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:551) at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61) at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242) at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:152) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:174) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:97) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) at jdk.proxy3/jdk.proxy3.$Proxy200.findAll(Unknown Source) at foo.service.AService.findAll(AService.java:88) at foo.service.AService$$FastClassBySpringCGLIB$$4afc8e16.invoke() at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ....

Now my question would be what am I doing wrong here (or is it an issue with jHipster) and how could I approach fixing it?

Cheers


Solution

  • After some digging in the generated code I figured out that the Gnerated Repository Class was empty so I went about creating corresponding methods in it. However a JPA Query still threw an error but a native query did the trick. So now I am wondering why jHipster did not generate the code, likewise I wonder why JPA is unable to correctly build the query. I am however fairly confident that I will find the answer tothe latter issue at least.