首页 \ 问答 \ 选择记录,其中id是集合ID之一(Select record where id is one of collection id)

选择记录,其中id是集合ID之一(Select record where id is one of collection id)

在spring mvc应用程序中,我有3个数据库表(包括一个映射表)和它们的2个相应的java实体。

实体是: -

public class User {
        private Long id;
        private String userName;

        @ManyToMany(fetch = FetchType.EAGER)  
        @JoinTable(name = "user_location",  
        joinColumns        = {@JoinColumn(name = "user_id", referencedColumnName = "id")},  
        inverseJoinColumns = {@JoinColumn(name = "location_id", referencedColumnName = "id")}  
                )  
        private Set<Location> location;
    }

public class Location {
        private Long id;
        private String locationCode;
    }

三个表是users,location和user_location。

我想选择位置id等于特定id的用户。 由于用户可以有多个位置,我不知道如何为此编写一个hibernate查询。 我在下面尝试了几个组合,但我要么得到一个例外,

illegal attempt to dereference collection [{synthetic-alias}{non-qualified-property-ref}] with element property reference [id]

或获取用户和位置对象的列表。 我只想要一个用户对象列表。

  • 来自user的用户名=:userName和:locationId in(location.id)
  • 来自用户用户内部联接user.location loc其中user.userName =:usersName和loc.id =:locationId

更新:我试过查询,

Query query = getCurrentSession().createQuery("from User user inner join user.location loc where user.userName = :usersName and loc.id = :locationId");  

Hibernate从上面的查询生成以下纯SQL,并返回User和Location对象的列表。 例如,如果用户的一个位置与上面的查询匹配,则hibernate返回包含一个User和一个Location对象的列表。

select
        user0_.id as id1_18_0_,
        location2_.id as id1_5_1_,
        user0_.user_name as user_na11_18_0_,
        location2_.location_code as location3_5_1_       
    from
        users user0_ 
    inner join
        user_location location1_ 
            on user0_.id=location1_.user_id 
    inner join
        location location2_ 
            on location1_.location_id=location2_.id 
    where
        user0_.user_name=? 
        and location2_.id=? 

In a spring mvc application i have 3 database tables (including one mapping table) and their 2 corresponding java entities.

The entities are:-

public class User {
        private Long id;
        private String userName;

        @ManyToMany(fetch = FetchType.EAGER)  
        @JoinTable(name = "user_location",  
        joinColumns        = {@JoinColumn(name = "user_id", referencedColumnName = "id")},  
        inverseJoinColumns = {@JoinColumn(name = "location_id", referencedColumnName = "id")}  
                )  
        private Set<Location> location;
    }

public class Location {
        private Long id;
        private String locationCode;
    }

Three tables are users, location and user_location.

I want to select a user whose location id is equal to a particular id. Since user can have multiple locations i am not sure how to write a hibernate query for this. I tried few combinations below but i am either getting a exception,

illegal attempt to dereference collection [{synthetic-alias}{non-qualified-property-ref}] with element property reference [id]

or getting a list of User and Location objects. i just want a list of user objects.

  • from User where userName = :userName and :locationId in (location.id)
  • from User user inner join user.location loc where user.userName = :usersName and loc.id = :locationId

Update: I tried query,

Query query = getCurrentSession().createQuery("from User user inner join user.location loc where user.userName = :usersName and loc.id = :locationId");  

Hibernate generates following plain SQL from above query and returns a list of User and Location objects. For example if there is one location for an user that matches above query hibernate returns a list that contains one User and one Location object.

select
        user0_.id as id1_18_0_,
        location2_.id as id1_5_1_,
        user0_.user_name as user_na11_18_0_,
        location2_.location_code as location3_5_1_       
    from
        users user0_ 
    inner join
        user_location location1_ 
            on user0_.id=location1_.user_id 
    inner join
        location location2_ 
            on location1_.location_id=location2_.id 
    where
        user0_.user_name=? 
        and location2_.id=? 

原文:https://stackoverflow.com/questions/35225726
更新时间:2021-05-04 11:05

最满意答案

因为有。 标准API库中包含了SOAP客户端所需的功能。 您可以使用wsimport工具(位于JDK安装的bin目录中)从指定的WSDL生成客户端类。


Because there is. The required functionality for SOAP clients are included in the standard API library. You can use the wsimport tool (located in the bin directory of your JDK installation) to generate client classes from a specified WSDL.

相关问答

更多
  • 您考虑过REST服务吗? 这是InfoQ的一个有用的介绍。 它适用于HTTP,您使用GET / PUT / POST / DELETE的标准HTTP命令来操作数据(您可以使用浏览器进行查询,客户端是简单的HTTP客户端)。 实际数据内容不是强制或指定的 - 通常是XML,但这不是必需的。 您可以使用Jersey在Java下轻松构建REST服务。 因为客户端只需要谈论HTTP,所以它们可以与语言无关。 可以使用HTTPClient编写Java客户端。 Have you considered a REST se ...
  • 试试Sun教程 。 这些通常非常好 Try the Sun Tutorial. These are usually very good
  • 因为有。 标准API库中包含了SOAP客户端所需的功能。 您可以使用wsimport工具(位于JDK安装的bin目录中)从指定的WSDL生成客户端类。 Because there is. The required functionality for SOAP clients are included in the standard API library. You can use the wsimport tool (located in the bin directory of your JDK inst ...
  • 虽然两者都被称为“Web服务”,但通常在.net中创建的基于SOAP的Web服务与遵循旧XML-RPC标准的 Web服务不兼容。 在我看来,你可以按照2条路线来解决你的问题: 你要么在Java下使用SOAP路由,为此目的最常见的API之一就是jax-ws - 这里有一些很好的教程指针,在Pascal Thivent的回答中 或者使用xml-rpc.net将.net webservices转换为XMl-RPC 这两条路线都有优点和缺点,如果不了解您的项目,很难为您做出选择。 选择SOAP路由的先验可能看起来“ ...
  • 由于我在服务器上进行用户管理,因此通过Appcelerator进行用户管理也没有意义。 我以前认为如果我想使用Appcelerator作为推送通知服务,我也必须通过他们的服务创建用户。 但是,我现在意识到Push Notification API中有两个部分。 订阅 退订 通知 和 subscribeToken unsubscribeToken notifyToken 后一组使用来自设备的pushToken,它与Appcelerator无关。 使用这些方法,您不需要拥有Appcelerator用户,因为您只 ...
  • 你会在网上找到很多这样的例子,可能存在很多框架来简化这个。 我没有尝试Spark,但看起来还不错。 Apache HttpComponents客户端也是一种可行的方式,并且已得到充分证明。 例: HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet('http://restUrl'); HttpResponse response = client.execute(request); 这是一些文档: http : ...
  • 管理解决我自己的问题。 这是我做到的。 XFire在内部使用Apache Http客户端,因此在此Api上设置Security certifect详细信息将完成这项工作。 为此,我们将使用no-yet-common-ssl.jar。 首先,我们将使用commons创建org.apache.commons.ssl.TrustMaterial ,然后在HttpSecureProtocol中设置它,它是javax.net.ssl.SSLSocketFactory的子代。 假设XYZ.cer是服务提供商提供的客户端 ...
  • 在部署的WSDL URL上运行wsimport,您可以从您的JDK运行它: wsimport -p client -keep http://localhost:8080/calculator?wsdl 这一步将生成并编译一些类。 注意 - 切换开关,您需要它来保留生成的Java源文件。 Calculator.java - 服务端点接口或SEI CalculatorService - 生成的服务,实例化它 public class MyClientServiceImpl { public stati ...
  • 只要Java Web服务使用WSDL等标准,您就应该能够在.NET中添加服务引用。 这并不是说你可能不需要注意的怪癖,但你应该具备互操作性。 本文介绍如何在Visual Studio 2010中添加服务引用。 As long as the Java web service uses standards such as WSDL, you should be able to add a service reference to it in .NET. That's not to say that there ...
  • 不确定,我从未见过那个错误...... 但是,我要做的是创建一个类库项目并在此处添加Web引用。 然后,您可以在SOAP发送端口中使用它,如此处所述(请参阅第5点)。 您还可以直接在BizTalk项目中引用类库。 既然你说Web引用在Console应用程序中工作,也许这可以工作...... 此外,您可以直接使用XSD架构 - 但这需要更多的工作。 您必须在业务流程或自定义管道组件中手动提升几个属性。 你可以在这篇文章中找到更多细节(网站目前正在关闭,但希望最终会重新上线)。 最后,您还可以使用httpBin ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)