Alex
Explore posts from serversJCHJava Community | Help. Code. Learn.
•Created by Alex on 9/30/2024 in #java-help
jpa and postgresql
entity
package org.example.demo.domain.entity;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.HashMap;
import java.util.Map;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Entity
@Table(name = "companies")
public class Company implements EntityBase<Integer> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(nullable = false, unique = true)
private String name;
// @Builder.Default
// @ElementCollection
// @CollectionTable(name = "company_locales", joinColumns = @JoinColumn(name = "company_id"))
// @MapKeyColumn(name = "lang")
// @Column(name = "description")
// private Map<String,String> locales = new HashMap<>();
}
package org.example.demo.domain.entity;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.HashMap;
import java.util.Map;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@Entity
@Table(name = "companies")
public class Company implements EntityBase<Integer> {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
@Column(nullable = false, unique = true)
private String name;
// @Builder.Default
// @ElementCollection
// @CollectionTable(name = "company_locales", joinColumns = @JoinColumn(name = "company_id"))
// @MapKeyColumn(name = "lang")
// @Column(name = "description")
// private Map<String,String> locales = new HashMap<>();
}
import java.io.Serializable;
public interface EntityBase<T extends Serializable> {
public void setId(T id);
public T getId();
}
import java.io.Serializable;
public interface EntityBase<T extends Serializable> {
public void setId(T id);
public T getId();
}
5 replies