Присоединение к нескольким созданным объектам JSON не имеет имен атрибутов.
PartnerSystem
@Entity
@Table(name = "partnersystem")
@NamedQueries({
@NamedQuery(name="PartnerSystem.findAllPartnerSystemByPartnerId",
query="SELECT new ps.idPartnerSystem, "
+ "ps.partnerIdPartner, ps.name, "
+ "e.name as env, s.name as system "
+ "FROM PartnerSystem ps "
+ "LEFT JOIN ps.partner p "
+ "LEFT JOIN ps.system s "
+ "LEFT JOIN s.environment e "
+ "WHERE ps.partnerIdPartner = :partnerIdPartner ")
})
public class PartnerSystem {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "idPartnerSystem")
private int idPartnerSystem;
..
@ManyToOne (cascade= {CascadeType.DETACH,CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH})
@JoinColumn(name = "partner_idPartner", insertable=false, updatable=false)
private Partner partner;
..
@ManyToOne (cascade= {CascadeType.DETACH,CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH})
@JoinColumn(name = "PartnerSystem_idSystem", insertable=false, updatable=false)
private System system;
}
Partner
@Entity
@Table(name = "partner")
public class Partner
{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "idPartner")
private int idPartner;
..
@JsonIgnore
@OneToMany(mappedBy="partner",
cascade= {CascadeType.DETACH,CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH})
private List<PartnerSystem> partnerSystems = new ArrayList<>();
..
}
Система
@Entity
@Table(name = "system")
public class System {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "idSystem")
private int idSystem;
@JsonIgnore
@OneToMany(mappedBy="system",
cascade= {CascadeType.DETACH,CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH})
private List<PartnerSystem> partnerSystems = new ArrayList<>();
@ManyToOne (cascade= {CascadeType.DETACH,CascadeType.MERGE,CascadeType.PERSIST,CascadeType.REFRESH})
@JoinColumn(name = "Environment_idEnvironment", insertable=false, updatable=false)
private Environment environment;
}
Репозиторий там метод репозитория именованного запроса возвращает List, поэтому логически предполагается, что он возвращает массив полей и значений.
@Repository
public interface PartnerSystemRepository
extends JpaRepository<PartnerSystem, Integer>{
public List<Object[]> findAllPartnerSystemByPartnerId(int partnerIdPartner);
}
выход :
[
[
1115,
459,
"CP US5-Generic",
"US Internal",
null,
19,
null,
"Dev",
"Generic"
],
[
1118,
459,
"CP US5-SAP",
"US Internal",
null,
21,
null,
"Dev",
"SAP"
]
]
Как получить JSON с именами атрибутов