Initialise H2GIS with Spring Boot JPA

TL;DR spring: jpa: generate-ddl: true properties: javax: persistence: schema-generation: database: action: drop-and-create create-source: script-then-metadata create-script-source: init.sql init.sql CREATE ALIAS IF NOT EXISTS H2GIS_SPATIAL FOR "org.h2gis.functions.factory.H2GISFunctions.load"; CALL H2GIS_SPATIAL(); CREATE DOMAIN POINT AS GEOMETRY(POINT); CREATE DOMAIN POLYGON AS GEOMETRY(POLYGON);

August 11, 2023 · Nigel Sim

Liquibase + Hibernate 5 + Envers + Spring Boot Naming Conventions

Starting with a project using Spring Boot 1.5.8 and Hibernate 5.2.12 I implemented Liquibase to handle database schema changes. This is all straight forward enough, with plenty of other tutorials of how to setup the runtime side. The schema diff generation side was another matter. The issues hit was that the identifier names were not correct - Spring Boot would produce underscore versions of names, e.g., my_table, while Liquibase would produce names as per the class or field name, e.g., MyTable. To get around this I could specify the actual table or column names in the @Table or @Column annotations. However, this was not going to work when we put Envers into the mix. ...

March 15, 2018 · Nigel Sim

Some thoughts on a dynamic (lazy) data access layer for web services

The problem I’ve been address in my most recent work block has been to develop an interface to a relational data store which can be used either as a local DB, or via webservices. The concept is quite straight forward, we want CRUD operations on a set of data objects. The schema is fairly straight forward too, with a core hierarchy of elements with a few enumerated lists. As well as a few cuts across the hierarchy. ...

April 3, 2008 · Nigel Sim

ManyToOne reference loading with JPA/Hibernate

In this example an InvestigationType has many SampleType’s. If I load an InvestigationType via em (entity manager) find it also loads the samples. InvestigationType inv2 = (InvestigationType) em.find( InvestigationType.class, inv.getId()); System.out.println(“Inv2 ID="+inv2.getId()); System.out.println(“Inv2 Title="+inv2.getTitle()); assertTrue(inv2.getSample().size() == 2); However, if I load a SampleType the investigation field is null, unless I refresh the object. // Get a sample SampleType s3 = (SampleType) em.find( SampleType.class, inv2.getSample().get(0).getId()); em.refresh(s3); System.out.println(convertDataToXmlString(s3)); InvestigationType inv3 = s3.getInvestigation(); assertNotNull(inv3); From my understanding I should not have to do this as the fetching should be the same in both instances, ie resolving the parent by default. Similarly, if I query for both objects the references are correctly loaded. ...

January 8, 2008 · Nigel Sim