Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Map of Objects using ElementCollection (hacked)

Using Jpa Converters, it is possible to convert Object class to binary array. In this scenario JpaExampleEmd class is not entity and neither embedded.

Code Block
languagejava
titleJpaExampleObjMapEc
collapsetrue
@Data
public class JpaExampleEmd implements Serializable {

    private static final long serialVersionUID = 1L;

    @VerifyKey
    @NotNull
    private ExampleKey key;

    private Boolean primed;

    @NotNull
    private Date timeStamp;
}

@Converter(autoApply = true)
public class ExampleConverter implements AttributeConverter<JpaExampleEmd, byte[]> {

    @Override
    public byte[] convertToDatabaseColumn(JpaExampleEmd attribute) {
        return SerializationUtils.serialize(attribute);
    }

    @Override
    public JpaExampleEmd convertToEntityAttribute(byte[] dbData) {
        return (JpaExampleEmd) SerializationUtils.deserialize(dbData);
    }

}

@Entity
@Table(name = "ExampleObjMapEc")
@Data
public class JpaExampleObjMapEc implements Serializable {

    private static final long serialVersionUID = 1L;

    @EmbeddedId
    @VerifyKey
    @NotNull
    private ExampleKey key;

    @ElementCollection
    @Lob
    private Map<@NotNull String, @NotNull JpaExampleEmd> examples;
}

...

  • Move to Hibernate with EclipseLink tables is possible using Jpa Converters.
  • The presence of longblob types used to store whole objects is an issues, it is readable only by Java language or by any other language compatible with Java binary code. I am not sure if a db-migrator can handle that.
  • Document databases store all information for a given object in a single instance in the database, and every stored object can be different from every other. So, using MongoDB/Cassandra will solve all issues. JpaRepository and MongoRepository extend CrudRepository and expose the capabilities of the underlying persistence technology in addition to the rather generic persistence technology-agnostic interfaces like e.g. CrudRepository.

...