40 lines
962 B
Java
40 lines
962 B
Java
package ru.mtusi.messenger.model;
|
|
|
|
import jakarta.persistence.*;
|
|
import lombok.*;
|
|
|
|
import java.time.Instant;
|
|
import java.time.temporal.ChronoUnit;
|
|
import java.util.UUID;
|
|
|
|
@Entity
|
|
@Table(name = "messages")
|
|
@Getter
|
|
@Setter
|
|
@NoArgsConstructor
|
|
public class Message {
|
|
|
|
@Id
|
|
@Column(nullable = false, updatable = false)
|
|
@GeneratedValue(strategy = GenerationType.UUID)
|
|
private UUID id;
|
|
|
|
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
|
@JoinColumn(name = "chat_id", nullable = false)
|
|
private Chat chat;
|
|
|
|
@ManyToOne(fetch = FetchType.LAZY, optional = false)
|
|
@JoinColumn(name = "sender_id", nullable = false)
|
|
private User sender;
|
|
|
|
@Column(nullable = false, length = 4000)
|
|
private String text;
|
|
|
|
@Column(name = "created_at", nullable = false, updatable = false)
|
|
private Instant createdAt;
|
|
|
|
@PrePersist
|
|
private void onCreate() {
|
|
this.createdAt = Instant.now().truncatedTo(ChronoUnit.MILLIS);
|
|
}
|
|
} |