criteria

spring-data-solr

匿名 (未验证) 提交于 2019-12-02 23:05:13
  Spring Data SolrSolr SolrJ API <field name="item_goodsid" type="long" indexed="true" stored="true"/> <field name="item_title" type="text_ik" indexed="true" stored="true"/> <field name="item_price" type="double" indexed="true" stored="true"/> <field name="item_image" type="string" indexed="false" stored="true" /> <field name="item_category" type="string" indexed="true" stored="true" /> <field name="item_seller" type="text_ik" indexed="true" stored="true" /> <field name="item_brand" type="string" indexed="true" stored="true" /> <field name="item_keywords" type="text_ik" indexed="true" stored=

hibernate criteria with exists clause

女生的网名这么多〃 提交于 2019-12-02 22:32:54
I cannot find a solution to a problem that seems to be easy. Say there are 2 entity classes: class A { Set<B> bs; } class B { String text; } How to create a criteria query that returns all A's that contains at least one B entity which fulfills a given condition (like b.text = 'condition')? Lucia Manescau I think this link can be useful: http://mikedesjardins.net/2008/09/22/hibernate-criteria-subqueries-exists/ It contains the following example about how create n exists criteria: "What you’re really trying to do is to obtain all Pizza Orders where an associated small pizza exists. In other

Hibernate笔记1

匿名 (未验证) 提交于 2019-12-02 21:45:52
ORM框架 对象关系映射(Object Relational Mapping,简称ORM) 是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换 Object :对象,java对象,此处特指JavaBean对象 Relational:关系,二维表,数据库中的表 Mapping:映射 什么是hibernat Hibernate是一个开放源代码的 对象关系映射 框架,他对JDBC进行了非常轻量级的对象封装 它将POJO与数据库表建立映射关系,是一个全自动的ORM框架 POJO简单的Java对象,实际就是普通JavaBeans hibernate可以自动生成SQL语句,自动执行,使得程序员可以随心所欲的使用对象编程思维来操作数据库 Hibernate可以应用在任何使用JDBC的场合,既可以在Java的客户端程序使用,也可以在Servlet/JSP的应用中使用 hibernate的简单使用 读取配置文件hibernate.cfg.xml和hibernate.properties的方法 Configuration cfg = new Configuration();//读取配置文件hibernate.properties Configuration cfg = new Configuration().configure();//读取配置文件hibernate.cfg.xml

Java连接MongoDB所需要实现得 org.springframework.data.mongodb.core.mapreduce.GroupBy

匿名 (未验证) 提交于 2019-12-02 21:40:30
分组查询主要使用org.springframework.data.mongodb.core.mapreduce.GroupBy这个spring中的类: 例: GroupBy groupBy = GroupBy.key("logonIp") .initialDocument(initial) .reduceFunction(reduceFunction); GroupByResults<T> results = mongoTemplate.group(criteria, "sessions", groupBy, T.class); GroupBy.key('key'): key是所进行分组字段的字段名; initial : 初始化对象,可理解为最后查询返回的数据初始化; reduceFunction: js函数,用于对返回的结果进行处理操作; function(doc,result){}: doc是根据查询条件(相当于where条件)获取的每一条数据,result是最后的查询结果,初始值就是initial对象; 查询操作: mongoTemplate.group(criteria,"session", groupBy, T.class); criteria:相当于SQL中的where条件; session: 数据库中的表名; groupBy: -以上; T.class:

Getting a count of rows in a datatable that meet certain criteria

故事扮演 提交于 2019-12-02 19:57:12
I have a datatable, dtFoo, and would like to get a count of the rows that meet a certain criteria. EDIT: This data is not stored in a database, so using SQL is not an option. In the past, I've used the following two methods to accomplish this: Method 1 int numberOfRecords = 0; DataRow[] rows; rows = dtFoo.Select("IsActive = 'Y'"); numberOfRecords = rows.Length; Console.WriteLine("Count: " + numberOfRecords.ToString()); Method 2 int numberOfRecords = 0; foreach (DataRow row in dtFoo.Rows) { if (row["IsActive"].ToString() == "Y") { numberOfRecords++; } } Console.WriteLine("Count: " +

Hibernate detached queries as a part of the criteria query

故事扮演 提交于 2019-12-02 18:37:58
java experts can you please help me write detached queries as a part of the criteria query for the following SQL statement. select A.* FROM AETABLE A where not exists ( select entryid FROM AETABLE B where B.classpk = A.classpk and B.userid = A.userid and B.modifiedDate > A.modifiedDate ) and userid = 10146 You need to write a correlated subquery . Assuming property / class names match column / table names above: DetachedCriteria subquery = DetachedCriteria.forClass(AETable.class, "b") .add(Property.forName("b.classpk").eqProperty("a.classpk")) .add(Property.forName("b.userid").eqProperty("a

Hibernate criteria query on different properties of different objects

流过昼夜 提交于 2019-12-02 18:19:27
Suppose I have classes like: class A { B getB(); C getC(); } class B { String getFoo(); } class C { int getBar(); } and I want to filter criteria on A, two filters on different subclass properties, like: Criteria criteriaA = session.createCriteria(A.class); Criteria criteriaB = criteriaA.createCriteria("b").add(Restrictions.eq("foo", "Something")); Criteria criteriaC = criteriaA.createCriteria("c").add(Restrictions.eq("bar", 0)); What I want to do is combine criteriaB and criteriaC using an "or" clause, something like: //this does not work criteriaA.add(Restrictions.disjunction().add(criteriaB

Hibernate query a foreign key field with ID

北战南征 提交于 2019-12-02 17:53:55
For example, I have two entities: Employee and Address. Of these enitities, Employee has a foreign key AddressID references the ID column on Address. In the Java domain objects, Hibernate nicely wraps the forgein key integer field with a Address object field. But now, how could I query the Employee with a certain AddressID? I have tried to create a table alias. That seems to work, but it is fairly awkward. I had also tried to do something like this: criteria.add(restriction.eq("TheAddressObjectFieldName", 123); It works some time but not always. I am not sure this is the right way, but I was

NHibernate: Query filtering on a list of values using criteria

倖福魔咒の 提交于 2019-12-02 17:21:44
问题 I'm trying to filter by a list of values using the criteria API. I suspect that this is not possible, I'm just asking here to be sure. class Entity { int id { get; set; } IList<Guid> Guids { get; set; } } The mapping: <class name="Entity"> <id ...></id> <bag name="Guids" table="Entity_Guids"> <key column="Entity_FK"/> <element column="Guid"/> </bag> </class> Assumed I have a list of Guids (actually these is another subquery). I want to filter all Entities where at least one guid is in the

Hibernate: Criteria with many-to-many join table?

不打扰是莪最后的温柔 提交于 2019-12-02 17:18:06
Consider following two relations: @Entity class Foo { @Id id; @ManyToMany @JoinTable(name = "ATag", joinColumns = @JoinColumn(name = "foo_id"), inverseJoinColumns = @JoinColumn(name = "tag_id")) Set<Tag> tags; } @Entity class Tag { @Id Long id; String name; } There is no corresponding entity class for the join table ATag. Now, I want to get all Foo instances with Tag named 'tag1', is it possible using only Criteria? A sub-query maybe helpful, however, I can't create DetachedCriteria for class ATag.class which isn't existed. Just dealt with this exact issue. You're thinking in tables, not