@embedded注释有什么影响? [英] What impact does the @embedded annotation mean?

查看:103
本文介绍了@embedded注释有什么影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嵌入式注释如何影响数据库?

How does the Embedded annotation affect the database?

如何更改SQL查询?

使用注释的典型用例是什么?

What's the typical usecase for using the annotation?

推荐答案

嵌入式注释如何影响数据库?

How does Embedded annotation affect the database?

它根本不影响它.在ORM提供程序层上,将嵌入式实体中的所有字段与父实体合并,并像对待它们始终在其中声明一样.换句话说,它就像您将所有字段,获取器和设置器直接复制到包含嵌入式对象的实体中一样.

It does not affect it at all. On ORM provider layer all fields from embedded entity are merged with parent entity and treated the same as if they were declared there all the time. In other words it works as if you would literally copy all the fields, getters and setters into the entity that contains embedded object.

如何更改SQL查询?

How will SQL queries need to change?

他们不会.您无需更改任何内容.见上文.

They won't. You don't need to change anything. See above.

使用注释注释的典型情况是什么?

What's the typical case for using the annotation annotation?

有时候您有一个巨大的表,其中包含几列(尤其是旧数据库).但是,某些列在逻辑上是相互关联的(例如CUSTOMER表中的街道,城市和电话号码).当您不想创建包含所有字段的对象时,可以创建一个嵌入的Address对象.这样一来,您就可以将地址列合理地分组为一个对象,而不是使用同样大小的字段具有同样大的POJO.

Sometimes you have a huge table with several columns (especially with legacy databases). However some columns are logically tied to each other (like street, city and phone number in CUSTOMER table). When you don't want to create an object with all the fields, you create an embedded Address object. This way you logically group address columns into an object instead of having equally huge POJO with a flat list of fields.

使用嵌入式对象被认为是一种好习惯,特别是当发现牢固的1-1关系时.

Using embedded objects is considered a good practice, especially when strong 1-1 relationship is discovered.

这篇关于@embedded注释有什么影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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