hibernate

Second level cache for java web app and its alternatives

Between the transitions of the web app I use a Session object to save my objects in. I've heard there's a program called memcached but there's no compiled version of it on the site, besides some people think there are real disadvantages of it. Now I wanna ask you. What are alternatives, pros and cons of different approaches? Is memcached...

How to do Grouping using JPA annotation with mapping given field

I am using JPA Annotation mapping with the table given below, but having problem that i am doing mapping on same table but on diffrent field given ProductImpl.java @Entity @Table(name = "Product") public class ProductImpl extends SimpleTagGroup implements Product { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private lo...

Jboss cache replicates no changes when used from Hibernate

We are using jboss cache as second level hibernate cache. It is configured to evict changed entities asyncronously. But this feature does not work for us. Some debugging revealed the root of the problem. When treecache accessed, it adds itself as transaction listener. This is done by adding Synchronization to active transaction inside o...

Hibernate: Querying objects by attributes of inherited classes

Hi all, I ran into a problem with Hibernate concerning queries on classes which use inheritance. Basically I've the following class hierarchy: @Entity @Table( name = "recording" ) class Recording { ClassA attributeSet; ... } @Entity @Inheritance( strategy = InheritanceType.JOINED ) @Table( name = "classA" ) public class Cla...

Hibernate design: persistent data plus temporary run-time classes

The question is this. I have a number of persisted objects that I'll pull using Hibernate. But during the application lifetime I'll create a few objects that do not live outside the running time of an app. They are temporary, for example contain user's choices, and they also hold links to the persistent objects(tables). But as soon as...

Have parameters in Dao methods to get entities the most efficient way for read-only access

Allot of my use of hibernate, at least for that data that is presented on many parts of the web application, is for read-only purposes. I want to add some parameters to my Dao methods so I can modify the way hibernate pulls the data and how it handles transactions etc. By 'pulls the data' I altering the locking and not having session w...

Nhibernate/Hibernate, lookup tables and object design

Hi, I've got two tables. Invoice with columns CustomerID, InvoiceDate, Value, InvoiceTypeID (CustomerID and InvoiceDate make up a composite key) and InvoiceType with InvoiceTypeID and InvoiceTypeName columns. I know I can create my objects like: public class Invoice { public virtual int CustomerID { get; set; } public virtual ...

Custom EntityNotFoundDelegate

Hi all, I get a org.hibernate.ObjectNotFoundException when I want to delete an object which doesn't exist anymore via hibernate. I just want this exception to be ignored. I could catch the exception and ignore, this would be a solution maybe. But, since there is a hibernate support for ignoring this exception through org.hibernate.cfg.C...

Nhibernate HQL SQL Server 2005 / 2008 CONTAINSTABLE

Hi all, do you know anyway how I to use CONTAINSTABLEvia HQL? I need to use CONTAINSTABLE, not just CONTAINS. Currently I am using a SQL-query, but I need to use the multi-query feature which is not avaiable for SQL right now. If there is no such thing, would I be able to extend the MSSQL dialect? Or would that require to modify the co...

Unit Testing Hibernate's Optimistic Locking (within Spring)

I'd like to write a unit test to verify that optimistic locking is properly set up (using Spring and Hibernate). I'd like to have the test class extend Spring's AbstractTransactionalJUnit4SpringContextTests. What I want to end up with is a method like this: @Test (expected = StaleObjectStateException.class) public void testOptimist...

In hibernate how do I always use db server's timestamp?

Hi, I would like to add db server's timestamp in last_update column of my table. How can I achieve this in hibernate? Thanks ...

Pros & Cons: Hibernate vs. EJB 3

What are the advantages and disadvantages of Hibernate & EJB3 relative to each other? I found this post, but it didn't really address my question. If I don't have any particular tie to either technology, what would cause me to pick one over the other? Or are there situations where I would want to use both? Thanks, Zack edit: in respon...

Hibernate mapping - "Could not determine type"

I currently have the following objects persisting successfully: Person first name, etc. Exams title, date, etc. I'd like to now create a third table Exam results. For this table I believe it should be person ID, exam ID and result, and this is a many to many relationship. @Entity public class ExamResult { private Exam exam; ...

Spring, Hibernate, EntityManager and class inheritance

Hi, I'm pretty much new to Spring & Hibernate. In our team, we are building a web application using Struts 2 for the presentation layer, with Spring 3 and Hibernate 3 (with Annotations) underneath. We are still debating on whether to use DAOs or not and Session's or EntityManager's for CRUD operations. Setting aside the question of which...

Hibernate - on the stack or on the heap?

As a Java programmer, you usually keep two truths in your pocket: Instance variables and Objects lie on Heap. Local variables and methods lie on the Stack. Now that I use Hibernate in just about everything, I realize I'm not as sure of myself. Are there some good rules of thumb for using hibernate and knowing where your memory liv...

Problems when data save on database by Hibernate

Hi; I'm trying do save data to database by help of Hibernate , in Java. But when ı run codes , ı had lot of problems. Can anyone help me about that? Thanks... My code: package org.ultimania.model; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuratio...

Random select rows via JPA

In Mysql, SELECT id FROM table ORDER BY RANDOM() LIMIT 5 this sql can select 5 random rows. How to do this via JPA Query (Hibernate as provider, Mysql database)? Thanks. ...

Does iBatis enforce a primary key on my table?

Hi guys, I'm working on a legacy project. The database is poorly designed. I want to change the DB layer now. The first think go through my mind is hibernate, but I hibernate need a primary key on my table. In fact some of my table does not have primary key. So I did a google search and I find iBatis, it's sounds very good with it. But ...

Books and resources for Java Performance tuning - when working with databases, huge lists

Hi All, I am relatively new to working on huge applications in Java. I am working on a Java web service which is pretty heavily used by various clients. The service basically queries the database (hibernate) and then works with a lot of Lists (there are adapters to convert list returned from DB to the interface which the service publish...

A trigger on hibernate (maybe this is called interceptor)

Hi, I have a module which uses Hibernate as an ORM solution with EHCache as second level cache. I have another seperate module which inserts and updates the database. What I need is to have the ability to trigger an event when a row is inserted or updated. Let's say I have a Customers table and it is mapped to a Customer entity. I want s...