Hibernate inheritance

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

Code sample

Java

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

To authenticate to Spanner, set up Application Default Credentials. For more information, see Set up authentication for a local development environment .

  import 
  
 jakarta.persistence.Entity 
 ; 
 import 
  
 jakarta.persistence.GeneratedValue 
 ; 
 import 
  
 jakarta.persistence.GenerationType 
 ; 
 import 
  
 jakarta.persistence.Id 
 ; 
 import 
  
 jakarta.persistence.Inheritance 
 ; 
 import 
  
 jakarta.persistence.InheritanceType 
 ; 
 import 
  
 java.util.UUID 
 ; 
 import 
  
 org.hibernate.annotations.JdbcTypeCode 
 ; 
 /** 
 * An example {@link Entity} which demonstrates usage of {@link Inheritance}. 
 */ 
 @Entity 
 @Inheritance 
 ( 
 strategy 
  
 = 
  
 InheritanceType 
 . 
 JOINED 
 ) 
 public 
  
 abstract 
  
 class 
 Payment 
  
 { 
  
 @Id 
  
 @GeneratedValue 
 ( 
 strategy 
  
 = 
  
 GenerationType 
 . 
 AUTO 
 ) 
  
 @JdbcTypeCode 
 ( 
 java 
 . 
 sql 
 . 
 Types 
 . 
 VARCHAR 
 ) 
  
 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 .

Design a Mobile Site
View Site in Mobile | Classic
Share by: