Hibernate inheritance

Stay organized with collections Save and categorize content based on your preferences.

Use hibernate inheritance and UUIDs to save a payment record in a database.

Code sample


To learn how to install and use the client library for Spanner, see Spanner client libraries.

import java.util.UUID;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import org.hibernate.annotations.Type;

 * An example {@link Entity} which demonstrates usage of {@link Inheritance}.
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Payment {

  @GeneratedValue(strategy = GenerationType.AUTO)
  @Type(type = "uuid-char")
  private UUID id;

  private Long amount;

  public UUID getId() {
    return id;

  public void setId(UUID id) {
    this.id = id;

  public Long getAmount() {
    return amount;

  public void setAmount(Long amount) {
    this.amount = amount;

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser.