From 8ab95abd61c3b05469b7d033b6211d2f11f0598e Mon Sep 17 00:00:00 2001 From: Lurian Date: Wed, 9 Nov 2022 08:10:05 +0100 Subject: [PATCH] Fixed logic error pertaining @OneToMany and @ManyToOne annotations --- ...eate_${variables.entityName}Entity.sql.ftl | 19 +++++++++---------- .../templates/testclasses/SQLTestEntity.java | 17 ++++++++--------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/templates/V0000__Create_${variables.entityName}Entity.sql.ftl b/cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/templates/V0000__Create_${variables.entityName}Entity.sql.ftl index 4052dda1a2..01ad07c463 100644 --- a/cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/templates/V0000__Create_${variables.entityName}Entity.sql.ftl +++ b/cobigen-templates/templates-devon4j/src/main/templates/sql_java_app/templates/V0000__Create_${variables.entityName}Entity.sql.ftl @@ -12,23 +12,24 @@ ${SQLUtil.debug(pojo)} <#continue> <#-- Primary Key statement --> <#elseif field.annotations.javax_persistence_Id??> - <#assign statements = statements + [SQLUtil.primaryKeyStatement(field)]> + <#assign statements += [SQLUtil.primaryKeyStatement(field)]> <#-- OneToOne statement --> <#elseif field.annotations.javax_persistence_OneToOne??> <#-- Key mapped on other table, skip --> <#if field.annotations.javax_persistence_OneToOne.mappedBy != ""> <#continue> - <#assign statements = statements + [SQLUtil.foreignKeyStatement(field)]> - <#-- OneToMany Foreign Keystatement --> + <#assign statements += [SQLUtil.foreignKeyStatement(field)]> + <#-- Skip OneToMany as it's just a Foreign Key on a different table --> <#elseif field.annotations.javax_persistence_OneToMany??> - <#assign statements = statements + [SQLUtil.foreignKeyStatement(field)]> - <#elseif field.annotations.javax_persistence_ManyToOne??> - <#-- Skip ManyToOne as it's just a Foreign Key on a different table --> <#continue> + <#-- ManyToOne: create Foreign Keystatement from the field --> + <#elseif field.annotations.javax_persistence_ManyToOne??> + <#assign statements += [SQLUtil.foreignKeyStatement(field)]> + <#-- TODO: Check if there is a JoinTable specified that should be created. --> <#elseif field.annotations.javax_persistence_ManyToMany??> - <#-- Check if there is a JoinTable specified.... --> <#continue> + <#-- Try generating simple SQL statement from field --> <#else> <#assign statements += [SQLUtil.basicStatement(field)]> @@ -38,8 +39,6 @@ CREATE TABLE ${tableName} ( ${statement}, ); -<#-- TODO: parse generated JoinTables (NOT SURE IF NECESSARY! - AS TICKET MAYBE IMPLIES 1 SQL FILE FOR EACH ENTITY. ---> +<#-- TODO: parse generated JoinTables --> <#list joinTables as tb> \ No newline at end of file diff --git a/cobigen-templates/templates-devon4j/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/testclasses/SQLTestEntity.java b/cobigen-templates/templates-devon4j/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/testclasses/SQLTestEntity.java index 23b94a8ad4..dff999c71c 100644 --- a/cobigen-templates/templates-devon4j/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/testclasses/SQLTestEntity.java +++ b/cobigen-templates/templates-devon4j/src/test/java/com/devonfw/cobigen/templates/devon4j/test/templates/testclasses/SQLTestEntity.java @@ -11,13 +11,13 @@ public class SQLTestEntity { private Long id; @Column(name = "VALUENAME") - private Integer value; + private Integer integerValue; - @OneToOne(mappedBy = "I_am_mapped!!_and_should_be_skipped!") + @OneToOne private ReferenceEntity refEntity; @Enumerated(EnumType.STRING) - @Column(length = 420, name = "YES_EXCACTLY") + @Column(length = 420, name = "ENUM_TEST_FIELD_NAME_OVERRIDE") private EnumForTest enumForTest; private List referenceEntities; @@ -30,17 +30,16 @@ public void setId(Long id) { this.id = id; } - public Integer getValue() { - return value; + public Integer getIntegerValue() { + return integerValue; } - public void setValue(Integer value) { - this.value = value; + public void setIntegerValue(Integer value) { + this.integerValue = value; } - @OneToMany - @JoinColumn(name = "reference_entity_id", unique = true, nullable = false) + @OneToMany(mappedBy = "I_SHALL_BE_SKIPPED") public List getReferenceEntities() { return referenceEntities; }