criteria

Hibernate - TypedQuery.getResultList() returns a list of the same object

对着背影说爱祢 提交于 2019-12-22 06:02:34
问题 Here is a more and maybe better description of the problem: I do a simple select query. The returning list contains the exact number of records/objects as if I do the same query in the DB, but the problem is that all the objects are the same/identical. For ex, this is the result in the DB (I removed the null values): 26801 01-JAN-00 7 31-DEC-99 7 Obere Kirchstr. 26 CH 8304 Walliselln 26801 01-JAN-00 2 31-DEC-99 2 Obere Kirchstr. 26 CH 8304 Walliselln And this is the content of the variable

Hibernate - TypedQuery.getResultList() returns a list of the same object

妖精的绣舞 提交于 2019-12-22 06:02:10
问题 Here is a more and maybe better description of the problem: I do a simple select query. The returning list contains the exact number of records/objects as if I do the same query in the DB, but the problem is that all the objects are the same/identical. For ex, this is the result in the DB (I removed the null values): 26801 01-JAN-00 7 31-DEC-99 7 Obere Kirchstr. 26 CH 8304 Walliselln 26801 01-JAN-00 2 31-DEC-99 2 Obere Kirchstr. 26 CH 8304 Walliselln And this is the content of the variable

Hibernate - TypedQuery.getResultList() returns a list of the same object

不打扰是莪最后的温柔 提交于 2019-12-22 06:02:04
问题 Here is a more and maybe better description of the problem: I do a simple select query. The returning list contains the exact number of records/objects as if I do the same query in the DB, but the problem is that all the objects are the same/identical. For ex, this is the result in the DB (I removed the null values): 26801 01-JAN-00 7 31-DEC-99 7 Obere Kirchstr. 26 CH 8304 Walliselln 26801 01-JAN-00 2 31-DEC-99 2 Obere Kirchstr. 26 CH 8304 Walliselln And this is the content of the variable

Hibernate Criteria join query

喜夏-厌秋 提交于 2019-12-22 01:29:07
问题 How do I create a Hibernate criteria query from the following sql? String hql = "select e.employeeId,m.meetingId,e.firstname from Employee e join e.meetings m"; Can anyone please provide the corresponding criteria query? 回答1: the criteria query is: Criteria c = session.createCriteria(Employee.class, "e"); c.createAlias("e.meetings", "m"); // inner join by default c.setProjection( Projections.distinct( Projections.projectionList() .add( Projections.property("e.employeeId"), "employeeId") .add(

How can I write a Hibernate Criteria query, for a super-class, and check for a certain sub-class?

情到浓时终转凉″ 提交于 2019-12-21 13:12:11
问题 How can I write a Hibernate Criteria query, for a super-class, and check for a certain sub-class? Let's imagine we have the following classes all mapped up with Hibernate-JPA: @Entity @Inheritance(strategy = InheritanceType.JOINED) public class Bar { @Id @Column(name = "id") private Long id; } @Entity @PrimaryKeyJoinColumn(name="bar_id") public class Foo extends Bar { } @Entity @PrimaryKeyJoinColumn(name="bar_id") public class Goo extends Bar { } When writing a Criteria query like this, I

How can I express joining to a grouped subquery using NHibernate?

怎甘沉沦 提交于 2019-12-21 13:06:16
问题 I'm trying to express a SQL query using NHibernate's Criteria API, and I'm running into difficulty because I'm thinking in a database-centric way while NHibernate is object-centric. SQL (works great): select outerT.id, outerT.col1, outerT.col2, outerT.col3 from tbl outerT inner join (select max(innerT.id) from tbl innerT group by innerT.col1) grpT on outerT.id = grpT.id Essentially, this is a self-join of a table against a subset of itself. I suppose I could try turning the self-join into a

Hibernate Criteria Query - nested condition

烂漫一生 提交于 2019-12-21 11:26:28
问题 I can't figure out how to create a query like this with Hibernate Criteria synthax select * from x where x.a = 'abc' and (x.b = 'def' or x.b = 'ghi') Do you have an idea of how to do that? I'm Using Hibernate Restriction static methods but I don't understand how to specify the nested 'or' condition 回答1: You specific query could be: crit.add(Restrictions.eq("a", "abc")); crit.add(Restrictions.in("b", new String[] { "def", "ghi" }); If you're wondering about ANDs and ORs in general, do this: //

NHibernate: Criteria expression to retrieve all entities with null count child collection

你。 提交于 2019-12-21 06:29:47
问题 In nhibernate, I have two classes that are associated with a many-to-one mapping: <class name="Employee" table="Employee"> .. <bag name="orgUnits"> <key column="id" /> <one-to-many name="OrgUnit" class="OrgUnit"> </bag> .. </class> I would like to use a criteria expression to get only Employees where the the collection is null (ie no orgunits) , something like this : IList employeesWithNoOrgUnit = sess.CreateCriteria(typeof(Employee)) .Add( Expression.IsNull("OrgUnits") ) .List(); This doesn

Hibernate Criteria order by a specific state

懵懂的女人 提交于 2019-12-21 05:38:29
问题 Hi In the database, we have a PRSN_ADDRESS table which has many addresses. A user is shown these addresses in a grid. The requirement is show the addresses associated with this user's state first and then show all other states. For example, say the table has 10 records with 5 of the addresses having state as Maryland, 2 from PA and 3 from NJ. Now if the user is associated with Maryland, we need to show all the 10 addresses, but Maryland addresses should show up in the first five and then the

2019.12.17笔记

拟墨画扇 提交于 2019-12-21 05:01:33
规格管理的增删改查 SpecificationService public interface SpecificationService { //高级查询 public PageResult findPage(Specification spec, Integer page, Integer rows); // 新建 public void add(SpecEntity specEntity); //查询实体 public SpecEntity findOne(Long id); //保存 public void update(SpecEntity specEntity); //删除 public void delete(Long[] ids); //下拉框 public List<Map> selectOptionList(); } SpecificationServiceImpl @Service @Transactional public class SpecificationServiceImpl implements SpecificationService { @Autowired private SpecificationDao specDao; @Autowired private SpecificationOptionDao optionDao; //高级查询