hibernate

NHibernate: HQL equivalent of Criteria Expression.In()?

How would you express the following Criteria query in HQL? var idArray = new int[] { 1, 2, 3, 4, 5 }; Session.CreateCriteria(typeof(Foo)) .Add(Expression.In("Id", idArray) .List<Foo>(); I am aware of that there is an "in" keyword in HQL, but as I understand it that keyword is for use with subqueries rather than something like...

Hibernate: Persist an object as a String?

Suppose I have an object like public class Handle { private String handle; public Handle(String name) { this.handle=name; } public String toString() { return this.handle; } } that is a property of some POJO that I would like to persist with Hibernate. How do I define the mapping for my POJO such tha...

How can I inherit Hibernate filters with annotations?

I'm trying to set up a Hibernate filter with annotations. I would like to specify it in a base class and make all sub classes use it but whenever I try to enable it, Hibernate fails to find the filter. Is it possible at all to inherit filter annotations? ...

Spring MVC, generating a form backing object from a request?

I am using Spring MVC 2.5, and I am trying to get a JSTL form object to load from a GET request. I have Hibernate POJOs as my backing objects. There is one page directing to another page with a class id (row primary key) in the request. The request looks like "newpage.htm?name=RowId". This is going into a page with a form backing object...

Hibernate uses initial WHERE clause in subsequent queries

In using Hibernate's JPA implementation, I noticed an interesting optimization behavior. Within the same transaction, the initial JPA query's WHERE clause is used for subsequent queries involving the results of the initial query. For example, person has lastName and a set of owned books. // (1) get person by last name Query q = entityM...

hibernate object vs database physical model

Is there any real issue - such as performance - when the hibernate object model and the database physical model no longer match? Any concerns? Should they be keep in sync? Our current system was original designed for a low number of users so not much effort was done to keep the physical and objects in sync. The developers went about ...

org.hibernate.annoatations vs. javax.persistence

Is it a bad idea to use the annotations from the javax.persistence package instead of using the org.hibernate.annotations annotations I know that using javax.peristence does introduce yet another dependency. But if I ignore that, what are the pros/cons? ...

Treat '0',"-1" as Null

I am working with a large, old database and i now try to access it with hibernate instead of SQL. One of the larger Problems with this is the use of "0" and "-1" (meaning "NULL") in foreignKeys without constraints. I had much of the code generated, but i add the joins manually. Like this @OneToMany(fetch = FetchType.EAGER) @JoinColum...

MultiFieldQueryParser only gives results when fields don't include the class name. is it possible to include them?

I'm working with hibernate search and I think I'm almost done implementing it except for this one issue. The problem is I don't get any results if the fields I pass into the MultiFieldQueryParser include the class name. I get the expected results when the fields just include the field name. String[] fields = {"bar.title", "foo.descript...

hibernate mapping file with dependancies to existing tables/POJOs

We have an existing and working database created from hbm mapping files. We want to create some new tables for an optional feature. One option is that these new tables always exist but we would prefer for the tables and POJOs to only be created on request. My issue is that these tables/POJOs have dependancies on existing tables/POJOs....

Manipulating Hibernate 2nd Level Cache

I am using hibernate as my ORM solution, with EHCache as the Second Level (Read-Write) cache. My question is: Is it possible to access the Second Level cache directly? I want to access this: http://www.hibernate.org/hib_docs/v3/api/org/hibernate/cache/ReadWriteCache.html How can I access the same ReadWriteCache that is being used b...

Spring Hibernate SQL Query

I have a VO class which has the getter and setter of another VO class too. For example: Class DocumentVO{ PrintJobVO job; PrintRunVO run; String id; getters and setters.. } Now I have a requirement to use the Native SQL Query using spring hibernate. When I want to map the ids I have a problem. My query is, select {r.*},{d...

HSQLDB Internals: Hibernate and Integer vs Long Ids

I am creating database Entities in my Java application and trying to rationalize between using an Integer or a Long as the class type of the "id" field. I am using Hibernate as my ORM which, in turn, will map this field to a column in the HSQLDB database. My struggle is this: a Long is obviously larger and will handle a greater number o...

How do you remove rows after changing the item in a JPA OneToOne relationship?

How do you get a OneToOne item to automatically remove with JPA/Hibernate? I would expect simply setting the OneToOne item to be null in the class that contains would be smart enough to allow Hibernate to delete it. Given a simple object, simplified: @Entity public class Container { private Item item; @OneToOne(cascade=Cascad...

Spring MVC form:select Tag, multiple selections not binding correctly?

I am trying to create a form to edit an existing database row. I am using the Spring MVC form tag to auto bind the html to a form backing object. The row has a many to many relationship with another table, which I am trying to represent with a multiple select box using the form:select tag; <form:select path="rules"> <form:options items...

Hibernate: Mapping One-way Redundant Columns

In my schema there are a few redundant columns used to speed up report queries. For example, the purchase total of a sale is saved in the "purchase_total" column of the "sale" table, yet in the model, it is calculated dynamically by adding up the sold price of each item purchase in the sale. This value can be retrieved by calling the "g...

Attaching an identifier to an Oracle session

My Java application uses db sessions, via Hibernate. What I want to do is somehow, when I create a session in my app, is to identify that session as an 'application' session. The reason is that I wish (via a before trigger) to restrict the updates that users can make to a table, while giving the application carte-blanche to do what it l...

Hibernate Criteria Query API

I assume that the following is a no no(?) > public Criteria createCritera(Class<?> persistentClass) { > ...//creation of session object etc. > session.beginTransaction(); > Criteria crit = session.createCriteria(persistentClass); > session.getTransaction().commit(); > session.close(); > > return crit; } ...

Problem using @SecondaryTable in Hibernate

Abridged version of my schema: utility_company id int not null -- PK name varchar(255) not null utility_settings utility_id -- FK to utility use_magic tinyint(1) not null default 0 There is a one-to-one mapping between these two tables. Setting aside the fitness of this design, I want to Map the data in both of these tables to one o...

Hibernate: ThreadLocalSessionContext: Already session bound on call to bind()

When I try to use the ThreadLocalSessionContext in the following way: Session hsession = HibernateUtils.getSession(); ThreadLocalSessionContext.bind(hsession); // do stuff hsession.close(); I do this for every single Struts Action. Is there something I am doing wrong, causing me to get the following error? [ThreadLocalSessionContext]...