hibernate

Deep Object Graphs Hibernate

Our domain model is very tightly coupled and some classes that are mapped with hibernate are 6 collections deep. Currently we don't use lazy loading for these since the business layer passes some of the higher level classes around and retrieves some of their lower level children at which time the session will have been closed. Retrieving...

Hibernate disable Query Cache

Following problem: I create a Query to display all Entries of a MYSQL Table, if I edit a Field and execute the Query again I get the same (old) Result as in the first query. It seems that Hibernate caches the Result. I tried to disable Caching with query.setCachable(false) "hibernate.cache.use_second_level_cache" "cache....

How to set default value in Hibernate

How do I set default value in Hibernate field? ...

Hibernate - Return collection of entities by ID knowing only the class

How do I load a collection of entities of a given class, with only a single trip to the database, e.g.: public Collection<Object> getEntities(Class<?> entityClass,Collection<Serializable> listOfIDs); I know that if I were only wanting to fetch a single entity, I could use: sessionFactory.getCurrentSession().get(Class,Serializable); ...

Sping-Hibernate question

I have been handed a large Spring-Hibernate project and have been told to go through the code and figure out how it works. I have been able to run the project in JBoss and access pages locally, but I have no idea how to figure out how the program is layed out, as I have no web programming experience. I have been told that it is "pretty...

Controlling generated setting on property in NHibernate

I have a case where one of the columns on the database is generated using a trigger because of a specific way we generate this value which I can't change. If I in my mapping in NHibernate sets the property to generated=insert, it works like a charm, where NHibernate inserts the row without the generated property, and afterwards does a se...

Have Oracle automatically roll back abandoned sessions?

Is there any way to guarantee that an application won't fail to release row locks in Oracle? If I make sure to put commit statements in finally blocks, that handles the case of unexpected errors, but what if the app process just suddenly dies before it commits (or someone kicks the power cord / lan cable out). Is there a way to have Ora...

Hibernate cannot find my Entity classes which are in a separate jar file.

My persistence.xml is located in A.jar and entity classes are in B.jar. When trying to create a query using entity manager (from A.jar), I got exception saying it cannot find NamedQueries. However, named queries are listed on the entity class using annotation. Tried to use <jar-file/> to include B.jar in persistence.xml, but it doesn't ...

hibernate hql getMaxVersion

I have a table with the following structure: ReportId Version Title ..... I want to use HQL to fetch the newest version of the report by id. Would the following query work? from Report where reportId = :reportId and version = (select max(version) from Report where reportId = :reportId) Is it possible to retrieve the row with the...

generate service /dao layer for GWT/Spring/Hibernate/PostgreSQL

We're developing a webapp using GWT 2.0(not to AppEngine), Spring and Hibernate and trying to jumpstart by auto-generating as much code as possible. I've looked at http://stackoverflow.com/questions/1963672/spring-roo-vs-appfuse-generate-service-dao-layer. I tried appfuse but that did NOT work for me; Also, roo for GWT is not quite ther...

JPA mapped model returns null elements with Composite-Keys

I have build my data model using JPA and am using Hibernate's EntityManager 3 to access the data. I used HSQLDB for testing (junit). I am using this configuration for other classes and have had no problems. However, the latest batch of tables use a composite-key as the primary-key and I am not able to retrieve the populated row from...

Is it poor design for DAOs to manage transactions?

I've been reading about the sun blueprint GenericDAO implementation and Gavin King's take on this for use with Hibernate. It seems he doesn't mention anything about transaction handling: public abstract class GenericHibernateDAO<T, ID extends Serializable> { protected Session getSession() { return HibernateUtil.getSessionFac...

Hibernate 2nd level cache ObjectNotFoundException with a high number of concurrent transactions

We have a Java application that uses MySQL, Hibernate (3.5.1-Final) and EHcache(1.2.3) for our 2nd level cache. Our hibernate.properties isolation level is Read-committed isolation = 2 # 2-Read committed isolation hibernate.connection.isolation=2 Under a high number of concurrent transactions, we're seeing an issue where certain col...

JPA EntityManager createQuery() with IN not working

About to kill myself here. This is failing: List<String> names = new ArrayList<String>(); names.add("sold"); Query query = em.createQuery("FROM PropField propField WHERE propField.name IN (?)"); query.setParameter(1, names); List<PropField> fields = query.getResultList(); And so is this: List<String> names = new ArrayList<String>();...

Options for using Spring, Hibernate, JPA, and Tomcat with multiple Databases

I have a java web app running under Spring 2.5.6, Hibernate 3.4 (with Hibernate as the JPA provider), and Tomcat 6. I have it working with one DB schema / persistence unit but now need to connect to 2 schemas / persistence units. Can I do this without moving to a J2EE container such as JBoss or Glassfish? Will I need to use something lik...

HQL - find entity where property x is highest

Can HQL queries do this? "get the UserEntity where the property creationTimestamp is the most recent of all UserEntities". Essentially a query to return the "newest user" in our program where each UserEntity has a field mapped to a timestamp column in our database. ...

Difference Between One-to-Many/Many-to-One and Many-to-Many?

Ok so this is probably a trivial question but I'm having trouble visualizing and understanding the differences and when to use each. I'm also a little unclear as to how concepts like unidirectional and bidirectional mappings affect the one-to-many/many-to-many relationships. I'm using Hibernate right now so any explanation that's ORM rel...

How can I lose my layout when adding Hibernate support to Tapestry?

So, I've started going through the tutorial on the Tapestry site. All fine, the application runs, and I get the starting page. But, the moment I add the libraries to my POM, and the project gets refreshed, I lose my Layout component, and all the 'properties', (So message:greet doesn't work anymore). How does this work? And more import...

Dozer mapping for hibernate entity class to any new object type.

How to convert hibernate entity class having many to many mapping. i have a class that has two many to many collection mapping. i can convert that entity class to the destination object but the problem is for the collection set Set<Address> s; -----------1 1 there is a generic set of Address class.And the Address class look like be...

Hibernate collection fetching optimally

I have the following structure Store Rebate RebateMetadata RebateCommission So, the relation is like this - Store -> Rebate is a one to many relation Rebate -> RebateMetadata is a one-to-one mapping Rebate -> RebateCommission is a one-to-one mapping My Query is to load all stores. And with it, load all Rebates ...