- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有两个表,即具有 join 的用户和组织。我必须编写一个方法,该方法将根据包含输入字符串的组织名称向用户提供信息。
User.java
@Entity
@Table(name = "USERS")
@EntityListeners(UsersEntityListener.class)
@NamedQueries({
@NamedQuery(name = "User.findAll", query = "SELECT u FROM User u")})
public class User extends Domain implements Serializable {
private static final long serialVersionUID = 1L;
@Basic(optional = false)
@Column(name = "FIRST_NAME", nullable = false)
private String firstName;
@Basic(optional = false)
@Column(name = "LAST_NAME", nullable = false)
private String lastName;
@Column(name = "MIDDLE_NAME")
private String middleName;
@Basic(optional = false)
@Column(name = "GENDER", nullable = false)
private String gender;
@Basic(optional = false)
@Column(name = "MOBILE", nullable = false)
private String mobile;
@Basic(optional = false)
@Column(name = "EMAIL", nullable = false)
private String email;
@Basic(optional = false)
@Column(name = "USERNAME", nullable = false)
private String username;
@Basic(optional = false)
@Column(name = "PASSWORD", nullable = false)
private String password;
@Column(name = "URL")
private String url;
@PrePersist
public void encryptPassword(){
this.setPassword(new BCryptPasswordEncoder().encode(getPassword()));
}
@OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
private List<UserRole> userRoles;
@OneToOne(cascade = CascadeType.ALL, mappedBy = "user")
private Organization organization;
public User() {
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getMiddleName() {
return middleName;
}
public void setMiddleName(String middleName) {
this.middleName = middleName;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
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 String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public Organization getOrganization() {
return organization;
}
public void setOrganization(Organization organization) {
this.organization = organization;
}
public List<UserRole> getUserRoles() {
return userRoles;
}
public void setUserRoles(List<UserRole> userRoles) {
this.userRoles = userRoles;
}
}
组织.java
@Entity
@Table(name = "ORGANIZATIONS", uniqueConstraints = {
@UniqueConstraint(columnNames = {"USER_ID"})})
@NamedQueries({
@NamedQuery(name = "Organization.findAll", query = "SELECT o FROM Organization o")})
public class Organization extends Domain implements Serializable {
private static final long serialVersionUID = 1L;
@Basic(optional = false)
@Column(name = "ORGANIZATION", nullable = false, length = 256)
private String organization;
@Column(name = "WEBSITE")
private String website;
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
@OneToMany(cascade = CascadeType.ALL, mappedBy = "organization")
private List<Location> locations;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "senderOrganization")
private List<PurchaseOrder> sendPurchaseOrders;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "receiverOrganization")
private List<PurchaseOrder> receivedPurchaseOrders;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "organization")
private List<Purchaser> purchasing;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "senderOrganization")
private List<Quotation> sendQuotations;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "receiverOrganization")
private List<Quotation> receivedQuotations;
@JoinColumn(name = "USER_ID", referencedColumnName = "ID", nullable = false)
@OneToOne(optional = false)
private User user;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "senderOrganization")
private List<Enquiry> sendEnquiries;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "receiverOrganization")
private List<Enquiry> receivedEnquiries;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "organization")
private List<Supplier> supplying;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "senderOrganization")
private List<Invoice> sendInvoices;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "receiverOrganization")
private List<Invoice> receivedInvoices;
public Organization() {
}
public String getOrganization() {
return organization;
}
public void setOrganization(String organization) {
this.organization = organization;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
public List<Location> getLocations() {
return locations;
}
public void setLocations(List<Location> locations) {
this.locations = locations;
}
public List<PurchaseOrder> getSendPurchaseOrders() {
return sendPurchaseOrders;
}
public void setSendPurchaseOrders(List<PurchaseOrder> sendPurchaseOrders) {
this.sendPurchaseOrders = sendPurchaseOrders;
}
public List<PurchaseOrder> getReceivedPurchaseOrders() {
return receivedPurchaseOrders;
}
public void setReceivedPurchaseOrders(List<PurchaseOrder> receivedPurchaseOrders) {
this.receivedPurchaseOrders = receivedPurchaseOrders;
}
public List<Purchaser> getPurchasing() {
return purchasing;
}
public void setPurchasing(List<Purchaser> purchasing) {
this.purchasing = purchasing;
}
public List<Quotation> getSendQuotations() {
return sendQuotations;
}
public void setSendQuotations(List<Quotation> sendQuotations) {
this.sendQuotations = sendQuotations;
}
public List<Quotation> getReceivedQuotations() {
return receivedQuotations;
}
public void setReceivedQuotations(List<Quotation> receivedQuotations) {
this.receivedQuotations = receivedQuotations;
}
public List<Enquiry> getSendEnquiries() {
return sendEnquiries;
}
public void setSendEnquiries(List<Enquiry> sendEnquiries) {
this.sendEnquiries = sendEnquiries;
}
public List<Enquiry> getReceivedEnquiries() {
return receivedEnquiries;
}
public void setReceivedEnquiries(List<Enquiry> receivedEnquiries) {
this.receivedEnquiries = receivedEnquiries;
}
public List<Supplier> getSupplying() {
return supplying;
}
public void setSupplying(List<Supplier> supplying) {
this.supplying = supplying;
}
public List<Invoice> getSendInvoices() {
return sendInvoices;
}
public void setSendInvoices(List<Invoice> sendInvoices) {
this.sendInvoices = sendInvoices;
}
public List<Invoice> getReceivedInvoices() {
return receivedInvoices;
}
public void setReceivedInvoices(List<Invoice> receivedInvoices) {
this.receivedInvoices = receivedInvoices;
}
@OneToMany(mappedBy = "organization")
private List<Tax> taxes;
public List<Tax> getTaxes() {
return taxes;
}
public void setTaxes(List<Tax> taxes) {
this.taxes = taxes;
}
@OneToMany(mappedBy = "organization")
private List<Identity> identities;
public List<Identity> getIdentities() {
return identities;
}
public void setIdentities(List<Identity> identities) {
this.identities = identities;
}
}
IUserRepository
@Repository
@RepositoryRestResource
public interface IUserRepository extends JpaRepository<User, UUID> {
Page<User> findByOrganizationContaining(@Param("organization") String organization, Pageable pageable);
}
我已将此方法创建为
Page<User> findByOrganizationContaining(@Param("organization") String organization, Pageable pageable);
但它不起作用,因为我想根据组织名称(组织表中的列)进行搜索。
最佳答案
您在组织中没有name
属性,您有organization
我认为这就是您所指的。你可以做这样的事情
Page<User> findByOrganization_Organization(String organization, Pageable pageable);
下划线(_)表示嵌套字段。但要使其发挥作用,您需要急切地获取组织。
@OneToOne(cascade = CascadeType.ALL, mappedBy = "user", fetch=FetchType.EAGER)
private Organization organization;
关于java - 如何为 findBy Join 表列制定 JPA 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43995757/
我有一些类(class) Activity : @Data @Document(collection = "event") public class Event { private String id
我有一个带有字符串名称字段的 Book 实体。使用 Spring Data JPA 关键字时有什么区别: Optional findByName(String name); 和 Optional fi
评分细则和品牌表(Many rubric to One Brand)之间存在关系。 这是我的代码 $dbChoices = $this->getConfigurationPool()
我有以下代码: println "@@@@@@@@ RUNNING ProfessionaCustomer - ${pcCounter} under ${accountCustomer.custome
我的Grails应用程序中提供以下服务: class Person { String name } class Host { String url } 然后,我有一个由多个并发线程调用
给定: controller PersonController with a @Transactional action save 服务 PersonService,方法 populateProper
我将 Symfony2 与 Doctrine2 一起使用。有以下实体: /** * Person * * @ORM\Entity(repositoryClass="Acme\Bundle\Con
我有一个包含大约 30 万行描述 Apple 推送通知服务设备的表。我使用 Doctrine 2 作为 ORM。 插入设备没有问题,但是,检索它们是一个完全不同的故事。使用简单的 MySQL SELE
我已经调试了好几天了。 Store.findBy(function (record, id)不行为。或者也许是我行为不端。已将 JSON 放入代码中,以便于测试。 FindBy() 匹配 12345
我有一个扩展,我想在其中包含一些过滤器,我知道我可以使用 findBy 过滤我的 listAction() 显示的结果>. 我测试了它,它是这样工作的: $cars = $this->carRepos
我有一个关于 symfony Doctrine 的片段,它按降序选择数据。尝试应用 where 子句某些字段等于 true 是一个问题。下面是我的片段 $results = $this->getDoc
我想要这个功能 $entityManager ->getRepository('AppBundle:Example') ->findBy(array('id' => $id, 'active' =>
我在表中有一些错误数据,但并非所有字段都具有空值,如果可能的话,我想通过实现类似这样的方法在一次迭代中获取所有错误行。 $contactObj = $this->em->getRepository("
我有域类 => 多对多并使用 addTo 将它们关联起来。 class Books { static belongsTo = Author } class Author { stati
我有一个对象,我必须从中过滤某些属性,其中一些也可能是“空”。我有一个 Filter 对象和一个 Product 对象。 在 Filter 对象中,我有一些反射(reflect) Product 对象
有人在 Symfony 3(最后一个版本)中遇到过这个奇怪的问题吗? 我有以下简单的代码: $repository = $this->getDoctrine()
我遵循在 Doctrine 模型类中设置自定义 findOneByJoinedToCategory($id) 函数的示例,如此处文档中所述: http://symfony.com/doc/curren
我有一个实体 Items,它与另一个实体 ExceptionType 上的字段具有 ManyToOne 关系。我想返回基于银行号码(来自 Items 实体)和 itemExceptionType(来自
所以我有一个有趣的难题,我很想从其他 Webdriver 框架架构师那里得到一些反馈。目前我遵循一个非常标准的执行模型: 基础对象 页面对象(扩展基础对象) Junit 测试对象(引用一个或多个页面对
我有一个 Item 类,其属性名为vendor_name,如下所示: @Entity @Table(name="item_info") public class Item { @Column(
我是一名优秀的程序员,十分优秀!