DevOps Articles

Curated articles, resources, tips and trends from the DevOps World.

How to Obtain Auto-Generated Keys With Hibernate

4 years ago dzone.com
How to Obtain Auto-Generated Keys With Hibernate

Summary: This is a summary of an article originally published by the source. Read the full original article here →

by Consider the following Author entity that delegates the keys generation to the database system: Now, let's see how to retrieve the database auto-generated primary keys via getId(), JdbcTemplate and SimpleJdbcInsert. In JPA style, retrieving the auto-generated keys can be done via getId() as in the following example: Using JdbcTemplate to retrieve the auto-generated keys can be done via the update() method.

The KeyHolder object contains the auto-generated key returned by the update() method. In code lines: In the above example, the PreparedStatement is instructed to return the auto-generated keys via Statement.RETURN_GENERATED_KEYS.

Made with pure grit © 2024 Jetpack Labs Inc. All rights reserved. www.jetpacklabs.com