hibernate

Grails/Hibernate Database crashes under load: Unable to connect (even when pooling)

I have an application in Grails. I use Hibernate to access the database (per standard grails rules) I use MySql and the site works and is stable (for 6 months). I am doing load testing, and recently discovered that the database rejects connections when under load. Using MySQL Server 5, I can see threads connected hovering around 20. Th...

JPA Implementations - Which one is the best to use?

Hi all, I have made use of the following JPA implementations: Hibernate, Toplink, OpenJPA Each of them has their own strengths and weaknesses. I found Hibernate the most advanced of the three except that it mixed some of its own enhancements with JPA which made it difficult to switch out to other providers. Most importantly, its que...

How to solve lazy initialization exception using JPA and Hibernate as provider

I am working on a project for a customer who wants to use lazy initialization. They always get "lazy initialization exception" when mapping classes with the default lazy loading mode. @JoinTable(name = "join_profilo_funzionalita", joinColumns = {@JoinColumn(name = "profilo_id", referencedColumnName = "profilo_id")}, inverseJoinColumn...

How do synchronized static methods work in Java?

If I have a util class with static methods that will call hibernate functions to accomplish basic data access. I am wondering if making the method synchronized is the right approach to ensure thread-safety. I want this to prevent access of info to the same DB instance. However, I'm now sure if the following code are preventing getObject...

Hibernate Next/Previous Sibling Mapping

I'm using nHibernate to map an object very similar to .NET's System.Web.SiteMapNode. In order to keep my object similar to this .NET object I would like to have it contain a ParentNode, PreviousSibling, NextSibling, and ChildNodes complex properties. The table looks somewhat like this and is open to be changed: ID (int) Title (string...

SQL query throws "not in aggregate function or group by clause" exception

I'm working on repairing the test suite for a project of ours, which is being tested through Hibernate/DBUnit. There are several test cases which all throw a similar exception from Hibernate, which looks something like this: java.sql.SQLException: Not in aggregate function or group by clause: org.hsqldb.Expression@109062e in statement ...

Hibernate not respecting MySQL auto_increment primary key field

Hello, I am trying to learn how Hibernate works, and I am running into an almost unacceptable learning curve. I can't see how to get Hibernate to respect the auto_increment policy for my objects. Instead, it is overwriting entries in the database with existing IDs, beginning with 1. I have a simple Foo object, backed by a MySQL table d...

NHibernate: Audit logging using Interceptor or Triggers?

Triggers seems like a simple solution for Audit logging. Why should I use Interceptors? Database portability is one con of trigger... what are others? ...

NHibenate cascade problem.

Hi I'm having a problem updating child objects in the following scenario. The mappings are as follows: Parent: Calendar <bag name="defaultCategories" inverse="true" lazy="false" cascade="all-delete-orphan"> <key column="parentID" /> <one-to-many class="DefaultCategory"/> </bag> Child: DefaultCatergory <class name="Def...

HQL for finding starting index of objects in a predefined order?

Using HQL, I would like to search for the starting index of sequenced objects. For example, if I have the following persisted classes: <class name="Word"> <id name="id" type="int"> <meta attribute="scope-set">protected</meta> <generator class="native"/> </id> <many-to-one name="sentence" class="Sentence"/> <property name="...

Does between in HQL compare strictly or not?

if I write in HQL A between 5 and 10 is that equivalent to A >= 5 and A <= 10 or A > 5 and A < 10 or some other of the 4 combinations? ...

Where can I find a list of all HQL keywords?

Where can I find a list of all HQL keywords? ...

JPA reserverd keywords to postgres

I'm using JPA with a postgres DBMS and I'm trying to create a new entity that maps to the table "User". This is a very common problem as User is a reserved word in Postgres. My question is, how can i "escape" the reserved keyword or set JPA to escape it? I tried @Table(name = "\"user\"") with no luck: 2009-02-25 15:43:14,218 ERROR...

How do I write a HQL Query for this?

I want a single HQL query that returns all groups containing a given user that where created before a given date. Somehow I can't get it right. public class Group { @ManyToMany Set<User> users; Date created; } public class User { ... } ...

Do you know of pmd or checkstyle definition files that will enforce hibernate best practices?

For example, not to build queries by string manipulation, and the like. ...

Inserting an object to the db using hibernate, only if it doesn't exist

Let's say I have a mapped User object with a user_id as a primary key, and a mail column with a unique constraint. I want my program to save a User object to the users table only if it doesn't exist. I can do the following thing in my insert function: begin transaction query for a user with the given mail if it doesn't exist, create a...

JPA: please help understanding "join fetch"

I have the following entity structure: Business --> Campaign --> Promotion, where ONE Business can have MANY Campaigns and ONE Campaign can have MANY Promotions. Both one-to-many relations are declared as LAZY. One place in my code, I need to eagerly fetch both collections from a Business, so I do: Query query = entityManager.create...

How to remove trailing whitespace in a database column?

I have an EJB 3 Entity bean that has a String property annotated with: @Column(unique=true). This value is set from a JSF page. Everything works fine as long as the user does not add whitespace add the end of the input field. In that case "someName" and "someName____" are treated not unique and are stored in the database. Is there a con...

Is it possible to use hibernate as Glassfish's persistence provider?

Is it possible to use hibernate as Glassfish's persistence provider and if so HOW? ...

Hibernate Annotations - Which is better, field or property access?

This question is somewhat related to http://stackoverflow.com/questions/305880/hibernate-annotation-placement-question. But I want to know which is better? Access via properties or access via fields? What are the advantages and disadvantages of each? ...