From 28add09c7be01a237c3c8ec061a9ffbcd23db3ed Mon Sep 17 00:00:00 2001 From: kirillius Date: Wed, 21 Aug 2024 14:21:02 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D1=80=D0=B8=D0=BC=D0=B5=D1=80=D1=8B=20=D1=87=D0=B0=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D0=B8=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D1=83?= =?UTF-8?q?=D0=B5=D0=BC=D1=8B=D1=85=20=D1=88=D1=82=D1=83=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/README.md b/README.md index 425b962..dbdd5ae 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,85 @@ # JPA-examples +### Entity annotation + +```java + +@Entity +@Table +public final class MyEntityClass { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + @Column + private float primitiveField; + + @Column + private String primitiveField2; + +} +``` + +### References to another entities + +```java + +@Entity +@Table +public final class AnotherEntity { + //... + @ManyToMany(fetch = FetchType.EAGER) + @JoinColumn(name = "my_entity_id", nullable = false) + private Collection entities; +} +``` + +### Collection of primitives + +```java +//... +public final class AnotherEntity { + //... + @ElementCollection(fetch = FetchType.EAGER) + private Set stringSet; +} + +``` + +### Map field as another data type + +```java + +//... +public final class AnotherEntity { + //... + @Column + @JSONProperty + @Convert(converter = CustomConverter.class) + private CustomType settings; +} + +public class CustomType { + //... +} + +/* + Convert custom type to string and vise versa + */ +@Converter +public static class CustomConverter implements AttributeConverter { + + @Override + public String convertToDatabaseColumn(CustomType customType) { + // return ... + } + + @Override + public CustomType convertToEntityAttribute(String dbData) { + // return ... + } +} + + + +``` \ No newline at end of file