选择记录,其中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
最满意答案
因为有。 标准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.
相关问答
更多-
在Java世界中创建新的RPC / Web服务的最佳方法?(Best approach for creating new RPC/web services in the Java world?)[2021-11-29]
您考虑过REST服务吗? 这是InfoQ的一个有用的介绍。 它适用于HTTP,您使用GET / PUT / POST / DELETE的标准HTTP命令来操作数据(您可以使用浏览器进行查询,客户端是简单的HTTP客户端)。 实际数据内容不是强制或指定的 - 通常是XML,但这不是必需的。 您可以使用Jersey在Java下轻松构建REST服务。 因为客户端只需要谈论HTTP,所以它们可以与语言无关。 可以使用HTTPClient编写Java客户端。 Have you considered a REST se ... -
Java Web服务(Java Web Services)[2022-11-14]
试试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 ...