为什么我们在Hibernate中使用@Embeddable [英] Why do we use @Embeddable In Hibernate
问题描述
在Hibernate中有什么用 @Embedded
和 @Embeddable
因为我在互联网上找到的每个例子都是在单个表格中插入数据,并使用两个不同的类来完成。我的观点是如果我使用单个表格,那么我可以映射单个类中的所有列,那么为什么我应该使用不同的类。如果我们使用两个不同的表,那么一对一
和一对多
hibernate关系。
Hibernate中有两种类型的对象
1. Value对象
2.实体
值对象是不能单独存在的对象。例如,以地址
为例。如果你说地址,人们会问这是谁的地址。所以它不能孤立无援。
实体对象是那些像 所以在值对象的情况下,首选的方法是将它们嵌入到实体对象中。 为了回答我们为什么要创建两个不同的类:首先,它是一个OOPS概念,您应该在类之间有松耦合和高内聚性。这意味着您应该只为专门用途创建类。例如,您的 第二点是通过创建不同的类来提高可重用性。 当我们为实体类定义值对象时, What's the use of There are two types of objects in Hibernate Value Objects are the objects which can not stand alone. Take Entity Objects are those who can stand alone like So in case of value objects preferred way is to Embed them into an entity object. To answer why we are creating two different classes: first of all, it's a OOPS concept that you should have loose coupling and high cohesion among classes. That means you should create classes for specialized purpose only. For example, your Second point is that by creating different classes you promote re-usability. When we define the value object for the entity class we use 这篇关于为什么我们在Hibernate中使用@Embeddable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! College c>和
学生
。
Student
类应只有与 Student
相关的信息。
@Embeddable
。
当我们在实体类中使用值类型对象时,我们使用 @Embedded
@Embedded
and @Embeddable
In Hibernate ? Because every example i found on internet is inserting data inside of a single table and to do that using two different class. My point is if I am using a single table then I can map all the columns inside of a single class then why should i use different class. and if We use two different table then there is one-to-one
and one-to-many
hibernate relationship.
1. Value Object
2. EntitiesAddress
, for example. If you say address, people will ask whose address is this. So it can not stand alone.College
and Student
. Student
class should only have the info related to Student
.@Embeddable
.
When we use value type object in entity class we use @Embedded