hibernate

Retrieve all Foo from Hibernate second level cache without a query cache?

In his excellent blog post "Hibernate query cache considered harmful?" Alex Miller (of Terracotta Inc.) explains why using the query cache can be harmful to latency and scalability. My question is: is it possible to write a 'get all' DAO method for a particular domain object type that uses the second level cache without having a query c...

HQL Bug and nullable fields.

Why does this query NOT work FROM WorkflowConfiguration WHERE ((saReplacement IS NOT NULL) AND (:currentTime >= saReplacement.start) AND (saReplacement.end >= :currentTime)) OR ((hrmsAdminReplacement IS NOT NULL) AND (:currentTime >= hrmsAdminReplacement.start) AND (hrmsAdminReplacement.end >= :currentTime)) OR ...

Hibernate Criteria contains-in on an association to a table

Good day, I have a Hibernate mapping that looks something like this: <class name="MyEntity"> <set name="scalarSet" table="(select fk, scalar_value from other_table)"> <key column="fk"/> <property column="scalar_value" type="long"/> </set> </class Given this, how do I query such that a value of MyEntity.scalarSet (which is...

Sorting on multiple fields with criteria in Grails

Hi, I have the following query which id like to sorty by "raceDate" and by "raceNo" asc. I can figure out how to sort by one field, but not by two, any ideas? def list = { params.max = Math.min( params.max ? params.max.toInteger() : 20, 100) params.offset = params?.offset?.toInteger() ?: 0 params.sort = "raceDate" ...

Which hibernate adapter should I use to handle Lazy Initialization in BlazeDS / Spring integration projects with Flex?

I'm researching ways in which the Spring Framework, Hibernate and BlazeDS can play happily together without throwing lazy initialization exceptions. So far, I ran across Gilead, dpHibernate and an entirely different alternative implementation of this problem via GraniteDS's Tide framework. Aside from GraniteDS, there doesn't seem to ...

Hibernate deleting orphans when updating collection

Hi I'm finding that orphan records aren't being deleted when removing from a collection in Hibernate. I must be doing something simple wrong, (this is Hibernate-101!), but I can't find it.. Given the following: public class Book { @ManyToOne @NotNull Author author; } public class Author { @OneToMany(cascade={CascadeTy...

How can I replicate "SHOW TABLES" in Hibernate?

I'm trying to iterate over all of my tables so I can truncate each one (at the beginning of each of my JBehave tests). I thought I would be able to: List<String> allTables = session.createSQLQuery("SHOW TABLES").list(); But hibernate throws a SQLGrammarException, complaining that "Column 'TABLE_NAME' not found." I guess this is beca...

Hiding deleted objects

Hi I have the following use case: There's a class called Template and with that class I can create instances of the ActualObject class (ActualObject copies its inital data from the Template). The Template class has a list of Product:s. Now here comes the tricky part, the user should be able to delete Products from the database but thes...

Mapping to varchar and nvarchar in hibernate

If there are 2 columns in database, eg. code varchar(3) name nvarchar(50) how to tell hibernate to pass varchar for searching by code? In the hibernate mappings string is mapped to nvarchar and it produces queries like: Select code, name From table where code=N'AAA' (instead of code='AAA') This is very bad as it causes index scan i...

Hibernate unidirectional one to many association - why is a join table better?

In this document (scroll down to the Unidirectional section): http://docs.jboss.org/hibernate/stable/annotations/reference/en/html_single/#entity-mapping-association-collections it says that a unidirectional one-to-many association with a join table is much preferred to just using a foreign key column in the owned entity. My question i...

Which pattern does Hibernate follow?

In his book "Patterns of Enterprise Application Architecture", Martin Fowler talks about persistence patterns which are commonly found in software development and particularly in relation to ORMs. Is there a pattern that Hibernate adheres to most closely? ...

Use a Criteria on top of another Criteria

I have a question on criteria: How can i use a Criteria (or similar) that filters and/or do whatever with another criteria? Something like: select clients.* from (select * from clients) as clients The real problem is something else, but achieving this behaviour would be terrific... (btw, both java and .net are welcome to help) ...

Hibernate, get datas from both tables in a join statement

I want to use below code and want to get datas from both tables, but how? There aren't any association in my hibernate mapping files. SQLQuery query = session.createSQLQuery("SELECT cat.* from cat inner join owner on cat.owner_id = owner.id where owner.name=:username"); query.addEntity(Cat.class); query.setInteger("username",'Duke');...

Hibernate @OneToMany without a separate join table

Consider the following database schema: create table UserGroup ( id int not null auto_increment, name varchar(200), primary key(id)); create table User ( id int not null auto_increment, name varchar(200), groupId int not null, primary key(id)); User.groupId = UserGroup.id, so a user can only be a member of one group, but a usergroup ...

Joining two tables over a compound index in Hibernate

I have Entity A - type - uniqueKey and Entity B - uniqueKey and i dont know how to integrate it into hibernate that i can produce results like from this query: select * from A left join B on B.uniqueKey = A.uniqueKey and A.tpye = 1 where A.id is null this will produce a result that has all the entries of B that are not in A fo...

Hibernate Exception Fixed By Alt+Tab

Hi all, I've got a very curious problem in Hibernate that I would like some opinions on. In my code if I do the following: Go to page A Click a link on page A to be taken to page B Click on data item on page B Exception thrown I get an error telling me: failed to lazily initialize a collection of role: XYZ, no session or session w...

many-to-many the same PK

How should I do if I have two tables and their primary keys have the same name like the following XML mapping file suggests? <class name="Person" table="person"> <id name="uid_" type="java.lang.String" column="uid"> <generator class="native" /> </id> <property name="name_" type="java.lang.String" column="pName" /> ...

Hibernate save to get sequences a second time.

I have a class like this (with getters and setters, all mapped to hibernate, each with a sequence to oracle DB) public class A{ private B b; private C c; } i'm creating this object and saving it to the database. So i create an A object and populate it with a B object and call saveOrUpdate(a) so i can have "a" and ...

Persist classes with inheritance using Gilead

I'm using Gilead to persist my entities in my GWT project and I've run into an issue. I'd like to create a parent class to hold some properties that are common throughout my entities (id, etc). When persisting I get a null pointer exception. Parent class: public abstract class Entity extends LightEntity implements Serializable { ...

How to do JoinTable annotation mapping

Hi Gurus, I have a design/programming question. First I wanna ask if my design is good and then I wanna know how to. What I wanna do is to have an i18n page, which may or may not have a translation. e.g. Page A has English & Japanese, and Page B may only have English This is the DB layout page ---- id int topic varchar(128) content v...