title: Modeling a Chat object in spring boot JPA relationship onetomany correct?
body: <p>I have a chat object that has two users. It is not bidirectional. I can't figure out if it should be onetoone or onetomany</p>
  <p>In my head a user can have many chats, but they would over have one chat with both them and the second user.</p>
  <pre><code>
  import com.fasterxml.jackson.annotation.JsonProperty
  import org.hibernate.annotations.CreationTimestamp
  import org.hibernate.annotations.Type
  import org.hibernate.annotations.UpdateTimestamp
  import java.util.*
  import javax.persistence.*
  
  
  @Entity
  @Table(name = &quot;chats&quot;)
  data class Chat(
      @Id
      @Type(type = &quot;pg-uuid&quot;)
      val id: UUID = UUID.randomUUID()
  ) {
      @ManyToOne
      lateinit var user1: User
  
      @ManyToOne
      lateinit var user2: User
  
      @JsonProperty(&quot;created_at&quot;)
      @CreationTimestamp
      @Column(name = &quot;created_at&quot;, updatable = false)
      val createdAt: Date = Date()
  
      @JsonProperty(&quot;updated_at&quot;)
      @UpdateTimestamp
      @Column(name = &quot;updated_at&quot;)
      val updatedAt: Date = Date()
  
  }
  </code></pre>
  <p>Then in the repo can query a specific chat or user. OneToOne seems to work sometimes but I think if I start two chats it breaks down.</p>