JPA and PostgreSQL with GenerationType.IDENTITY

If you have a column of type SERIAL, it will be sufficient to annotate your id field with: @Id @GeneratedValue(strategy=GenerationType.IDENTITY) This is telling Hibernate that the database will be looking after the generation of the id column. How the database implements the auto-generation is vendor specific and can be considered “transparent” to Hibernate. Hibernate just … Read more

IllegalArgumentException: At least one JPA metamodel must be present

You have added <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> in your pom.xml. Spring boot will try automatically create an entity factory for JPA, but you do not have defined anything regarding JPA models. Try removing it in order to test what have you done so far. Afterwards you can check a tutorial using spring-data-starter-jpa like this guy

How to use Postgres JSONB datatype with JPA?

All the answers helped me to reach the final solution that is ready for JPA and not EclipseLink or Hibernate specifically. import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import java.io.IOException; import javax.json.Json; import javax.json.JsonObject; import javax.persistence.Converter; import org.postgresql.util.PGobject; @Converter(autoApply = true) public class JsonConverter implements javax.persistence.AttributeConverter<JsonObject, Object> { private static final long serialVersionUID = 1L; private static ObjectMapper … Read more

Multiple data source and schema creation in Spring Boot

spring.jpa.hibernate.ddl-auto=create has stopped working, not because you have two DataSources, but because your application’s creating its own LocalContainerEntityManagerFactoryBeans. This has the effect of disabling the auto-configuration of a LocalContainerEntityManagerFactoryBean so you now have to configure it yourself. You can configure the two entity managers to have different schema generation behaviour like this (the first’s doing … Read more

Does JPA support mapping to sql views?

While using the @Id annotation with fields of directly supported types is not the only way to specify an entity’s identity (see @IdClass with multiple @Id annotations or @EmbeddedId with @Embedded), the JPA specification requires a primary key for each entity. That said, you don’t need entities to use JPA with database views. As mapping … Read more

TransactionRequiredException Executing an update/delete query

I am not sure if this will help your situation (that is if it stills exists), however, after scouring the web for a similar issue. I was creating a native query from a persistence EntityManager to perform an update. Query query = entityManager.createNativeQuery(queryString); I was receiving the following error: caused by: javax.persistence.TransactionRequiredException: Executing an update/delete … Read more

LazyInitializationException in selectManyCheckbox on @ManyToMany(fetch=LAZY)

You need to fetch it while inside a transaction (thus, inside the service method), and not while outside a transaction (thus, inside e.g. JSF managed bean init/action method), that would thus throw a LazyInitializationException. So, your attempt hardware.getConnectivities().size(); has to take place inside a transaction. Create if necessary a new service method for the purpose … Read more