简体   繁体   English

我应该使用mySQL表视图还是Spring Data JPA投影?

[英]Should I use mySQL Table Views or Spring Data JPA projections?

I have a mySQL relational database with football statistics that contains a table matches. 我有一个带橄榄球统计信息的mySQL关系数据库,其中包含一个表匹配项。 I created a method in my Spring project to build a standings table. 我在Spring项目中创建了一个方法来构建排行榜。 This method uses a projection because I need each match object to include the two team objects. 此方法使用投影,因为我需要每个比赛对象都包括两个团队对象。 This response (get all matches + get the two teams in each match) takes around 7 seconds. 此响应(获取所有比赛+在每场比赛中获得两支球队)大约需要7秒钟。

The same information but within a View in my database takes 0.231 seconds. 相同的信息但是在我数据库的视图中需要0.231秒。

I'm very new to Spring Data so my question is. 我是Spring Data的新手,所以我的问题是。 Should I use table views when I need to join tables? 需要联接表时应该使用表视图吗? Is there any advice against doing so? 是否有反对这样做的建议?

I don't see any problem with using table views. 使用表格视图没有任何问题。 You can map to them with JPA @Table annotation. 您可以使用JPA @Table注释映射到它们。

The only potential problem is when migrating databases (you will have to make sure Views are migrated correctly). 唯一的潜在问题是在迁移数据库时(您必须确保正确迁移了View)。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM