Мне нужно создать объект, который имеет все поля таблицы и что некоторая информация из другой таблицы вместе (не все).
@ Query ("ВЫБЕРИТЕ новый com.nowigo.systemsheet.User.User (U.id, U.name)
ОТ пользователя U INNER JOIN U.promoter P, где P.id =? 1 ") public
List findAllById (Long promoterId);
@ Query ("ВЫБЕРИТЕ U.id, U.name, P.name ОТ пользователя U INNER JOIN U.promoter P
где P.id =? 1 ")
Entity User
package com.nowigo.systemsheet.User;
import com.nowigo.systemsheet.base.BaseEntity;
import com.nowigo.systemsheet.Promoter.Promoter;
import java.io.Serializable;
import java.sql.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.springframework.format.annotation.DateTimeFormat;
@Entity
//@Inheritance(strategy = InheritanceType.JOINED)
public class User extends BaseEntity implements Serializable{
@ManyToOne
@JoinColumn(name = "promoter_id" )
private Promoter promoter;
private String name;
private String username;
private String password;
private String description;
@Column(name = "enabled", columnDefinition = "tinyint")
private Boolean enabled;
private Integer types;
private String permissions;
private Long restricted_event_id;
private Long restricted_cashlesscash_id;
private Long restricted_reseller_id;
@Column(name = "time_begin_reseller_bat", columnDefinition = "timestamp")
@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm:ss")
private Date time_begin_reseller_bat;
@Column(name = "time_end_reseller_bat", columnDefinition = "timestamp")
@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm:ss")
private Date time_end_reseller_bat;
@Column(name = "time_begin_reseller_individual", columnDefinition = "timestamp")
@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm:ss")
private Date time_begin_reseller_individual;
@Column(name = "time_end_reseller_individual", columnDefinition = "timestamp")
@DateTimeFormat(pattern = "dd/MM/yyyy HH:mm:ss")
private Date time_end_reseller_individual;
private Long img_id;
@Column(name = "can_make_return_operation", columnDefinition = "tinyint")
private Boolean can_make_return_operation;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public Long getRestricted_reseller_id() {
return restricted_reseller_id;
}
public void setRestricted_reseller_id(Long restricted_reseller_id) {
this.restricted_reseller_id = restricted_reseller_id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Boolean getEnabled() {
return enabled;
}
public void setEnabled(Boolean enabled) {
this.enabled = enabled;
}
public Integer getTypes() {
return types;
}
public void setTypes(Integer types) {
this.types = types;
}
public String getPermissions() {
return permissions;
}
public void setPermissions(String premissions) {
this.permissions = permissions;
}
public Long getRestricted_event_id() {
return restricted_event_id;
}
public void setRestricted_event_id(Long restricted_event_id) {
this.restricted_event_id = restricted_event_id;
}
public Long getRestricted_cashlesscash_id() {
return restricted_cashlesscash_id;
}
public void setRestricted_cashlesscash_id(Long restricted_cashlesscash_id) {
this.restricted_cashlesscash_id = restricted_cashlesscash_id;
}
public Long getRestricted_resellet_id() {
return restricted_reseller_id;
}
public void setRestricted_resellet_id(Long restricted_resellet_id) {
this.restricted_reseller_id = restricted_resellet_id;
}
public Date getTime_begin_reseller_bat() {
return time_begin_reseller_bat;
}
public void setTime_begin_reseller_bat(Date time_begin_reseller_bat) {
this.time_begin_reseller_bat = time_begin_reseller_bat;
}
public Date getTime_end_reseller_bat() {
return time_end_reseller_bat;
}
public void setTime_end_reseller_bat(Date time_end_reseller_bat) {
this.time_end_reseller_bat = time_end_reseller_bat;
}
public Date getTime_begin_reseller_individual() {
return time_begin_reseller_individual;
}
public void setTime_begin_reseller_individual(Date time_begin_reseller_individual) {
this.time_begin_reseller_individual = time_begin_reseller_individual;
}
public Date getTime_end_reseller_individual() {
return time_end_reseller_individual;
}
public void setTime_end_reseller_individual(Date time_end_reseller_individual) {
this.time_end_reseller_individual = time_end_reseller_individual;
}
public Long getImg_id() {
return img_id;
}
public void setImg_id(Long img_id) {
this.img_id = img_id;
}
public Boolean getCan_make_return_operation() {
return can_make_return_operation;
}
public void setCan_make_return_operation(Boolean can_make_return_operation) {
this.can_make_return_operation = can_make_return_operation;
}
public Boolean getCan_make_register_operation() {
return can_make_register_operation;
}
public void setCan_make_register_operation(Boolean can_make_register_operation) {
this.can_make_register_operation = can_make_register_operation;
}
@Column(name = "can_make_register_operation", columnDefinition = "tinyint")
private Boolean can_make_register_operation;
public Promoter getPromoter() {
return promoter;
}
public void setPromoter(Promoter promoter) {
this.promoter = promoter;
}
public User(String name) {
this.name = name;
this.getId();
}
public User() {
}
public User(Promoter promoter, String name, String username, String password, String description, Boolean enabled, Integer types, String permissions, Long restricted_event_id, Long restricted_cashlesscash_id, Long restricted_reseller_id, Date time_begin_reseller_bat, Date time_end_reseller_bat, Date time_begin_reseller_individual, Date time_end_reseller_individual, Long img_id, Boolean can_make_return_operation, Boolean can_make_register_operation) {
this.promoter = promoter;
this.name = name;
this.username = username;
this.password = password;
this.description = description;
this.enabled = enabled;
this.types = types;
this.permissions = permissions;
this.restricted_event_id = restricted_event_id;
this.restricted_cashlesscash_id = restricted_cashlesscash_id;
this.restricted_reseller_id = restricted_reseller_id;
this.time_begin_reseller_bat = time_begin_reseller_bat;
this.time_end_reseller_bat = time_end_reseller_bat;
this.time_begin_reseller_individual = time_begin_reseller_individual;
this.time_end_reseller_individual = time_end_reseller_individual;
this.img_id = img_id;
this.can_make_return_operation = can_make_return_operation;
this.can_make_register_operation = can_make_register_operation;
}
}
Промоутер организации
package com.nowigo.systemsheet.Promoter;
import com.nowigo.systemsheet.User.User;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.nowigo.systemsheet.base.BaseEntity;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.OneToMany;
@Entity
//@PrimaryKeyJoinColumn(name="user_id")
public class Promoter extends BaseEntity implements Serializable{
@OneToMany(mappedBy = "promoter", orphanRemoval = true)
@JsonIgnore
private List<User> user;
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
private String address;
private String address_number;
private String address_extra;
private String address_area;
private String city;
private String cnpx;
private String ierg;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getAddress_number() {
return address_number;
}
public void setAddress_number(String address_number) {
this.address_number = address_number;
}
public String getAddress_extra() {
return address_extra;
}
public void setAddress_extra(String address_extra) {
this.address_extra = address_extra;
}
public String getAddress_area() {
return address_area;
}
public void setAddress_area(String address_area) {
this.address_area = address_area;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public String getCnpx() {
return cnpx;
}
public void setCnpx(String cnpx) {
this.cnpx = cnpx;
}
public String getIerg() {
return ierg;
}
public void setIerg(String ierg) {
this.ierg = ierg;
}
public List<User> getUser() {
return user;
}
public void setUser(List<User> user) {
this.user = user;
}
public Promoter(String address) {
this.address = address;
}
public Promoter() {
}
public Promoter(List<User> user, String password, String address, String address_number, String address_extra, String address_area, String city, String cnpx, String ierg) {
this.user = user;
this.password = password;
this.address = address;
this.address_number = address_number;
this.address_extra = address_extra;
this.address_area = address_area;
this.city = city;
this.cnpx = cnpx;
this.ierg = ierg;
}
}
Репозиторий пользователя
package com.nowigo.systemsheet.User;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
public interface UserRepository extends JpaRepository<User, Long> {
public List<User> findByPromoterId(Long promoterId);
@Query(value = "SELECT U.id,U.name, P.address FROM sheetsystem.user U JOIN sheetsystem.promoter P ON U.promoter_id = P.id where P.id = ?1", nativeQuery = true)
public List<User> findAllById(Long promoterId);
}
Ожидаемое:
{
"id": 17,
"promoter": {
"id": 4,
"address": "Av. John Wick"
},
"name": "usuario",
"username": null,
"description": null,
"enabled": null,
"types": null,
"permissions": null,
"restricted_event_id": null,
"restricted_cashlesscash_id": null,
"restricted_reseller_id": null,
"time_begin_reseller_bat": null,
"time_end_reseller_bat": null,
"time_begin_reseller_individual": null,
"time_end_reseller_individual": null,
"img_id": null,
"can_make_return_operation": null,
"can_make_register_operation": null,
"restricted_resellet_id": null
}
Я получаю это:
Поле can_make_register_operation не найдено