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

Hibernate (JPA) inheritance mapping of abstract super classes

Use: @Entity @Inheritance(strategy = InheritanceType.JOINED) AbstractLegalEntity In the database you will have one table for AbstractLegalEntity, and tables for classes, which extend AbstractLegalEntity class. You won’t have instances of AbstractLegalEntity if it’s abstract. Polymorphism can be used here. When you use: @MappedSuperclass AbstractLegalEntity @Entity ConcretePersonEntity extends AbstractLegalEntity This will create only one table in your … Read more

JPA @ElementCollection List specify join column name

Try this: @Entity public class Shirt implements Serializable { @Id @Size(max=9) private String id; @ElementCollection @CollectionTable( name = “SHIRT_COLORS”, joinColumns=@JoinColumn(name = “id”, referencedColumnName = “id”) ) @Column(name=”color”) private List<String> colors = new ArrayList<String>(); …

JPA: pattern for handling OptimisticLockException

If you get an optimistic locking exception, it means that some other transaction has committed changes to entities you were trying to update/delete. Since the other transaction has committed, retrying immediately might have a good chance to succeed. I would also make the method fail after N attempts, rather than waiting for a StackOverflowException to … Read more

Kotlin: Collection has neither generic type or OneToMany.targetEntity()

Have you tried changing var roles: Set<RoleType>? = null to var roles: MutableSet<RoleType>? = null If you have a look at the interface definition of Set, you’ll see it’s defined as public interface Set<out E> : Collection<E> whereas MutableSet is defined as public interface MutableSet<E> : Set<E>, MutableCollection<E> Set<out E> ‘s Java equivalent I believe … Read more

Postgres Sql `could not determine data type of parameter` by Hibernate

The PostgreSQL driver tries to figure out the type of the parameters to tell those parameters directly to the PostgreSQL Server. This is necessary that the PostgreSQL server is able to compare fields. In case of a java.sql.Timestamp the PostgreSQL driver is just not able to do it since there are two matching fields for … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)