not like condition in hibernate criteria query

I have a list of tickets. I want all tickets whose status are not like %CLOSED%. Here is an example using Criteria.


Criteria c = super.getSession().createCriteria(Ticket.class);

c.add(Restrictions.not(Restrictions.like("status", "%CLOSED%")));

Advertisements

javax.validation.ValidationException: HV000183: Unable to load ‘javax.el.ExpressionFactory’. Check that you have the EL dependencies on the classpath, or use ParameterMessageInterpolator instead

I got this exception when I executed my newly written junit test for a Spring DAO with Hibernate Validations.

After adding javax.el to pom, this is resolved.


<dependency>
<groupId>javax.el</groupId>
<artifactId>javax.el-api</artifactId>
<version>2.2.4</version>
</dependency>
<dependency>
<groupId>org.glassfish.web</groupId>
<artifactId>javax.el</artifactId>
<version>2.2.4</version>
</dependency>

 

org.hibernate.AssertionFailure: null id in entry (don’t flush the Session after an exception occurs)

I’m  inserting multiple records to MySQL with Hibernate 5.

After a constraint failure, all the records are failed to get inserted with the error ‘org.hibernate.AssertionFailure: null id in entry (don’t flush the Session after an exception occurs)’. To get rid of this problem, I cleared the hibernate session when the exception occurs with session.clear().

Data is getting pumped without any problem now.

Cd1bUvDUUAEo8M4.jpg large

Ticketing management / support desk management with struts, spring and hibernate

Here are the screenshots I promised in my earlier post.

image

Report of the tickets-more filters to be added

image

Details of a ticket and the provision to add the follow-ups if any.

image

Historic report of the followups for the selected ticket.

image

Screen to add a ticket

Delivery 1 is completed yesterday. Lets wait for next release for more features.. Stat tuned!

ஜெய்ஹிந்த்
Posted from WordPress for Android

Ticketing management on SDLC with struts, spring and hibernate

Here are tge screenshots I promised in my earlier post.

image

Report of the tickets-more filters to be added

image

Details of a ticket and the provision to add the follow-ups if any.

image

Historic report of the followups for the selected ticket.

image

Screen to add a ticket

Delivery 1 is completes yesterday. Lets wait for next release for more features.. Stat tuned!

ஜெய்ஹிந்த்
Posted from WordPress for Android

Illegal attempt to associate a collection with two open sessions

Illegal attempt to associate a collection with two open sessions

When we are working with collections with spring and hibernate, you may end up with this exception while saving an object. Googling says this is a feature/bug of hibernate – hibernate is not versioning the collections as it does for other objects. Don’t know what it is in detail, but I should solve this right now. The suggested solution is to have  single session. The following the code that saves my object.

public class BaseDAO extends HibernateDaoSupport implements IBaseDAO {
.....
/* (non-Javadoc)
	 * @see com.eginnovations.license.dao.IBaseDAO#save(java.lang.Object)
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED, readOnly=false)
	public Object save(Object entity){
		Session session = super.getSession();
		Serializable save = session.save(entity);
		logger.debug("save:"+save.getClass()+" "+save+" "+entity);
		return save;
	}

..............
}

New session are getting opened in super.getsession() and session.save().

The problem is I have not implemented OpenSessionInViewFilter till now, so I don’t have the option to have the single session. So here is the entries added to the deployment descriptor web.xml.

	<filter>
		<filter-name>openSessionInViewFilter</filter-name>
		<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
		<init-param>
			<param-name>singleSession</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>

And this is the filter mapping.

<filter-mapping>
		<filter-name>openSessionInViewFilter</filter-name>
		<url-pattern>/*</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
		<dispatcher>ERROR</dispatcher>
	</filter-mapping>

Go ahead!