hibernate

Hibernate lazy loading + Jersey REST = eager loading?

I'm developing a Client-Server-Application with Hibernate as persistence layer and Jersey REST for network communication. Given a user with roles: when I want to display all users in the client, I don't want the roles to be loaded by Hibernate and I don't want them to be sent over the network when I want to modify the user's roles, I...

Representing incomplete objects when loading from database

So in a recent project (a small internal tool), I want to experiment with not using an ORM tool which we typically use in all our projects. The reason is that I particularly aren't a fan of them specially in complex projects with complex object hierarchies and relationships. Using an ORM it becomes difficult to debug performance issues a...

Hibernate Annotation + AspectJ -> Attributes names pbs in HQL

I'm looking for a way to use aspects to inject parameters in hibernate annotated classes. Here is a user : @Entity public class User implements IHasCity { @Id private int id; private String name; } public interface IHasCity { } Here is an aspect contributing to that User public aspect ACity { @Column private S...

Is package level annotations still available on EJB3 to map entities on JPA/Hibernate?

The Problem: I have two complementary projects, a base one (Base Project) with shared entities and a specific one (Specific Project) that needs to query the entities from the first project. They both access the same database, but in different schemes and different users/grants. Nonetheless, both have at least 'SELECT' grant on the shar...

Duplicate key issue with Spring and Hibernate - assistance needed

--Summary (shortened)-- I have a controller that loads a profile object from the corresponding DAO. It updates some properties, many of them sets, and then calls saveOrUpdate (via save in the DAO) to reattach and update the profile object. At seemingly random intervals, we get an org.hibernate.exception.ConstraintViolationException, w...

Grails Domain Class Dynamic List As A property

Let's say I have a domain class called ShopCategoryPageTab. And I have a domain class called Product. I want ShopCategoryPageTab to have a list of Products. However, this list is not static, but determined by a formula. For example, I might want to have a "products" property which would list all products with criteria X, Y Z. So this...

Hibernate EntityManager Factory - EHCache

Hi all, I am having more problems with getting the entity manager factory up and running. Unfortunately, the error message is very vague. I'm not quite sure why it's not more descriptive, but it is what it is: Hibernate Startup log messages (trace level), no entities configured for brevity (same error message either way except all th...

Best way to write a named SQL query that returns if row exists?

So I have this SQL query, <named-query name="NQ::job_exists"> <query> select 0 from dual where exists (select * from job_queue); </query> </named-query> Which I plan to use like this: Query q = em.createNamedQuery("NQ::job_exists"); List<Integer> results = q.getResultList(); boolean exists = !results.isEmpty(); ...

using hibernate in J2EE app

I am maintaining following structure for my project Web - Web Project Model - EJB Project Persistence - Java project having data classes and their mapping for Hibernate Pokuri - EAR Project As we know we can give jar file to hibernate configuration to load mapping information from jar. As I deploy EAR on to server I just want to bui...

Get Hibernate transaction status

I'm using Hibernate 3.3 in a Swing application. I'd like to retrieve some stats on the performed transaction and make that info available to my views. For example: Execution time Number of rows touched Type of transaction (update, delete, create, select etc) I have several helper classes. I'm thinking of having some public fields lik...

Hibernate and 2nd level cache

I would like to Cache instances of class Cat each time I call saveOrUpdate(Cat cat) Retrieve Cat instances from the cache when I run a query findByName(String catName) - cat name is not a primary key It looks like that the second level cache cannot help, because my understanding is that it works with primary keys only. Moreover, I a...

NHibernate ICriteria search

I have the following criteria search that I would expect to return 1 project with multiple task and contexts and a single user. What is actually getting returned is the same project multiple times for each different task. It almost looks like I am missing a statement in the criteria to tell the search to return unique projects. Any he...

Best way to override Hibernate's lazy loading in this instance.

Suppose you have class B with lazily loaded property c. And that this is fine everywhere in the system except the following: You have a class A with property b of class B. Whenever you load an entity of type A you want to load the full a.b.c chain non-lazily. Is there a way to set up this type of logic in Hibernate? Edit: A propert...

Easiest way of programatically checking that a class has a valid JPA defintion

I'm working with many classes which are annotated with javax.persistence.Entity and the like. My project is about generating metadata about JPA-annotated classes rather than persistence by itself, so I'm using them as test cases. Rather than firing up Hibernate or some other JPA provider, I'd like to programatically check - part of my u...

Hibernate domain model

When specifying one to many relationships in the domain model....is it better to initialize the set? i.e. private Set<Book> books = new HashSet<Book>(); OR private Set<Book> books; Thxs. ...

Hibernate and keyvalue pair implementation

I would like to create a few classes which are in essense wrapper of a map of key value pair. What is the best appoarch to retrieve or store these classes into a database using hiberate? What are the right hibernate annotations to get the job done? On the database, I would expect this formation of data class1, field1, value1 class2, fi...

Hibernate: More than one relationship using the same join column

I'm using a legacy database schema with composite keys. I have an entity with two relationships and one of the join columns is shared. For example, Let's say i have a Student entity with two relationships Department and Course. Department uses dept_code column while Course uses dept_code and course_code colum. The domain model is such ...

Hibernate Criteria API and Scalar Subqueries

Hi, I want to translate a HQL query to Criteria API but I don't know if it's possible to write the same thing with Criteria. The HQL looks like this: select distinct new DataTransferObject(property1, property2, ..., (select NVL(property3, null) from Table1 where property3 in elements(...) and ... ), property4, ..., (select .....), ...)...

"SELECT ... FOR UPDATE" not working for Hibernate and MySQL

Hi, We have a system in which we must use pessimistic locking in one entity. We are using hibernate, so we use LockMode.UPGRADE. However, it does not lock. The tables are InnoDB We have checked that locking works correctly in the database (5.0.32), so this bug http://bugs.mysql.com/bug.php?id=18184 seems to be no problem. We have chec...

Hibernate boolean true_false yields a char in MySql... sometimes?

I've been enjoying Hibernate's "yes_no" notation for a while now. I use it a lot on active fields like so: @Column(name = "active") @Type(type = "true_false") public boolean getActive() { return active; } public void setActive(boolean active) { this.active = active; } Recently I added a new field called processable, to a dif...