hibernate

hibernate - uniqueResult silently fails

I have a login controller that use the hibernate uniqueResult method. Everything works fine when i test it in eclipse's tomcat server. But when i deploy my webapps to tomcat server (on the same machine) it fails: it always returns null even i use the correct credential. Here is my hibernate code: session.createCriteria(User.class) ...

Ids not available from proxy object

I have the follow object: @Entity @Table(name="slideshow") @Searchable public class SlideShow implements Serializable { @Id @GeneratedValue(generator="slideShowSeq") @SequenceGenerator(name="slideShowSeq", sequenceName="slideshow_seq") @SearchableId int slideShowId @SearchableProperty String name @Man...

Getting a 'No thread-bound request found' error from spring in my web app

I'm getting a 'No thread-bound request found' error in my web app and hoping to get some help. I'm trying to use struts2 + spring + hibernate, and use spring to manage the hibernate session factory, and inject hibernate sessions into my struts actions. I hope that made sense. When the app starts up, there are no errors, but when i make t...

LazyInitialization Exception with Spring and Hibernate

Hi everyone I think i'm missing something fundamental about how Hibernate works, specifically with lazy loading. My problem is debugging, as I'm not sure if this is a Hibernate problem or a Spring problem in disguise. I thought I would ask here before doing some major refactoring. I have two Entities. One holds a collection of the ...

Hibernate: When to use getSession() and when to use getCurrentSession()?

Hi All, I have been using hibernate with Springs where i don't get to use getSession() or getCurrentSession() as the Spring container manages it. But i came across this getSession() and getCurrentSession() methods while reading hibernate. Can anyone explain when to use either of the methods? ~ Jegan ...

HIbernate Query taking very long time

I am trying optimize my code. I fetching the data using hibernate, when i am running the query directly on the database it fetching the results in 2secs, rowcount around 2800. Same query when i fire from my java code takes 8 secs. i have included the code sniplet below. Please help me out on this, its very urgent. Session hSession =open...

how does spring allow for lazy-loading?

If you have a call in a Dao method like (pseudo code): return ..getHibernateTemplate( get by id ); Now say that entity has a lazy-loaded collection. Once you return from your Dao using the hibernateTemplate helper method, how come the session stays in scope and allows you to lazy-load a collection? Is the session initialized and comm...

iterate array to create hibernate criteria statement

let say my array has 3 integer object value= 3,4,5 i would need to create hibernate criteria that look like below criteria.add(Restrictions.and(Restrictions.not(Restrictions.eq( "stepId", new Integer(3))), Restrictions.and(Restrictions .not(Restrictions.eq("stepId", new Integer(4))), Restrictions .not(Restriction...

Hibernate fails with NullPointerException in EntityTuplizerFactory.constructTuplizer? Why?

I have a problem when I try to instantiate Hibernate and connect with a MySQL database (see error message below). Curiously enough the connection works fine using the exact same hibernate.cfg.xml file when running Junit tests but it refuses to work when run from Tomcat... I am starting to run out of ideas. Any clues or tip where to l...

Hibernate Validation and Spring 3.x

I am trying to use validation with Spring 3.x. I have annotated a method field with @Valid, added <mvc:annotation-driven/> to my common.xml, and added Hibernate-Validator.jar in the lib/ dir, but I keep getting this message: "Hibernate validator not found: ignoring". Am I missing something? [Version:15] Hibernate Annotations 3.4.0.G...

Hibernate One-to-Many cascade efficiency

I have been learning Hibernate for the past few weeks, I have gotten most of what I learned to work but have a question on the efficiency of a One-to-Many mapping. It works, but I am pretty sure that it could be tweaked quite a bit. When saving, I notice that there are three queries that get executed, an insert for the "Parent" object, a...

Mapping Hibernate "Custom" Subclasses

As a new Hibernate user, I have heard that a good pattern for adding some helper methods to generated classes is to add them in a subclass. For example: // generated via Hibernate mapping file public class GeneratedClass { long id; String someValue; // etc, etc. } // my own class with pretty printing method public class MyGener...

Hibernate validator error - 4.0.2.GA

Hi, the validate function of the Hibernate Validator seems to be buggy (version hibernate-validator-4.0.2.GA.jar). Do I maybe miss a dependency? Part of my stack trace: java.lang.NoSuchMethodError: javax.persistence.Persistence.getPersistenceUtil()Ljavax/persistence/PersistenceUtil; at org.hibernate.validator.engine.resolver.JP...

Lazy loading...

Is there a scenario where eager loading is preferred over lazy loading? ...

Hibernate resolve foreign key lookup id by name

I'm in the process of writing a module for an application that bulk imports data. I'm using Hibernate version 3 for data access. I receive a flat table of data let's call it products for simplicity and assume this data layout: Name, category, sub-category foo, main1, sub11 The category and sub-category fields actually refer to the ...

How to sort through an association table in hibernate?

Given a representation of database tables where two entities are connected through a join table, is it possible to sort on the other entity specifying the sort order somehow through annotations? Consider, roughly, the following database tables: actor ( id, name ) credit ( actorId, movieId, roleName ) movie ( id, title, year ) And hi...

hibernate annotation bi-directional mapping

I'm building a web application using Spring framework and Hibernate with annotation and get stuck with a simple mapping between two entities. I'm trying to create a many-to-many relationship between User and Course. I followed one of the Hibernate tutorials and my implementation is as follows: User class: @Entity @Table(name="USER") ...

use compass rather than hibernate second level cache

looking forward to hear opinion from you all. do you think just use compass and enabled caching in compass is enough and thus no need to use hibernate second level cache? i even heard compass support memcached. in that case no point to use hibernate second level cache do you all use compass and still enable hibernate 2nd level cache on...

select statement get time duration

let say i have table look like below actionTable ----------- id, user, actionName, time 1 , userX, startdoing, 1/1/2010 9am 2, userX, endDoing, 2/1/2010 10am may i know whether possible to use 1 sql select statement to minute record 2 from 1 and get time spent ? or use hibernate.criteria to do this? ...

Criteria queries in JPA

Is there Hibernate criteria like queries in JPA? ...