From 00ebfb6e23a5a3787bda9dc9d5643ac4d6edea2f Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Wed, 20 Jul 2016 22:01:47 +0200 Subject: [PATCH] Spring JPA: data base, column names with caps --- .../de/spring/example/persistence/domain/Ad.java | 16 +- .../example/persistence/domain/AdDescription.java | 16 +- .../persistence/domain/audit/MyCustomRevision.java | 5 +- .../domain/audit/MyCustomRevisionListener.java | 10 +- .../persistence/domain/audit/package-info.java | 6 + .../liquibase/ddlChangelog.xml | 42 +- .../liquibase/dmlChangelog.xml | 3902 ++++++++++---------- 7 files changed, 2008 insertions(+), 1989 deletions(-) create mode 100644 SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/audit/package-info.java diff --git a/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/Ad.java b/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/Ad.java index 0f91253..73672a2 100644 --- a/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/Ad.java +++ b/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/Ad.java @@ -33,7 +33,7 @@ import de.spring.example.persistence.converters.OffsetDateTimeAttributeConverter @Entity @Audited(withModifiedFlag=true) -@Table(name="ad", schema="mybatis_example") +@Table(name="AD", schema="mybatis_example") @JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="jsonId") // 1. Named query is JPL. It is portable. // 2. Instead of annotating the domain class we should be using @Query annotation at the query method @@ -68,34 +68,34 @@ public class Ad implements Serializable { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) - @Column(name="id", updatable=false, nullable=false) + @Column(name="ID", updatable=false, nullable=false) private Long id; @OneToMany(fetch=FetchType.LAZY, cascade = CascadeType.ALL) - @JoinColumn(name = "ad_id", nullable = false) + @JoinColumn(name = "AD_ID", nullable = false) private Set adDescriptions; @Max(60) - @Column(name="company_id") + @Column(name="COMPANY_ID") private Long companyId; @Max(40) - @Column(name="company_categ_id") + @Column(name="COMPANY_CATEG_ID") private Long companyCategId; @Size(min=2, max=255) - @Column(name="ad_mobile_image") + @Column(name="AD_MOBILE_IMAGE") private String adMobileImage; @NotNull @Convert(converter=OffsetDateTimeAttributeConverter.class) - @Column(name="created_at", nullable=false) + @Column(name="CREATED_AT", nullable=false) @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ssZ") private OffsetDateTime createdAt; @NotNull @Convert(converter=OffsetDateTimeAttributeConverter.class) - @Column(name="updated_at", nullable = false) + @Column(name="UPDATED_AT", nullable = false) @JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd HH:mm:ssZ") private OffsetDateTime updatedAt; diff --git a/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/AdDescription.java b/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/AdDescription.java index 2142b39..0b07605 100644 --- a/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/AdDescription.java +++ b/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/AdDescription.java @@ -23,42 +23,42 @@ import com.fasterxml.jackson.annotation.ObjectIdGenerators; @Entity @Audited -@Table(name="ad_description", schema="mybatis_example") +@Table(name="AD_DESCRIPTION", schema="mybatis_example") @JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="jsonId") public class AdDescription implements Serializable { @Id @GeneratedValue(strategy=GenerationType.IDENTITY) - @Column(name="id", updatable=false, nullable=false) + @Column(name="ID", updatable=false, nullable=false) private Long id; @ManyToOne(fetch=FetchType.LAZY, cascade = CascadeType.ALL, optional=true) - @JoinColumn(name="ad_id", nullable=false, updatable = false, insertable = false, referencedColumnName="id") + @JoinColumn(name="AD_ID", nullable=false, updatable = false, insertable = false, referencedColumnName="ID") private Ad ad; @NotNull @Max(60) - @Column(name="laguage_id") + @Column(name="LANGUAGE_ID") private Long languageId; @NotNull @Size(min=2, max=255) - @Column(name="ad_name") + @Column(name="AD_NAME") private String adName; @NotNull @Size(min=2, max=255) - @Column(name="ad_description") + @Column(name="AD_DESCRIPTION") private String adDescription; @NotNull @Size(min=2, max=500) - @Column(name="ad_mobile_text") + @Column(name="AD_MOBILE_TEXT") private String adMobileText; @NotNull @Size(min=2, max=3000) - @Column(name="ad_link") + @Column(name="AD_LINK") private String adLink; // It will be used by JPA when filling the property fields with data coming from data base. diff --git a/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/audit/MyCustomRevision.java b/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/audit/MyCustomRevision.java index f8ebfe9..692acb5 100644 --- a/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/audit/MyCustomRevision.java +++ b/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/audit/MyCustomRevision.java @@ -1,14 +1,17 @@ package de.spring.example.persistence.domain.audit; +import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Table; +import org.hibernate.envers.DefaultRevisionEntity; import org.hibernate.envers.RevisionEntity; @Entity @RevisionEntity(MyCustomRevisionListener.class) @Table(name="CUSTOM_REVISION", schema="mybatis_example") -public class MyCustomRevision { +public class MyCustomRevision extends DefaultRevisionEntity { + @Column(name="USERNAME") private String username; // It will be used by JPA when filling the property fields with data coming from data base. diff --git a/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/audit/MyCustomRevisionListener.java b/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/audit/MyCustomRevisionListener.java index 79e3bf2..acd46aa 100644 --- a/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/audit/MyCustomRevisionListener.java +++ b/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/audit/MyCustomRevisionListener.java @@ -1,14 +1,18 @@ package de.spring.example.persistence.domain.audit; +import javax.inject.Inject; + import org.hibernate.envers.RevisionListener; import de.spring.example.context.UsernameThreadContext; public class MyCustomRevisionListener implements RevisionListener { - private final UsernameThreadContext userNameThreadContext; + @Inject + private UsernameThreadContext userNameThreadContext; + - public MyCustomRevisionListener(UsernameThreadContext userNameThreadContext) { - this.userNameThreadContext = userNameThreadContext; + protected MyCustomRevisionListener() { + } @Override diff --git a/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/audit/package-info.java b/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/audit/package-info.java new file mode 100644 index 0000000..137b183 --- /dev/null +++ b/SpringJava/JPA/spring-jpa-persistence/src/main/java/de/spring/example/persistence/domain/audit/package-info.java @@ -0,0 +1,6 @@ +@QueryEntities({DefaultRevisionEntity.class}) +package de.spring.example.persistence.domain.audit; + + +import org.hibernate.envers.DefaultRevisionEntity; +import com.querydsl.core.annotations.QueryEntities; \ No newline at end of file diff --git a/SpringJava/JPA/spring-jpa-persistence/src/main/resources/spring-configuration/liquibase/ddlChangelog.xml b/SpringJava/JPA/spring-jpa-persistence/src/main/resources/spring-configuration/liquibase/ddlChangelog.xml index e8fbd91..900271f 100644 --- a/SpringJava/JPA/spring-jpa-persistence/src/main/resources/spring-configuration/liquibase/ddlChangelog.xml +++ b/SpringJava/JPA/spring-jpa-persistence/src/main/resources/spring-configuration/liquibase/ddlChangelog.xml @@ -1,42 +1,48 @@ - - + + - - - - - + + + + + - + + + + - - + + - + - - + + - - + + - + + + + @@ -44,9 +50,9 @@ - + - + diff --git a/SpringJava/JPA/spring-jpa-persistence/src/main/resources/spring-configuration/liquibase/dmlChangelog.xml b/SpringJava/JPA/spring-jpa-persistence/src/main/resources/spring-configuration/liquibase/dmlChangelog.xml index 0f07094..8d10e3a 100644 --- a/SpringJava/JPA/spring-jpa-persistence/src/main/resources/spring-configuration/liquibase/dmlChangelog.xml +++ b/SpringJava/JPA/spring-jpa-persistence/src/main/resources/spring-configuration/liquibase/dmlChangelog.xml @@ -1,1960 +1,1960 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -- 2.1.4