1
我有一個像這樣的SQL查詢: "Select UIProfileID from UserTable where UPPER(UserID) = UPPER('?1')"
。如何將SQL查詢轉換爲Spring JPA查詢
我想將其轉換爲Spring JPA。 我想寫getUIProfileId()
並返回Integer。但我不知道如何實施。由於用戶表沒有UIProfileId
列,因此它已從UIProfileTable
表中加入。請幫我解決它。 目前,我有表:
User.java
@Entity
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Table(name = "UserTable")
public class User {
@Column(name = "UserID", length = 32, nullable = false)
@Id
private String name;
@ManyToOne
@JoinColumn(name = "DomainID", nullable = false)
private Domain domain;
@Column(name = "Password", length = 32, nullable = false)
private String password;
@ManyToOne
@JoinColumn(name = "UIProfileID", nullable = false)
private UIProfile uiProfile;
@Column(name = "ResPerpage", nullable = false)
private Integer resperpage;
@Column(name = "DefaultTab")
private Integer defaulttab;
@ManyToOne
@JoinColumn(name = "AdminProfile")
private AdminProfiles adminProfile;
@Column(name = "LanguageId")
private Integer languageId;
}
UIProfile.java
@Entity
@Getter
@Setter
@Table(name = "UIProfileTable")
public class UIProfile implements Serializable {
@Id
@Column(name = "UIProfileID", length = 11, nullable = false)
private Integer id;
@Column(name = "UIProfileName", length = 32, nullable = false)
private String name;
@OneToMany(mappedBy = "id.uiProfile")
private List<UIProfileTopLevel> topLevels;
}
UserRepository.java
public interface UserRepository extends Repository<User, String> {
Optional<User> findOne(String name);
@Query("Select UIProfileID from User where UPPER(UserID) = UPPER('admin')")
Integer getUIProfileId();
}
嗨,Ajit Soman。它將返回UIProfile對象,不能轉換爲java.lang.Integer –
@ Ajit Soman。我想獲得UIProfileTable @Column的ID(name =「UIProfileID」,長度= 11,可空= false) private Integer id ;. –
我已編輯我的答案 –