Add rls-safe-mode module: Hibernate 8.0.0.CR2 HQL safe mode and PostgreSQL row-level security for @TenantId
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6ZEVHGaYy15HAxRzy
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
54c6d606ff
commit
1c9d9423c0
@@ -0,0 +1,38 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user