liquibasechangelogjpa-buddy

How to generate SDO_GEOMETRY for geolatte Geometry with JPA Buddy


I am using JPA Buddy to generate Liquibase changelog from a JPA-annotated Entity in Kotlin.

My model looks something like this:

@Entity
class MyEntity(
  @Id
  val id: Long,

  val someField: String,

  @Type(JsonBlobType::class)
  val someStruct: SomeClass,

  val geometry: Geometry<*>,
)

When I use the Liquibase init generation, all fields are generated except the geometry field. I have tried adding a mapping in jpb-settings.xml:

          <mapping-type sql-type-parameter="Nothing">
            <java-class>org.geolatte.geom.Geometry</java-class>
            <sql-type>MDSYS.SDO_GEOMETRY</sql-type>
          </mapping-type>

But this has no effect.

How can I make JPA Buddy generate a Liquibase changelog that includes geometry fields?


Solution

  • One way to make JPA Buddy pay attention to the type you want is to use the @Column annotation along with the columnDefinition attribute. For example, this column declaration worked for me.

    import jakarta.persistence.*
    import org.geolatte.geom.Geometry
    import org.geolatte.geom.Position
    
    @Entity
    @Table(name = "my_entity")
    open class MyEntity {
        @Id
        @GeneratedValue(strategy = GenerationType.IDENTITY)
        @Column(name = "id", nullable = false)
        open var id: Long? = null
    
        @Column(name = "geometry", columnDefinition = "MDSYS.SDO_GEOMETRY")
        open var geometry: Geometry<*>? = null
    }
    
    <databaseChangeLog
            xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
                                            http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-4.19.xsd"
            objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
    
        <changeSet id="1685444752395-1"
                   author="vlasov (generated)">
            <createTable tableName="my_entity">
                <column autoIncrement="true"
                        name="id"
                        type="BIGINT">
                    <constraints nullable="false"
                                 primaryKey="true"
                                 primaryKeyName="pk_my_entity"/>
                </column>
                <column name="geometry"
                        type="MDSYS.SDO_GEOMETRY"/>
            </createTable>
        </changeSet>
    
    </databaseChangeLog>