Multi -Mieter auf @manytoone Field

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Multi -Mieter auf @manytoone Field

by Guest » 08 Feb 2025, 07:16

In Hibernate wie man Mieterfilter auf Onetomany Feld zum Beispiel annehme

Code: Select all

@Entity
@Table(name = "\"user\"")
class User(
@Column(nullable = false)
@Id
@GeneratedValue(strategy = GenerationType.UUID)
var id: String? = null,

@Column(nullable = false, unique = true)
var userName: String,

@Column(nullable = false)
var email: String,

@Column(nullable = false, updatable = false)
@CreationTimestamp
var createdAt: Instant? = null,

@Column(nullable = false)
@UpdateTimestamp
var updatedAt: Instant? = null,

@OneToMany(mappedBy = "user", fetch = FetchType.EAGER, cascade = [CascadeType.ALL], orphanRemoval = true)
var userRoles: MutableList = mutableListOf(),
)
< /code>
@Entity
class UserRole(
@Column(nullable = false)
@Id
@GeneratedValue(strategy = GenerationType.UUID)
var id: String? = null,

@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
var user: User,

@ManyToOne
@JoinColumn(name = "role_id", nullable = false)
var role: Role,

@TenantId
@Column(name = "organization_id", nullable = false)
var organizationId: String? = null,

@Column(nullable = false, updatable = false)
@CreationTimestamp
var createdAt: Instant? = null,

@Column(nullable = false)
@UpdateTimestamp
var updatedAt: Instant? = null,
)

< /code>
@Entity
class Role(
@Column(nullable = false)
@Id
@GeneratedValue(strategy = GenerationType.UUID)
var id: String? = null,

@Column(nullable = false, unique = true)
var role: String,

@Column(nullable = false)
var description: String,

@Column(nullable = false, updatable = false)
@CreationTimestamp
var createdAt: Instant? = null,

@Column(nullable = false)
@UpdateTimestamp
var updatedAt: Instant? = null,

@OneToMany(mappedBy = "role", fetch = FetchType.EAGER, cascade = [CascadeType.ALL], orphanRemoval = true)
var rolePrivilege: MutableList = mutableListOf(),
)

In der obigen IT gibt alle UserRole für den Benutzer unabhängig von der Organisations -ID zurück, wenn ich byemail finde Es funktioniert für bestimmte Mieter -ID.

Top