hql

Hibernate ConstraintViolationException on SELECT query

非 Y 不嫁゛ 提交于 2019-12-06 11:01:19
I have a Persistent Class with multi-field unique constraint on it. But defined unique constraint is not sufficient for me because on one those field non-equal but similar values are unique too. I implement a checkUniqueConstraint method. In add and update methods of DAO class, I call checkUniqueConstraint before adding or updating persist object. checkUniqueConstraint method just run a SELECT query to find object similar to input and throw a check Exception where find some ones. public class PersistClassDao { public void checkUniqueConstraint(PersistClass persistObject) throws

Is there a 'does not contains' functionality on a collection property of a domain object for createCriteria?

删除回忆录丶 提交于 2019-12-06 09:32:36
I have a problem similar to this . But I want a does not contain functionality. Like I have a Post domain. A Post hasMany User. What I'd like to do, using createCriteria, is something like this: def c = Post.createCriteria() def l = c.list (max: maxVar) { notContains("users", thisUser) } I tried using ne But no luck. def l = c.list (max: maxVar) { users { ne('id', thisUser.id) } } To be clear, how can I get list of all the Post whose users field which is a collection does not contain thisUser ? You can use HQL for this List<Post> posts = Post.executeQuery("select distinct p from Post p where

MYSQL case sensitive search (using hibernate) for utf8

半腔热情 提交于 2019-12-06 09:19:18
I have Login Table that have utf8 charset and utf8 collation when I want check user name and retrieve other information for this specific user name the hql query give me the same result with lowercase and uppercase. what should l do for my HQL query that work case sesitive I use Mysql 5 and java hibernarte this is my query: return queryManager.executeQueryUniqueResult("select b.login from BranchEntity b where b.userName = ?", username); The easiest way is to change your column's definition to use case-insensitive collation like utf8_bin . Details are here Add class public class CollateDialect

How to filter the child entity while quering the parent in hibernate

こ雲淡風輕ζ 提交于 2019-12-06 08:51:13
Lets say that i have two entities public class EntityA { @id @GeneratedValue @Column(name="id") private Long id; @OneToMany(mappedBy="EntityA") @JoinColumn(name = "entityA_id") private List<EntityB> entityBList; } public class EntityB { @Column(name = "MODEL_PERCENT") private BigDecimal modelPercent; @ManyToOne @joincolumn(name="entityA_id") private EntityA entityA; } What i want now is, when i fetch the EntityA i want to add a where clause to fetch all EntityBs' whose modelPercent is greater than 0. I do not want to use filters since this requirement is only for this perticular situation. Eg

Converting Hibernate linq query to HQL

为君一笑 提交于 2019-12-06 08:46:16
I understand that a IQueryable cannot be serialized. That means that queries can not be serialized, sent to a webservice, deserialized, queried and then sent back. I was wondering if it is possible to convert a hibernate linq query to hql to be sent over the wire. Is there another route I am missing? I think I've seen ADO.NET Data Services as advertised to work with NHibernate: http://wildermuth.com/2008/07/20/Silverlight_2_NHibernate_LINQ_==_Sweet http://ayende.com/Blog/archive/2008/07/21/ADO.Net-Data-Services-with-NHibernate.aspx This is an old post, and not sure how maintained this feature

Why does this HQL delete fail, when an HQL select with same terms works?

一笑奈何 提交于 2019-12-06 08:32:46
问题 Why does the following HQL query fail? string hql = @"delete MyLog log where log.UtcTimestamp < :threshold and log.Configuration.Application = :application"; session.CreateQuery(hql) .SetDateTime("threshold", threshold) .SetEnum("application", this.application) .ExecuteUpdate(); The same form of query works when used in a select: string hql = @"from MyLog log where log.UtcTimestamp < :threshold and log.Configuration.Application = :application"; IList<MyLog> log = session.CreateQuery(hql)

Nhibernate: distinct results in second level Collection

筅森魡賤 提交于 2019-12-06 08:15:42
问题 I have an object model like this: class EntityA { ... IList<EntityB> BList; ... } class EntityB { ... IList<EntityC> CList; } I have to fetch all the colelctions (Blist in EntityA and CList in EntityB), because if they all will be needed to make some operations, if i don't eager load them i will have the select n+1 problem. So the query was this: select a from EntityA a left join fetch a.BList b left join fetch b.CList c The fist problem i faced with this query, was the return of duplicates

Hibernate HQL query does not update the Lucene Index

六月ゝ 毕业季﹏ 提交于 2019-12-06 07:59:36
I am using Hibernate 3.6.3 Final and Hibernate Search 3.4.1. I wrote an HQL delete query. The objects are deleted from the database but they are not removed from the Lucene Index after the transaction completes. Here is the query: Session session = factory.getCurrentSession(); Query q = session.createQuery("delete from Charges cg where cg.id in (:charges)"); q.setParameterList("charges", chargeIds); int result = q.executeUpdate();` What am I missing? What do I need to do to solve issue? I created a PostDeleteEvent, hoever the FullTextEventListener doesn't appear to be receiving the event:

Get nextval sequence value by simple java Query on a PostgreSQL DB

痴心易碎 提交于 2019-12-06 07:52:20
I'm working on a PostgreSQL Database and I am trying to recover a nextval sequence by a simple Query by Java, but It's not working : Query q = entityManager.createQuery("SELECT nextval(numcallcartnewcart) as num"); BigDecimal result=(BigDecimal)q.getSingleResult(); return result.longValue(); (Of course it's not the best solution, but I can't do better, because I'm blocked by the Hibernate configuration with the composite-id tag which don't accept a generator sequence like that : <column name="num_call" /> <generator class="sequence"> <param name="sequence">numcallcartnewcart</param> <

Spring security/hibernate: Bad credentials even if they're right?

亡梦爱人 提交于 2019-12-06 07:21:42
问题 Hey I am having a bit of a mess with my springsecurity based login I'm keep getting the error "bad credentials" Here's my user table: ![Usertable][1] Here's my dataSource from the applicationContext: <!-- database driver/location --> <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="com.mysql.jdbc.Driver" /> <property name="url" value="jdbc:mysql://localhost:3306/ams" /> <property name="username" value="root" />