hibernate

Asynchrous calls cause StaleObjectStateException

Hi all, I'm struggling with a Grails service. The service gets AJAX calls from the clients and behaves like a simple local cache for remote objects: void **someCallFromClient**() { // extract params def results = remoteService.queryService(params) results.each{ // try to fetch result object from local DB def obj = Some...

Using SQLQuery.uniqueResult() to perform native SQL INSERTs and UPDATEs

I am using Hibernate in my project and there is a certain scenario where I want to use the uniqueResult() method on the org.hibernate.SQLQuery class to perform native SQL INSERT and UPDATE operations. I did try using the executeUpdate() method on the same class. But I get an error saying that they are used for HQL updates only. Please ...

Lost with hibernate - OneToMany resulting in the one being pulled back many times..

I have this DB design: CREATE TABLE report ( ID MEDIUMINT PRIMARY KEY NOT NULL AUTO_INCREMENT, user MEDIUMINT NOT NULL, created TIMESTAMP NOT NULL, state INT NOT NULL, FOREIGN KEY (user) REFERENCES user(ID) ON UPDATE CASCADE ON DELETE CASCADE ); CREATE TABLE reportProperties ( ID ...

How to convert slightly different tables?

Is there a way to convert table entries from an old table to a new one using the same entity class? To be specfic, here are my entity class' annotations for the new table: @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @Basic(optional = false) @Column(name = "benutzer_id") private Integer benutzerId; @Basic(optional = false) @...

Getting the object with the highest member value in hql?

I'm still a little new to hql, and I had a question about aggregation functions and efficiency for a query I'm writing. Let's say I have this class mapped in hibernate (getters/setters/constructors/etc. omitted for brevity): public class Foo { private int i; private String s; private float f; } I want to do a hql query ...

CascadeType problem in One to Many Relation

Hi I have two classes which have a Unidirectional One to Many relation with each other. public class Offer{ ... @OneToMany(cascade=CascadeType.ALL) @JoinTable(name = "Offer_Fields", joinColumns = @JoinColumn(name = "OFFER_ID"), inverseJoinColumns = @JoinColumn(name = "FIELDMAPPER_ID")) private Set<FieldM...

Using hibernate with annotations, i want a one-many relationship to be sorted

Using hibernate with annotations, i want a one-many relationship to be sorted by the 'created' field on the 'many' table. So far i've got this, which always ends up in a random order: // The notes @OneToMany @JoinColumn(name="task_id") Set<TaskNote> notes; public Set<TaskNote> getNotes() {return notes;} public void setNotes(Set<TaskNo...

How to lock a transaction for reading a row and then inserting in Hibernate?

I have a table with a name and a name_count. So when I insert a new record, I first check what the maximum name_count is for that name. I then insert the record with that maximum + 1. Works great... except with mysql 5.1 and hibernate 3.5, by default the reads don't respect transaction boundaries. 2 of these inserts for the same nam...

Choose 'better' or more familiar technologies for a new project?

I am looking to start work on a brand-new project, something I've been thinking about for a while as my first independent sellable project. It's broadly speaking a web-based service application, and my first choice, server-language is quite easy... I know Java pretty well from working on Java web-apps in the past. However my experience ...

Does Hibernate3.5 support JPA1+EJB3.0 on GlassfishV2?

Hi All, Can I use newest version of hibernate 3.5 (3.5.0-3.5.2) as JPA1 provider with EJB3.0 on Glassfishv2? I tried, but hibernate 3.5 required JPA2 spec and obviously this did not work with GFv2. Thanks, Anton ...

hibernate query language or using criteria

Any one who tell me the query using criteria/hql/sql. Requirement is that user enter email or username the query return the password of the user from table user. ...

Hibernate Auto-Increment not working

I have a column in my DB that is set with Identity(1,1) and I can't get hibernate annotations to work for it. I get errors when I try to create a new record. In my entity I have the following. @Entity @Table(schema="dbo", name="MemberSelectedOptions") public class MemberSelectedOption extends BampiEntity implements Serializable { ...

JPA Date Arithmetic?

Is it possible to perform date arithmetic using JPA/Hibernate? For example, I have an entity with a java.util.Date field indicating when the row was created. Is it possible to perform a query using JPQL and include date arithmetic on that field? For example, can I perform a COUNT(*) of rows and then GROUP BY the month in that field? ...

Recommendation for using equals in Entities and avoiding LazyInitializationExceptions?

In the beginning there is a problem that wants to be solved. In my case i got an LazyInitializationException while using indexof in a Collection to retrieve an Object for manipulation. Here i start to think about using equals in EntityBeans (OR-Mapper at all). I know there are some discussions about overriding equals in association with ...

tool for translate multi-table queries -> single table queries

Hi. I'm trying to find something to help me with y problem. Now I'm changing the strategy. What I need is to build (because I think there is nothing like this) a tool that take a query, a multi-table select, and translate all this in many single table queries. Does anybody has any idea about how hibernate does that (based on the dialect...

Hibernate subclass with foreign key relationships

I need some help defining the following object hierarchy/ database relationship in Hibernate From the object sense – Agent is inherited from Person and Agency is inherited from Organization. they are inherited from Party which can have multiple Addresses associated with it The database consists of Agent -ID -Name -PartyID (referenc...

Alright to truncate database tables when also using Hibernate?

Is it OK to truncate tables while at the same time using Hibernate to insert data? We parse a big XML file with many relationships into Hibernate POJO's and persist to the DB. We are now planning on purging existing data at certain points in time by truncating the tables. Is this OK? It seems to work fine. We don't use Hibernate's s...

Simple CMS to manage existed project on JAVA (Spring+Hibernate)

Can anybody suggest simple CMS to manage existed project on JAVA (Spring+Hibernate). I need simple CRUD operations for Hibernate Mapping objects (annotations based mapping). ...

netbeans + hibernate for java swing application

Hi all, im developing a java swing app and i would use hibernate for persistance. Im totally new in jpa, hibernate and ORM in general. Im follow this tutorial, its easy but the problem is the java class that descrive a table in db are made from the table with reverse enginering. I want do the opposite process: i want make db table from...

Updating counters through Hibernate

This is an extremely common situation, so I'm expecting a good solution. Basically we need to update counters in our tables. As an example a web page visit: Web_Page -------- Id Url Visit_Count So in hibernate, we might have this code: webPage.setVisitCount(webPage.getVisitCount()+1); The problem there is reads in mysql by defaul...