11-15 06:12
Recent Posts
Recent Comments
๊ด€๋ฆฌ ๋ฉ”๋‰ด

miinsun

[JPA] ๋ณตํ•ฉํ‚ค ์„ค์ • ๋ณธ๋ฌธ

WebApp/Spring

[JPA] ๋ณตํ•ฉํ‚ค ์„ค์ •

miinsun 2022. 2. 4. 02:09

๐Ÿ“Œ JPA ๋ณตํ•ฉํ‚ค ์„ค์ •ํ•˜๋Š” ๋ฐฉ๋ฒ•

๋จผ์ € PK ํด๋ž˜์Šค๋ฅผ ๋งŒ๋“ค์–ด ์ค€๋‹ค.

@Data
class UserLikePlacePK implements Serializable{
	private String userId;
	
	private int placeId;	
}

 

๋งŒ๋“ค์–ด์ค€ PK ํด๋ž˜์Šค๋ฅผ JPA ๋„๋ฉ”์ธ ํด๋ž˜์Šค์— ์ ์šฉํ•ด์ค€๋‹ค.

@SuppressWarnings("serial")
@Entity
@Table(name="user_like_place")
@NoArgsConstructor
@AllArgsConstructor
@Getter
@Setter
@IdClass(UserLikePlacePK.class)
public class UserLikePlace implements Serializable{
	
	@Id
	@Column(name = "user_id")
	private String userId;
	
	@Id
	@Column(name = "place_id")
	private int placeId;
	
	@OneToOne
    @JoinColumn(name="place_id", insertable = false, updatable = false)
	private Place place;
	
	@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone="Asia/Seoul")
	@DateTimeFormat(pattern = "yyyy-MM-dd")
	@Transient
	private String time;
}

 

Comments