hibernate

What should be in a two days Hibernate Training

Hi, I am preparing a Hibernate training. The training will be two days long and targeted at somewhat experienced Java developers with no Hibernate experience. So what things would you cover / leave out in such a training? ...

(Lazy) LEFT OUTER JOIN using the Hibernate Criteria API

Hi all, I want to perform a LEFT OUTER JOIN between two tables using the Criteria API. All I could find in the Hibernate documentation is this method: Criteria criteria = this.crudService .initializeCriteria(Applicant.class) .setFetchMode("products", FetchMode.JOIN) .createAlias("products", "product"...

Real world experiences with AutoFetch for Hibernate?

I saw the project AutoFetch for Hibernate. It sounds pretty cool - when Hibernate queries are executed, it checks for the N+1 problem. If there was a problem, next time that query (it figures out which one it is by looking at the stacktrace) gets executed it adds appropriate fetch statements. It says on the website "Autofetch integrates...

How do I sanitize string fields containing HTML at model level?

I have an app using Spring, JPA (Hibernate) and the Java validation framework (Hibernate Validator). I would like to be able to annotate fields in our domain model that are allowed to contain HTML and have them automatically sanitized at commit time. Anyone know a clever way to do this? I have tried using the validation framework but th...

Spring+JPA+Hibernate: persist is updating the entity surprisingly. Please go through the details.

Hi, In my code, I did as follows: queried for a course entity populate it with the given course data. courseDao.update(entity) which internally calls persist(entity) method. Surprisingly, the data is got updated successfully. I am confused with this behaviour of persist method. Please help me out. code is as below: //My Service....

Optimizing an ORM-based model post-launch

I'm using Hibernate to work on a new project, and as I work I'm realizing that my original vision for the application may not end up being its destiny. Data that I think is not going to be often requested (and thus lazy-loaded) might end up being needed for 85% of requests. Conversely, data that I'm loading under the assumption it will b...

Hibernate Criteria: Left Outer Join with restrictions on both tables

Hi all, I am doing a LEFT OUTER JOIN, but I am only able to apply Restrictions on the first table. Is there a way ti apply on the second table as well? Here is my code: Criteria criteria = this.crudService .initializeCriteria(Applicant.class).setFetchMode("products", FetchMode.JOIN);. This works (applicant has a...

Typesafe Primary Key in Hibernate/JPA

I am looking for a way to have a typesafe primary key for my entities using generics in Hibernate. Instead of doing this @Entity public class User{ @PrimaryKey Long id } I was thinking of doing this... @Entity public class User{ @PrimaryKey PrimaryKey<User,Long> id } Or take the type inference even further... Any ideas? Has ...

How to check for a length of 5 or 9 with hibernate validator?

I can validate the length of a String with an annotation like: @Length(max = 255) But what if I want to verifiy that the length is either 5 or 9? Can this be done with an annotation? ...

Some help with hibernate Criteria query

Can somebody please help me complete / clean up this query. I am trying to first get the number of rows in the table, then I need to actually fetch a set of rows. I am not sure how I can use the same criteria instance to perform both queries. To fetch the count I have something like this: Criteria criteria = session.createCriteria(My...

GORM Save cascade return collection with no ids

Hi, Using Grails (GORM) I'm populating a collection upon creating an object and I must return the newly populated collection with ids. class A { static hasMany = [bees:B] } class B { static belongsTo = [a:A] } As noticed, a one-to-many relationship when the many side belongs to the one side for full cascading If A is not saved befor...

Middle ground between JDBC and Hibernate?

We've been implementing Hibernate recently as a replacement for JDBC. What I like is not having to constantly write SELECT, UPDATE, INSERT statements and the associated PreparedStatement and ResultSet code. However we've been struggling with random bizarre behavior (example A) which I find hard to understand and resolve due to all the ...

Converting Hibernate proxy to real object

Hello! During Hibernate session I am loading some objects and some of them are loaded as proxies due to lazy loading. It's all OK and I don't want to turn lazy loading off. But later I need to send some of the objects (actually one object) to the GWT client via RPC. And it happens that this concrete object is a proxy. So I need to turn...

Defining a particular strategy of ID generation in Grails

Hi, how i can define and use a strategy of ID (primary keys) generation for my domain classes ? I want to put a prefix for the primaryKey of some domain classes like customers and manufacturers based in the ID (primary key) of their hometown. I know that Hibenate has a API for this, but who i can integrate such strategy in my Grails app...

Hibernate + Postgresql with case insensitive searching

Hi, I've been googling around for a straight-forward solution on getting our new postgresql + hibernate setup working with case insensitive search, without luck. We had previously been using mysql which has a policy on case insensative searching however Postgresql seems to lack this. For example, I'd like Hibernate/Postgresql to return ...

Cyclic serialisation with Many to Many relationship with Hibernate.

I have a parent (Program) pojo with a many-to-many relationship with their children (Subscriber). The problem is when it serialises a Program, it also serialises the Program's Subscribers, which involves serialising their Programs, which involves serialising their Subscribers, until it has serialised every single Program & Subscriber in...

Audit trail in hibernate with new and old values using an Interceptor

Hi, I can easily log last modified date, modified by etc. However, I need old and new value to be logged too. In the interceptor, I can fire a select before postflush starts executing to get the value of the current record. Then I can run a diff between this record and the new one to see what changed and log that information as old and ...

image upload problem

I am writting the code to upload file on oracle as BLOB but while saving that file its giving me the exception java.sql.SQLException: ORA-01460: unimplemented or unreasonable following are the functions to convert my blob type to byteArray private byte[] convertToByteArray(Blob fromBlob) { ByteArrayOutputStream baos = new ByteArr...

Hibernate Filters break the second level cache

I've a collection mapped, which caches fine in the L2Cache. As soon as I apply a filter to the collection, the L2Cache is not used. I can't use a where clause in the collection as I need it to be more dynamic than that. Anyone have any ideas ?? ...

Stack Overflow whilst cascade saving nhibernate entity with custom generator

I'm pretty new to Nhibernate, so apologies for a long - winded description I suspect that changing the structure of the legacy DB is probably the best option, but I want to try and get NHibernate to deal with it. Basically the structure is this an EndPoint has an address and a contact. Endpoint is stored in a table with a composite ID ...