This is similar to JPA mapping views and tables with inheritance but since accepted answer does not satisfy me I decided to ask my own question.
I have one based class that holds common fields for all entities
@MappedSuperclass
@Access(AccessType.FIELD)
public abstract class CommonFields{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long id;
(...)
}
Lets say I have one entity called Table
@Entity
@Table(name = "my_table")
public class Table extends CommonFields{
(..)
}
This works perfectly for me. I created view, which adds one column to my_table
. I mapped it this way:
@Immutable
@Entity
@Table(name = "my_table_plus_view")
public class TableView extends Table{
(..)
}
TableView
is read_only. This is simple Table
with additional informations for presentation purposes.
This application runs on Tomcat and Postgres DB. Server starts whithout errors but when I try to get all records from view I got an error that my Table
does not contain DTYPE
column. I know what it is and how it works but since I don't need it I don't want it.
I want read/write my Table
just like now but I don't know how to map my TableView
so JPA query can use it. I did some efforts whith InheritanceType
but with no success. If I copy all fields from Table
to TableView
then my application will run just as expected but this this doesn't suit me. How can I map my view so I can use inheritance?