filmov
tv
Hibernate Tip : How to map multiple entities to the same table
![preview_player](https://i.ytimg.com/vi/RxE9nU285nM/maxresdefault.jpg)
Показать описание
One of the readers of my blog asked me this question: Some of our entities have a lot of attributes and we don’t need all of them in all use cases. Can I create a second entity that only maps a subset of the most commonly used attributes? Is there anything I should consider?
Yes, you can map two or more entities to the same database table. If you want to map the same database table to two entities, you should create a simple inheritance hierarchy. The superclass, in this example a class called AbstractAuthor, should be abstract and contain all attributes that are shared by both entities. You should map it as a mapped superclass so that it is not an entity itself.
If you like this video, please give me your thumbs up and share it with your friends and co-workers.
Like my channel? Subscribe!
Join the free Member Library:
Want to connect with me?
#Hibernate #JPA #HibernateTips
Hibernate Tip : How to create and initialize a database
Hibernate Tip: How To Map an Entity to a Query
Hibernate Tip: How to use a custom database sequence
Hibernate Tip - How to bootstrap Hibernate with Spring Boot
Hibernate Tips ‘n’ Tricks - 15 Tips to solve common problems by Thorben Janssen
Hibernate Tip : How to avoid MultipleBagFetchException
Hibernate Tip: How to map the latest element of an association
Hibernate Tip: How to map a java.util.Date
Hibernate Tip: How to map an entity attribute to an Optional
Hibernate Tip: How to define schema and table names
Hibernate Tip: How to use the QueryCache to avoid additional queries
Hibernate Tip: How to access Hibernate APIs from JPA
Hibernate Tip: How to order associated entities without writing a custom query
Hibernate Tip: How to create a database setup script based on entity mappings
Hibernate Tip: How to integrate an external query builder
Hibernate Tip - How to map an association to a java.util.Map
Hibernate Tip: How to initialize lazy relationships within a query
Hibernate Tip: How to automatically set an attribute before persisting it
Hibernate Tip: How to map native query results to managed entities
Hibernate Tip: How to persist a List of Strings as an ElementCollection
Hibernate Tips: How to use Hibernate's native bootstrapping API
Hibernate Tip: How to automatically validate entity attributes
Hibernate Tip - How to use pagination with JPQL
Hibernate Tip: How to Call a Stored Procedure
Комментарии