Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default Inheritance strategy in hibernate for a bean mapped to a database table?

This is my first query in stackoverflow and I think I am providing all my necessary inputs:

I have provided my Java bean and the database table details below:

******Java Bean Class:***

import java.sql.Timestamp;

import javax.persistence.Column;

import javax.persistence.Entity;

import javax.persistence.Id;

import javax.persistence.Table;

@Entity

@Table(name = "BANK_MESSAGES")

public class messagesBean implements Serializable

{

    @Id
    @Column(name="msg_id")
    private String msg_id;

    @Column(name="msg_date")
    Timestamp msgDateTime;

    @Column(name="message")
    private byte[] message;

    @Column(name="msg_type")
    private String msg_type;

    //Getters and Setters for the above fields
}

Below is the DDL for my Database Table (Oracle):

create table BANK_MESSAGES
(msg_id varchar2(10),
msg_date timestamp,
message blob,
msg_type varchar2(5)) ;

I am trying to understand what is the default Inheritance strategy in hibernate for a bean mapped to a database table like above ?

like image 404
developer Avatar asked Jul 31 '15 12:07

developer


1 Answers

If you just have one entity without any subclass, inheritance is irrelevant.

Otherwise, the javadoc has the answer:

Annotation Type Inheritance

@Target(value=TYPE)
@Retention(value=RUNTIME)
public @interface Inheritance

Defines the inheritance strategy to be used for an entity class hierarchy. It is specified on the entity class that is the root of the entity class hierarchy. If the Inheritance annotation is not specified or if no inheritance type is specified for an entity class hierarchy, the SINGLE_TABLE mapping strategy is used.

(emphasis mine).

like image 81
JB Nizet Avatar answered Nov 15 '22 08:11

JB Nizet