hibernate

Hibernate: Criteria search and Restrictions.in() won't work on a table with a composite-id when searching with multiple keys

Hello I'm using Hibernate with a Restrictions.in() criteria on a table with a composite id. Everything works fine when I put just one id in the query but when I put multiple id:s in the query Hibernate binds the parameters wrong. This is the output from the jboss log: 16:48:24,882 INFO [STDOUT] Hibernate: select this_.part_id as par...

Scaling EhCache

Hi everyone, I'm currently building an application that needs to be scalable, and therefor I'm interested in distributed caching and not replicated caching. We will be using memcache for common cache use cases. However Hibernate and Spring Security ACL both rely on EhCache which doesn't seem to have the same replication scheme as memca...

How do I know if a date is within the certain period

We are capturing attendance data in a certain table primarily capturing the values (userId, startDate, endDate). If a person applies leave on a certain date then only startDate is filled and if he applies for a set of dates then the start/end dates are captured. What query will help me find if a person is taking leave on a certain date (...

Hibernate: Where do insertable = false, updatable = false belong in composite primary key constellations involving foreign keys?

When implementing composite primary keys in Hibernate or other ORMs there are up to three places where to put the insertable = false, updatable = false in composite primary key constellations that use identifying relationships (FKs that are part of the PK): Into the composite PK class' @Column annotation (@Embeddable classes only) or I...

How to mimic upsert behavior using Hibernate?

Hello all, I'm writing an application that sync's entities from a third party datasource into our own schema, with a transformation/mapping step in between. I'm using Hibernate to represent and persist the entities in our own schema. A problem I'm running into is that I have a unique multi-column key on one of my tables. The behavior...

Hibernate error: current transaction is aborted, commands ignored until end of transaction block

Hi, I randomly see the same error in the catalina.out log: WARNING: SQL Error: 0, SQLState: 25P02 Sep 8, 2010 11:50:13 PM org.hibernate.util.JDBCExceptionReporter logExceptions SEVERE: ERROR: current transaction is aborted, commands ignored until end of transaction block org.hibernate.exception.GenericJDBCException: could not execute qu...

"where exists" in Hibernate HQL

Hello Overflowers, How can I write a "not exists" query in HQL? I am trying to get an HQL not exists query which returns the same results as this Oracle SQL query: select * from SCHOOL a where not exists (select 1 from STUDENT b where B.SCHOOL_ID=a.id and B.STATUS_ID not in (0,1,2,3,4)) My mapping files are below: <!-- prim...

Hibernate: Better monolithic class or many class maps?

I am making a website with GWT and using Hibernate to connect to the database. Every time a user loads a page and it is required to grab information off the database. Is it better to have monolithic classes containing all the getters/setters for the tables, and select the information as needed, or is it better to have many different cla...

Get distinct months from database using HQL

Hi I have a java.util.Date field in an @Entity and would like to get the distinct months from that column. Suppose I only had three rows, with 14/07/2010, 24/11/1975 and 03/11/1975 (European date format - day/month/year), I would like to get the following back from Hibernate to go into a dropdown for filtering the data: 07/2010 11/197...

Is there a simple workflow to generate a database schema from classes with hibernate mappings?

Id like to define my objects then use hibernate to generate my ddl from this. But it seems like the only real workflow with hibernate is to generate a datbase schema and then reverse engineer it. Am I wanting to do something that makes no sense? ...

Asking help for many-to-many properties persistence in Hibernate

Hi Buddies, Here I have a question about persist many-to-many properties. Example: class Movie { /** * @hibernate.bag cascade="save-update" table="movie_genre" * @hibernate.collection-key column="ITEM_ID" * @hibernate.collection-many-to-many column="GENRE_ID" class="Genre" * @hibernate.collection-cache usage="r...

How to configure JPA 2.0 with Hibernate 3.5.2 to use EHCache as a Level 2 cache and query cache?

I found some instructions how to configure pure hibernate to use EHCache. But I can't find any instructions how to configure JPA2.0 EntityManager to use cache. Hibernate 3.5.2 is my JPA2.0 provider. edit// Is @Cacheable(true) enough for entity? Or should I use @org.hibernate.annotations.Cache to configure the entity? ...

How to retrieve the java data types of columns from the database using Hibernate ?

I want to retrieve the java data types of the columns of a table in MySql using hibernate so that I can dynamically convert my input data to corresponding data type while inserting into database. One way is to read the class-name.hbm.xml and retrieve the data type information but I want the data types straight from the database and not ...

Stop Hibernate from creating not-null constraints

Is there a way to stop Hibernate from creating not-null constraints for properties annotated with @javax.validation.constraints.NotNull when using hbm2ddl = create? ...

proper hibernate annotation for byte[]

I have an application using hibernate 3.1 and JPA annotations. It has a few objects with byte[] attributes (1k - 200k in size). It uses the JPA @Lob annotation, and hibernate 3.1 can read these just fine on all major databases -- it seems to hide the JDBC Blob vendor peculiarities (as it should do). @Entity public class ConfigAttribut...

Deploying Grails on a Production Env. (Hibernate tries updating schema)

Hi there, I am deploying to a unix box running Jboss. We are using SQL Server 2008 as our database. Once deployed I push the changes by re-deploying the war to the environment. I see server.log has errors, seems hibernate tries to re-generate/modify tables already created. I am using dbCreate = "update" setting in my datasource.groov...

jpa 2 hibernate limit (max results) to a CriteriaQuery

Guys, maybe it's a silly question but I cannot find the answer in the docs: How can set a limit to the CriteriaQuery using JPA2? Thanks ...

Grails CXF plugin Webservice

Hi, I was wondering what is the best way to handle a request for an update on an existing entity (e.g. a Person) when receiving the request as a webservice request. In my project I have a Person domain class and I would like to expose CRUD operations as webservice operation through the CXF plugin. So I make a PersonService, and expose...

groovy / grails / hibernate - configure set to be fetched eagerly

We are configuring hibernate with grails using the domain classes. Added: static hasMany = [image:Image] static fetchMode = [image:"eager"] However, when I pull the object graph each image is not loaded. Please advise. Thanks. ...

How to get over limitations of the Hibernate Criteria and Example APIs?

I'm in a position where our company has a database search service that is highly configurable, for which it's very useful to configure queries in a programmatic fashion. The Criteria API is powerful but when one of our developers refactors one of the data objects, the criteria restrictions won't signal that they're broken until we run ou...