hibernate

Performance difference of Native SQL(using MySQL) vs using Hibernate ORM?

I am using Spring MVC for an application that involved a multilevel back end for management and a customer/member front end. The project was initially started with no framework and simple native JDBC calls for database access. As the project has grown significantly(as they always do) I have made more significant database calls, sometime...

Hibernate: joining with one of the keys of a multi-keyed table

Hi guys, I've got a table Category and a table TranslatableText. The category is like this create table Category ( id int not null, parent_id int default 0, TranslatableDescriptionId int default 1, primary key(id)); create table TranslatableText ( id int not null, lang enum ('NO','EN','FR'), text mediumtext, primary ke...

Hibernate <set> key from joined table

I wonder if it's possible to define Set in Hibernate mapping in a such way, that element would specify not column in original (FOO) table, but in joined one (BAR). Let's say we have some FooContainer.hbm.xml, which contains Set of Foo objects: <set ...> <key column="COLUMN_FROM_BAR" /> <one-to-many class="xyz.Foo" /> </set> Here ...

Hibernate generating SQL queries when accessing associated entity's id

I have Hibernate Entities that look something like this (getters and setters left out): @Entity public class EntityA { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "parent_id") private EntityB parent; } @Entity public class EntityB extends SuperEntity { @OneToMany(mappedBy = "parent") @Fetch(FetchMode.SUBSE...

grails / groovy / cxf / jaxb - hibernate persisted entity marshalled as empty

Expecting grails domain object to be written to XML response: Image.groovy: @XmlRootElement @XmlAccessorType(XmlAccessType.NONE) class Image{ @XmlElement String url @XmlElement String contentType } WebServiceRequestHandler.groovy: @GET @Path("/myrestfullmethod/parameter1/{parameter1name} @Produces("text/xml") Images...

Hibernate returning another object

Hi guys, I have a query that looks like this Document document = DocDAO.getSession().read(someId); MyFile file = (MyFile) DAO.getSession() .createQuery("SELECT file FROM MyFile file WHERE file.document = :document AND file.version = :version") .setParameter("document", document) .setParameter("version", version) .uniqueResult(); Now,...

hibernate : howto order by custom (user-defined) function in PostgreSQL 8.4

We have a Family Hibernate Entity. This entity has(among others) 4 booleans properties. When retrieving the Families from the Postgres 8.4 DB, it is required that the List of families be ordered by sum of the boolean properties. There are 2 other fields in the order by criterion. Eg select fam.a, fam.b, fam.c, fam.d, fam.e from family...

Problem HIbernate + Mysql

I'm having the following problem. I have a survey which indicate the start / end of a given process. When I select the start date, everything works. When I put only the end date (and no other filter the search), here comes the problem. I have a monster delay in the research and the session falls Ext. My bank has about 250,000 registered...

Hibernate Criteria Subquery

Hi, I need to do this SQL query with detachedCriteria: SELECT g.id FROM games g WHERE NOT EXISTS ( SELECT 1 FROM users_games ug WHERE ug.user_id = 1 AND g.id = ug.game_id) The idea is to get the ids from the games that aren't owned by the user. I tried like 10 different approaches with detachedCriteria but I get the "Unknown entit...

jpa removing child from collection

Hi! I'm using JPA over Hibernate in my web-app. Here are two entities (only getters are shown): class Child { private Parent parent; @ManyToOne(optional=false) @JoinColumn(name="parent_id", referencedColumnName="parent_id", nullable=false, updatable=false) public Parent getParent() { return parent; } } class Parent { ...

javax.persistence.PersistenceException: No Persistence provider for EntityManager named customerManager

I am new to JPA & Hibernate. After reading some online materials I now understand what Hibernate is and how it can be used with JPA. Now, I am trying to run this JPA & Hibernate tutorial. I've done everything they mention in this tutorial. I don't have Oracle DB, only MySQL. So I made some changes to persistence.xml using my understand...

Hibernate - Criteria - bidirectional search with unidirectional mapping?

Could you tell me is possible to search by hibernate criteria on bidirectional direction with only unidirectional associations? For examle: I have two class: Box { Long id; Set parcels; Integer status; // other properites } Parcel { Long id; // other properties } I've got associations one-to-many in cl...

multiple databases in hibernate

Can any one send me the code to connect to multiple databases through hibernate. I desperately need it.. Thanks in advance. ...

Connecting the same database from two different web applications(GXT) using Hibernate

I am working with two different web applications built upon GXT. But the problem is that both the applications are accessing the same database and the hibernate is not allowing to do so when we tried to deploy together in Apache Tomcat and then access them simultaneously. Can you tell me how can we access the same database using hibernat...

Should I include main method for JPA?

Hi, For the last three days i am learning JPA by various examples, to change my JDBC code to JPA. Every JPA example and tutorial have main method to run it. Of course, in main method only they defining EntityManager & EntityManagerFactory. I dont have main method in my web application's server side code. Is that a problem in point of ...

Custom Hibernate NamingStrategy with singularized foreignkeys of many-to-many's

Hello! I'm trying to implement my own Hibernate NamingStrategy based on the ImprovedNamingStrategy. This is quite nice... only the foreign keys of many-to-many relations are ugly. Example scenario: public class Teacher { @ManyToMany private Set<Course> courses; } public class Course { @ManyToMany private Set<Teacher> ...

Hibernate simple criteria query solving problem

I'm stuck with a very simple criteria query problem: sess .createCriteria(user.class, "user") .user_c.add(Restrictions.eq("user.status", 1)) .user_c.createAlias("user.userCategories","ucs") .add(Restrictions.eq("ucs.category_id",1)); .add(Restrictions.eq("ucs.category_id",'yes')); .add(Restrict...

Hibernate - @ElementCollection - Strange delete/insert behavior

@Entity public class Person { @ElementCollection @CollectionTable(name = "PERSON_LOCATIONS", joinColumns = @JoinColumn(name = "PERSON_ID")) private List<Location> locations; [...] } @Embeddable public class Location { [...] } Given the following class structure, when I try to add a new location to the list of ...

get max value record from table in hibernate

Hi, How to get max value record from table in hibernate, advance in thanks ...

Unable to configure EntityManagerFactory

I am new to JPA & hibernate. In my web-app i have changed my JDBC codes to JPA. While running the web-app i am getting a BIG list of errors. But from my knowledge in JPA and Hibernate, I think the two errors below represent most of my problem. Unable to configure EntityManagerFactory 16047 [31149935@qtp-23671010-1] ERROR org.hiberna...