#Comments / Replies Single Table

10 messages · Page 1 of 1 (latest)

eternal estuary
#

How should I handle replies to comments? As of right now, I have created a parent_id column in the comment table, but not entirely sure what the mapping would look like. Guessing it'll be a @tribal pikenyToOne annotation as there can be many replies to comment?

ebon pineBOT
#

This post has been reserved for your question.

Hey @eternal estuary! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

eternal estuary
#

I want to keep things relatively simple so how should I handle this if my goal is something like this:

#

I am retroactively trying to implement these replies into my application. This is what my comment entity looks like as of now:

#
package com.skilldistillery.lorehunter.entities;

import java.time.LocalDateTime;
import java.util.Objects;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;

import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
public class Comment {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private int id;
    
    private String content;
    
    @CreationTimestamp
    @Column(name = "created_at")
    private LocalDateTime createdAt;
    
    private String status;
    
    @UpdateTimestamp
    @Column(name = "last_edited")
    private LocalDateTime lastEdited;
    
    @ManyToOne
    @JoinColumn(name = "user_id")
    private User user;
    
    @JsonIgnore
    @ManyToOne
    @JoinColumn(name = "post_id")
    private Post post;
    
    private Boolean enabled;
    
    @Column(name = "parent_id")
    private int parentId;
ebon pineBOT
#

💤 Post marked as dormant

This post has been inactive for over 300 minutes, thus, it has been archived.
If your question was not answered yet, feel free to re-open this post or create a new one.

eternal estuary
#

Bump

viral forge
#

Yeah this looks correct. Only thing is that you don't need to explicitly list your join column if it follows standard naming conventions