package com.ankurm.tenant; import jakarta.persistence.Column; import jakarta.persistence.Entity; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; import jakarta.persistence.Id; import jakarta.persistence.Table; import org.hibernate.annotations.TenantId; /** * A tenant-owned row. {@code @TenantId} makes Hibernate (1) add {@code tenant_id = ?} to every HQL * query and (2) in Hibernate 8, generate a PostgreSQL row-level-security policy on the table. */ @Entity @Table(name = "invoice") public class Invoice { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) public Long id; @TenantId @Column(name = "tenant_id", nullable = false) public String tenant; public String customer; public int cents; public Invoice() { } public Invoice(String customer, int cents) { this.customer = customer; this.cents = cents; } }