hibernate

Hibernate Subquery and DetachedCriteria

I have created a DetachedCriteria that is retrieving estates that have the isApproved and isPublished set to true. It is defined in this way: DetachedCriteria activePublishedCriteria = DetachedCriteria.forClass(Estate.class) .add(Restrictions.eq("isApproved", true)) .add(Restrictions.eq("isPublished", true)) .setResultTransf...

Projections for Collections and Nested Projections

Hi, The first part is HOW TO PROJECT COLLECTIONS? Can We apply projections on collection elements? For e.g class User{ private address List<Address>; } class Address{ private String city; private String state; } Now can I just load the address attribute of User class? Using code like : criteria.setProjection(Proje...

hibernate3-maven-plugin: entiries in different maven projects, hbm2ddl fails

I'm trying to put an entity in a different maven project. In the current project I have: @Entity public class User { ... private FacebookUser facebookUser; ... public FacebookUser getFacebookUser() { return facebookUser; } ... public void setFacebookUser(FacebookUser facebookUser) { this.facebookUser = facebookUser; } Then Fa...

Hibernate Envers : How to delete entries from my audit table?

Hi everyone, I am currently working with Hibernate Envers. My problem is the following : How to delete entries in the audit table related to the entity I want to delete? My entity has no relation with other entities. I figured out that I have to do that in onPostDelete method of my custom listener : import org.hibernate.envers.event...

Postgresql & xml type with hibernate

Hi, In a table, we are using the type xml for a field. But the mapping with hibernate with string doesnt work. It seems that we have to write a custom type to store it by using postgres driver utils. I cant find this mapping on google and here. Anyone have ever write a mapping to the xml type for hibernate & will share it here please...

Can I bypass an intermediate object in hibernate

I have top level entities TRACK, MEDIA_GROUP and MEDIA, each with an integer primary key. I also have a join table from TRACK to MEDIA_GROUP which is 1:1 and MEDIA has a FK column into MEDIA_GROUP. I'm trying to find a way in hibernate to map a collection of Media directly into the Track object, bypassing the creation of a MediaGroup o...

common problem with Hibernate/NHibernate and child IDs

I'm asking both Hibernate and NHibernate groups because I'm thinking this may be a common issue seen on both. What does it usually mean when you call a saveOrUpdate on a child object and... 1) If it is an insert everything works fine. 2) If it is an update its wiping out the parent ID in the database. More info: problem is really occur...

Reuse Hibernate session in thread

Hello, I've read somewhere that when a session is flushed or a transaction is committed, the session itself is closed by Hibernate. So, how can i reuse an Hibernate Session, in the same thread, that has been previously closed? Thanks ...

Hibernate Native Query problem with named parameters

I have a problem with Hibernate Native Query. I have one SELECT that selects array slice (PostgreSQL database). The problem is that hibernate recognizes the following part: ":300" from "SELECT my_array[1:300]..." as named parameter and I get the following exception: Not all named parameters have been set. I tried to escape the colon (:...

migrate database from sybase to mysql

I have been trying to migrate a database from sybase to Mysql. This is my approach: Generate pojo classes from my sybase database using hibernate in eclipse Use these pojo classes to generate the schema in mysql database Then somehow migrate the data from sybase to mysql I guess this approach should work??? Please let me know if the...

Joining tables with composite keys in a legacy system in hibernate

Hi, I'm currently trying to create a pair of Hibernate annotated classes to load (read only) from a pair of tables in a legacy system. The legacy system uses a consistent (if somewhat dated) approach to keying tables. The tables I'm attempting to map are as follows: Customer CustomerAddress -------------------------...

How to retrieve row count of one-to-many relation while also including original entity?

Say I have two entities Foo and Bar where Foo has-many Bar's, class Foo { int ImportantNumber { get; set; } IEnumerable<Bar> Bars { get; set; } } class FooDTO { Foo Foo { get; set; } int BarCount { get; set; } } How can I efficiently sum up the number of Bars per Foo in a DTO using a single query, preferrably only with the Cr...

Changing the Hibernate 3 settings

I use Hibernate3 and Hibernate Tools 3.2.4 to generate hbm.xml and java files and I want to use List instead of HashSet(...). I've tried to modify the hbm.xml files, putting list instead of set. Is there any way to specify to hibernate tools that I want to generate automatically a list not a HashSet? This is an exemple: Java class publ...

Java/Hibernate using interfaces over the entities.

I am using annoted Hibernate, and I'm wondering whether the following is possible. I have to set up a series of interfaces representing the objects that can be persisted, and an interface for the main database class containing several operations for persisting these objects (... an API for the database). Below that, I have to implement...

How to use a int2 database-field as a boolean in Java using JPA/Hibernate

Hello... I write an application based on an already existing database (postgreSQL) using JPA and Hibernate. There is a int2-column (activeYN) in a table, which is used as a boolean (0 => false (inactive), not 0 => true (active)). In the Java application i want to use this attribute as a boolean. So i defined the attribute like this: @E...

merging / re-attaching IN JPA / Hibernate without updating the DB

Working with JPA / Hibernate in an OSIV Web environment is driving me mad ;) Following scenario: I have an entity A that is loaded via JPA and has a collection of B entities. Those B entities have a required field. When the user adds a new B to A by pressing a link in the webapp, that required field is not set (since there is no sensib...

Hibernate Criteria API equivalent to HQL select clause?

I'd like to have a combined query for two persistent classes. In HQL this could be achieved by the select clause, select new Family(mother, mate, offspr) from DomesticCat as mother join mother.mate as mate left join mother.kittens as offspr In the above example, Family is a conbined class with DemesticCat as its c...

Hibernate @PostLoad problem

Looked at many forums but haven't found answer...Simple stuff, method annotated with @PostLoad newer gets invoked...added listener via @EntityListeners but problem remains. I'm using SessionFactory based configuration. ...

Hibernate: Mapping result set of native query with @SqlResultSetMapping

I'm trying the following: MyResult.java : import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.EntityResult; import javax.persistence.SqlResultSetMapping; @Entity @SqlResultSetMapping(name = "myResults", entities = {@EntityResult(entityClass = MyResult.class)}) publi...

Mapping a boolean[] PostgreSql column with Hibernate

I have a column in a PostgreSql database that is defined with type boolean[]. I wish to map this to a Java entity property using Hibernate 3.3.x. However, I cannot find a suitable Java type that Hibernate is happy to map to. I thought that the java.lang.Boolean[] would be the obvious choice, but Hibernate complains: Caused by: org.hiber...