https://github.com/awslabs/aurora-dsql-hibernate
Aurora DSQL Dialect for Hibernate
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Academic email domains
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (10.6%) to scientific vocabulary
Keywords
Repository
Aurora DSQL Dialect for Hibernate
Basic Info
Statistics
- Stars: 3
- Watchers: 5
- Forks: 0
- Open Issues: 0
- Releases: 1
Topics
Metadata Files
README.md
Aurora DSQL Dialect for Hibernate
Introduction
The Aurora DSQL dialect for Hibernate provides integration between Hibernate ORM and Aurora DSQL. This dialect enables Java applications to leverage Hibernate's powerful object-relational mapping capabilities while taking advantage of Aurora DSQL's distributed architecture and high availability.
Sample Application
There is an included sample application in examples/pet-clinic-app that shows how to use Aurora DSQL with Hibernate. To run the included example please refer to the sample README.
Prerequisites
- Java 17 or higher
- Hibernate version 6.2 or higher
- A connection to an Amazon Aurora DSQL database
- PostgreSQL JDBC driver version 42.x or higher
Setup
A dialect for Aurora DSQL is used in largely the same way as other dialects for other databases. It is added as a dependency to your Maven or Gradle application:
```
// Maven
// Gradle implementation("software.amazon.dsql:aurora-dsql-hibernate-dialect:1.0.0") ```
With the aurora-dsql-hibernate-dialect JAR included in your Java application, the dialect can then be configured in a few ways:
- In a Hibernate.properties file: hibernate.dialect=software.amazon.dsql.hibernate.dialect.AuroraDSQLDialect
- In persistence.xml: <property name="hibernate.dialect" value="software.amazon.dsql.hibernate.dialect.AuroraDSQLDialect"/>
- In Spring application properties: spring.jpa.properties.hibernate.dialect=software.amazon.dsql.hibernate.dialect.AuroraDSQLDialect
- Programmatically using StandardServiceRegistryBuilder, the configuration API, or in a SessionFactory
Hibernate will not automatically detect the DSQL dialect based on metadata, it must be explicitly specified or else the PostgreSQLDialect will be used instead. With the dependency in place and the property set in Hibernate, the AuroraDSQLDialect will then automatically be used in DB interactions. Depending on your logging configuration, this may be verified in logs as connections are created.
See Hibernate documentation for more information on configuring your Hibernate application, including setting the dialect.
Database Connection
Configure your database connection for DSQL as follows:
properties
hibernate.connection.url=jdbc:postgresql://<cluster_endpoint>/postgres?sslMode=verify-full&sslNegotiation=direct
hibernate.connection.username=<username>
hibernate.connection.driver_class=org.postgresql.Driver
Best practices
Primary key generation
Hibernate supports various ways to generate primary keys for tables, but Hibernate applications using DSQL should use UUID as keys, generated by the database. Auto-incrementing integer keys using sequences or serial are not supported in DSQL. UUID key generation can be done in your entity definition as follows:
java
@Id
@GeneratedValue
@Column(name = "id", updatable = false, nullable = false, columnDefinition = "UUID DEFAULT gen_random_uuid()")
private UUID id;
Auto-DDL
Usage of an automatically generated schema with Hibernate is not recommended with DSQL. While it may be useful for experimental development or testing environments, it should not be used in production. An automatically generated schema can perform poorly, and can be destructive in unexpected ways.
Concurrency control and locking
Aurora DSQL uses optimistic concurrency control (OCC), where conflicts are presumed to be rare. Conflicts are only handled
when they occur, by allowing the first transaction to commit successfully, while any later transaction commit will result
in an error. This has largely the same effect as Hibernate's built in version-based OPTIMISTIC lock mode. Users should
therefore not use Hibernate's OPTIMISTIC lock mode, as DSQL will always trigger an OCC error prior to committing if
there is a conflict, rendering the version check unnecessary.
There are only two lock modes that should be used: NONE (which will still use standard DSQL OCC), and PESSIMISTIC_WRITE. Although DSQL will always use
optimistic locking, in Hibernate PESSIMISTIC_WRITE will add the SELECT ... FOR UPDATE modifier, which adds additional
read checks on selected rows, preventing commits if rows read are modified by another transaction. There are multiple
examples of how DSQL's concurrency control works available here in an AWS blog,
including with SELECT ... FOR UPDATE. DSQL does not support any other locking modes, and so only these two Hibernate
locking modes should be used.
Dialect Features and Limitations
Dialects provide syntax and supported features to allow the Hibernate ORM to correctly handle differences between databases. As Aurora DSQL is PostgreSQL-compatible and supports most PostgreSQL features, much of the dialect is similar to that of PostgreSQL. There are some key differences however that will help ensure a seamless developer experience with Hibernate and Aurora DSQL. The list below contains some of the key differences from the PostgreSQL dialect:
- Data types: The dialect provides correct
float,doubleandnumericprecision as well asvarcharsize limits. - Foreign Keys: Aurora DSQL does not support foreign key constraints. The dialect disables these constraints, but be aware that referential integrity must be maintained at the application level.
- Index creation: Aurora DSQL does not support
CREATE INDEXorCREATE UNIQUE INDEXcommands. The dialect instead usesCREATE INDEX ASYNCandCREATE UNIQUE INDEX ASYNCcommands. See the Asynchronous indexes in Aurora DSQL page for more information. - Locking: Aurora DSQL uses optimistic concurrency control (OCC) with support for
SELECT ... FOR UPDATE. The dialect supports these two locking methods. See the Concurrency control in Aurora DSQL page for more information. - Sequences: Aurora DSQL does not support sequence objects,
SERIALandIDENTITYcolumns, thus they are not supported by this dialect. For this reason, these data types are unsuitable for primary key generation with this dialect. See the Primary keys in Aurora DSQL page for more information. - Temporary tables: Aurora DSQL does not support temporary tables. The dialect will use standard tables instead. These tables will appear with
HT_orHTE_prefixes, and will be managed automatically by Hibernate. - Truncate command: Aurora DSQL does not support
TRUNCATEcommand. The dialect uses aDELETEcommand instead.
Developer instructions
Instructions on how to build and test the dialect are available in the Developer Instructions.
Security
See CONTRIBUTING for more information.
License
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1
Owner
- Name: Amazon Web Services - Labs
- Login: awslabs
- Kind: organization
- Location: Seattle, WA
- Website: http://amazon.com/aws/
- Repositories: 914
- Profile: https://github.com/awslabs
AWS Labs
GitHub Events
Total
- Watch event: 1
- Delete event: 2
- Member event: 1
- Push event: 4
- Public event: 1
- Pull request review event: 3
- Pull request event: 5
- Create event: 2
Last Year
- Watch event: 1
- Delete event: 2
- Member event: 1
- Push event: 4
- Public event: 1
- Pull request review event: 3
- Pull request event: 5
- Create event: 2
Issues and Pull Requests
Last synced: 5 months ago
All Time
- Total issues: 0
- Total pull requests: 5
- Average time to close issues: N/A
- Average time to close pull requests: 33 minutes
- Total issue authors: 0
- Total pull request authors: 2
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 3
Past Year
- Issues: 0
- Pull requests: 5
- Average time to close issues: N/A
- Average time to close pull requests: 33 minutes
- Issue authors: 0
- Pull request authors: 2
- Average comments per issue: 0
- Average comments per pull request: 0.0
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 3
Top Authors
Issue Authors
Pull Request Authors
- dependabot[bot] (3)
- mitchell-elholm (2)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- actions/checkout v4 composite
- gitleaks/gitleaks-action v1.6.0 composite
- actions/checkout v4 composite
- actions/setup-java v4 composite
- aws-actions/configure-aws-credentials v4 composite
- actions/checkout v4 composite
- actions/setup-java v4 composite
- postgres 17.0
- org.hibernate:hibernate-core 6.2.38.Final implementation
- org.apache.logging.log4j:log4j-core 2.20.0 testImplementation
- org.hibernate.orm:hibernate-ant 6.2.38.Final testImplementation
- org.junit.jupiter:junit-jupiter-api 5.9.2 testImplementation
- org.junit.jupiter:junit-jupiter-engine 5.9.2 testImplementation
- org.mockito:mockito-core 5.3.1 testImplementation
- org.postgresql:postgresql 42.7.2 testImplementation
- software.amazon.awssdk:aws-core 2.31.64 testImplementation
- software.amazon.awssdk:dsql 2.31.64 testImplementation
- software.amazon.awssdk:regions 2.31.64 testImplementation
- jakarta.xml.bind:jakarta.xml.bind-api * implementation
- javax.cache:cache-api * implementation
- org.hibernate:hibernate-core 6.6.13.Final implementation
- org.springframework.boot:spring-boot-starter-cache * implementation
- org.springframework.boot:spring-boot-starter-data-jpa * implementation
- org.springframework.boot:spring-boot-starter-thymeleaf * implementation
- org.springframework.boot:spring-boot-starter-validation * implementation
- org.springframework.boot:spring-boot-starter-web * implementation
- software.amazon.awssdk:dsql 2.31.33 implementation
- software.amazon.dsql:aurora-dsql-hibernate-dialect 1.0.0 implementation
- com.github.ben-manes.caffeine:caffeine * runtimeOnly
- com.h2database:h2 * runtimeOnly
- com.mysql:mysql-connector-j * runtimeOnly
- org.postgresql:postgresql * runtimeOnly
- org.springframework.boot:spring-boot-starter-actuator * runtimeOnly
- org.webjars.npm:bootstrap ${webjarsBootstrapVersion} runtimeOnly
- org.webjars.npm:font-awesome ${webjarsFontawesomeVersion} runtimeOnly
- org.springframework.boot:spring-boot-docker-compose * testImplementation
- org.springframework.boot:spring-boot-starter-test * testImplementation
- org.springframework.boot:spring-boot-testcontainers * testImplementation
- org.testcontainers:junit-jupiter * testImplementation
- org.testcontainers:mysql * testImplementation
- org.springframework.boot:spring-boot-devtools provided
- com.github.ben-manes.caffeine:caffeine
- com.h2database:h2
- jakarta.xml.bind:jakarta.xml.bind-api
- javax.cache:cache-api
- org.hibernate.validator:hibernate-validator
- org.hibernate:hibernate-core 6.6.13.Final
- org.postgresql:postgresql
- org.springframework.boot:spring-boot-starter-actuator
- org.springframework.boot:spring-boot-starter-cache
- org.springframework.boot:spring-boot-starter-data-jpa
- org.springframework.boot:spring-boot-starter-thymeleaf
- org.springframework.boot:spring-boot-starter-validation
- org.springframework.boot:spring-boot-starter-web
- org.webjars.npm:bootstrap 5.3.3
- org.webjars.npm:font-awesome 4.7.0
- software.amazon.awssdk:aws-core 2.31.39
- software.amazon.awssdk:aws-json-protocol 2.31.39
- software.amazon.awssdk:dsql 2.31.39
- software.amazon.awssdk:regions 2.31.39
- software.amazon.awssdk:sts 2.31.39
- software.amazon.awssdk:url-connection-client 2.31.39
- software.amazon.dsql:aurora-dsql-hibernate-dialect 1.0.0
- org.glassfish:jakarta.el 4.0.2 test
- org.springframework.boot:spring-boot-docker-compose test
- org.springframework.boot:spring-boot-starter-test test
- org.springframework.boot:spring-boot-testcontainers test
- org.testcontainers:junit-jupiter test