hibernate中的实体和值类型 [英] Entity and value types in hibernate

查看:94
本文介绍了hibernate中的实体和值类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实体和值类型在对象级别上有什么区别。我知道实体将有一个ID,但价值不会但为什么我们需要不同的方式来映射实体与值类型?

What is the difference between entity and value types at the object level. I understand that entity will have an id but value won't but why do we need different ways to map entity vs value types?

是否这样做使得hibernate可以将任何优化应用于值类型?

Is it done so that hibernate can apply any optimization to value type?

推荐答案

一个实体已经定义了它的持久表。因此,当您在实体A中拥有B实体列表时,无需为Bs定义目标表:B已经定义它。值类型没有任何关联的表,因此实体A中的 List< String> 映射必须定义将使用哪个表来存储此列表。

An entity already defines the table where it's persisted. So when you have a list of B entities in an entity A, there is no need to define the target table for the Bs: B already defines it. Value types don't have any associated table, so the mapping of a List<String> in entity A must define which table will be used to store this list.

此外,按照定义,价值类型总是由其包含的实体完全拥有。一旦删除实体,您也删除与此实体关联的所有字符串。实体情况并非如此:当您删除课程实体时,您不会删除其所有学生。

Moreover, value types, by definition are always completely owned by their containing entity. Once you delete the entity, you also delete all the Strings associated to this entity. This is not the case with entities: when you delete a Course entity, you don't delete all its students.

这两个例子显示必须定义不同的映射属性。

These are just two examples showing that different mapping properties must be defined.

这篇关于hibernate中的实体和值类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆