0

I have two entity classes - A and B. The template of the code is as follows:

class A extends class B  {
    // ...
}

@Entity
@Table("OPERATION")
@DiscriminatorValue()
@Access()
class B  {
    // ...
}

Class B has a schema defination in the .sql file. Class A does not have any schema defination.

My question is, doesn't class A need to have a schema definition in the .sql file as well, in order for it to be mapped to the relational database? I am confused on this and cannot understand how the mapping is taking place.

To use a more concrete example, I have the following two classes Operation and OperationAmend with their code as follows :

 @Entity
 @DiscriminatorValue()
 @Access()
 class OperationAmend extends Operation {   
     //some functions here for amending an operation
 }

 @Entity
 @Table("OPERATION")
 @DiscriminatorValue()
 @Access()
 class Operation  {   
     //some functions here for the operation.
 }

SQL Schema :

 CREATE TABLE OPERATION {    
     OperationId INT;    
     Name VARCHAR(20); 
 }

How can the OperationAmend class be saved even when it has no schema?

2
  • Related: JPA @Entity Inheritance Commented Jan 20, 2013 at 5:04
  • I use ibatis and inheritance mapping in ibatis is a bit different.. Commented Jan 20, 2013 at 10:42

1 Answer 1

0

In JPA, an entity only has to be declared in the persistence.xml (or scanned for by the provider) for it to be recognized. The provider generates a schema for it. Now, the implementation tables might not exist in the DB, but that's easy enough to fix.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.