Tag: Hibernate

Hibernate Discriminator-Based Multi-Tenancy (in Quarkus)

How Hibernate ORM applies tenant isolation when configured with the DISCRIMINATOR multi-tenancy approach. Working production code can be found in this repository: https://github.com/abstratium-dev/abstrauth. Configuration Set the kind of multi-tenancy to use n application.properties: quarkus.hibernate-orm.multitenant=DISCRIMINATOR An entity declares a tenant discriminator column using @TenantId: @Entity @Table(name = "T_oauth_clients") public class OAuthClient { @Id @Column(length = 36) private String id; @TenantId @Column(name = "org_id", length = 36) private String orgId; // other fields... } A TenantResolver provides the tenant ID for each request: @PersistenceUnitExtension @RequestScoped public class JwtOrgResolver implements TenantResolver { @Override public String resolveTenantId() { // E.g. extract orgId from the JWT Bearer token } } What Hibernate Does Automatically INSERT — org_id is auto-populated Java: em.persist(client); Generated SQL: insert into T_oauth_clients (allowed_scopes, auto_subscribe, client_id, client_name, client_type, created_at, org_id, redirect_uris, require_pkce, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) The org_id value is set automatically from the resolved tenant — you never set it in code. Tenant ID enforcement on persist Hibernate validates the @TenantId field before emitting the INSERT: Field is null — silently overwritten with the resolved tenant ID. Field differs from resolved tenant — PropertyValueException thrown during flush; no SQL is executed, e.g. PropertyValueException: assigned tenant id differs from current tenant id for entity dev.abstratium.abstrauth.entity.OAuthClient.orgId. em.find() — org_id filter added automatically (when hitting database) Java: em.clear(); // Clear persistence context to force DB round-trip OAuthClient found = em.find(OAuthClient.class, id); Generated SQL: select oc1_0.id, oc1_0.allowed_scopes, oc1_0.auto_subscribe, oc1_0.client_id, oc1_0.client_name, oc1_0.client_type, oc1_0.created_at, oc1_0.org_id, oc1_0.redirect_uris, oc1_0.require_pkce from T_oauth_clients oc1_0 where oc1_0.id = ? and oc1_0.org_id = ? Hibernate appends org_id = ? to the WHERE clause…

Read more

Enterprise GWT: Combining Google Web Toolkit, Spring and Other Features to Build Enterprise Applications

The following is just the introduction taken from a new white paper available at www.maxant.ch/white-papers: Google Web Toolkit (GWT) provides developers with a powerful means of developing AJAX front ends without the worry of having to maintain complex Java script libraries to support multiple browsers and browser versions. GWT also provides support for Remote Procedure Calls (RPC) to the server. Since April 2009 the Google App Engine has existed, which allows developers to deploy their GWT applications and also provides support for Java Data Objects (JDO) and the Java Persistence API (JPA). However what is missing for GWT to be deployed to a modern Enterprise environment is a service framework providing dependency injection and inversion of control (IoC), transaction demarcation and security, such as that provided by Spring or Enterprise Java Beans (EJB) 3.0. Furthermore GWT does not define any patterns for User Interface designs, or composite widgets. This paper describes how to successfully integrate Spring into a GWT Application with the aim of creating a fully scalable development framework for deployment in the Enterprise and beyond (including simple and small applications), with very little start up time being required, because you can download the demo application. It includes UI Patterns and composite widgets to improve the development of the front end. This GWT Demo Application is live at http://gwtdemo.maxant.co.uk and is available for download at https://www.maxant.ch/white-papers (c) 2010 Ant Kutschera

Read more