Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 7 additions & 15 deletions src/main/java/cat/udl/eps/softarch/demo/domain/Content.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,20 @@

import java.time.ZonedDateTime;

import com.fasterxml.jackson.annotation.JsonIdentityReference;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import lombok.Data;
import lombok.EqualsAndHashCode;

import jakarta.persistence.ManyToOne;
import com.fasterxml.jackson.annotation.JsonIdentityReference;
import java.util.List;



@Entity
@Data
//@EqualsAndHashCode(callSuper = true)
public class Content {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long contentId;

/*@ManyToOne
@JsonIdentityReference(alwaysAsId = true)
@Column(nullable = false)
private Project project;*/

@ManyToMany
@JoinTable(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to configure JoinTable or JoinColumn, use the defaults unless you are using a legacy database

name = "content_tags",
Expand All @@ -39,7 +27,10 @@ public class Content {
@ManyToOne
@JoinColumn(name = "user_id")

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed like JoinTable

private User user;


@OneToMany(mappedBy = "content", cascade = CascadeType.REMOVE, orphanRemoval = true)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid using the OneToMany side, just the ManyToOne. So, in reports, keep track of the Content corresponding to a Report. And for the reverse direction, use a findByContent in the Reports repository

private List<Report> reports;

@NotBlank(message = "Name cannot be empty")
@Column(unique = true, nullable = false)
private String name;
Expand All @@ -55,6 +46,7 @@ public class Content {

private ZonedDateTime modifiedAt;

@Enumerated(EnumType.STRING)
@Column(nullable = false) private Visibility visibility;
@Enumerated(EnumType.STRING)
@Column(nullable = false)
private Visibility visibility;
}