简体   繁体   English

JPA Hibernate - 导致具有多对多关联的非实体

[英]JPA Hibernate - Results in Non Entity with many-to-many assoctiation

I have an entities:我有一个实体:

  1. Player播放器
  2. Team团队

There is many-to-many association between Player and Team. Player 和 Team 之间存在多对多关联。

Player and Team entities are big so we want to fetch all Player entities in lightweight Pojo with only few attributes. Player 和 Team 实体很大,所以我们想在轻量级 Pojo 中获取所有 Player 实体,只有很少的属性。 But we need team info too.但我们也需要团队信息。

USE CASE display all players (for example 1500 players) in table with following info用例在表格中显示所有玩家(例如 1500 名玩家),并提供以下信息

Player name |球员姓名 | Player surname |球员姓氏 | Teams团队

This is code we use now:这是我们现在使用的代码:

                "SELECT new pojos.PlayerPojo(e.id, e.firstName, e.lastName, t.id, t.name) " +
                        "FROM Player e LEFT JOIN e.teams t");

Problem with this query is that we get multiple rows if player has multiple teams, then we need to iterate through all entities and join them in Java, which is performance issue.这个查询的问题是,如果玩家有多个团队,我们会得到多行,然后我们需要遍历所有实体并在 Java 中加入它们,这是性能问题。 We want to have snappy app.我们想要有活泼的应用程序。 We cannot use Entity class as it is too big and we have performance issues and memory issues (we are limited with our cloud plans)我们不能使用实体类,因为它太大了,而且我们有性能问题和内存问题(我们的云计划有限)

maybe you could provide two Entity that keep the require fields, and put the ManyToOne/OneToMany annotation in these entity class so you can enjoy all the features in hibernate Conveniently without write hsql.也许你可以提供两个保留require字段的实体,并在这些实体类中放置ManyToOne/OneToMany注解,这样你就可以在不编写hsql的情况下方便地享受hibernate中的所有功能。

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

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