hibernate

how to simple add an object to a collection in hibernate from client

Hello, I'm trying to add an object to a collection in my client view and to save it on server with hibernate/jpa mechanism. Here is the problem: Take a Group object which can contains Account objects. On my client view (gwt), I create a new group (so the id is null) and I add to this group some accounts (where ids exist). BUT these ac...

Hibernate Criteria: Eagerly load ManyToMany collection

My problem seems pretty straightforward to me, but I just can't seem to find an answer that works. I have a Hibernate Entity which has a ManyToMany association with another Entity, which is fetched lazily by default. I want to create a Criteria which will return the Entity with the ManyToMany association loaded eagerly. Here is the Enti...

Limit associated entities loaded through a Hibernate Criteria

Is it possible to limit the number of associated entities fetched through a Hibernate Criteria? Consider the following two entities: @Entity public class History { @OneToMany private List<Entry> entries ... } @Entity public class Entry { @ManyToOne private History history; private DateTime date; ... } I need to us...

why does hibernate not force you to mark fields as virtual, but nhibernate does?

why does hibernate not force you to mark fields as virtual, but nhibernate does? Is this a result of the differences between the VM and CLR? ...

using load/get using generics

With Hibernate, how do I load an entity using generics? Curretly I am doing: Entity e = (Entity) session.load(Entity.class, 123); In NHibernate, with generics, I can do: session.Get<Entity>(123); What's the Hibernate equivalent? ...

How to ensure that methods called from same thread use the same DB session

In our system we have multi-threaded processing engine. During processing each thread calls methods to retrieve data from the database. We determined that performance is greatly improved if methods called from the same thread use the same DB session (sessions are coming from the pool of course). Is there any standard way in Spring to e...

Specification Pattern vs Specific Hibernate Query

My question is when to use a specification pattern, and when to use specific SQL query. I understood that specific pattern need to collect whole collection and post filter using concrete specification. But i dont't understand the advantage in front of specific SQL query. CarColorSpecification cc = new CarColorSpecification(RED); CarAge...

how to set query to be read uncommited?

with hibernate, how can I set a query to be read uncommitted? I don't want this to be a global setting, just want to do it on a per query basis. ...

before calling session.gettransaction, do I have to ensure one exists?

before calling session.gettransaction, do I have to ensure one exists? if so, how do I check if there is a current uncommitted transaction in the session? ...

Hibernate list operation question

I'm working on a utility to update a list of entities in a database as a group. The database contains a list of entities. The result of the update is a new list. The API accepts this new list. The update may end up modifying some of the entities in the list, creating new ones and deleting some. So at the entity level, I may have to do a...

Grails query with associations - find all in a table where id is not in another table

I need to be able to find all items in a table where the id of each item is not in a relational mapping table. In other words, I have one table where each row has an id. If that id is in a map table, it should not show up in my list. I was thinking of querying my map table for all id's in it, then turning around and querying my main t...

when to use global transaction Or use spring aop for transaction

Q1. i do understand when we need to deal with multiple databases, we need to use global transaction. but from this post http://fogbugz.atomikos.com/default.asp . the person suggested just use spring aop to advise on the different transactionmanager ( more > datasource/sessionfactory). can anyone explain in what kind of situation we ca...

hibernate property

can anyone explain on this 2 properties Q1. hibernate.cglib.use_reflection_optimizer ? what is the effect of setting to true and false Q2. hibernate.c3p0.max_statements . i read hibernate doc https://www.hibernate.org/214.html. it only mentioned default value is 0. I am using oracle10g, and i set to 100. but i want to know how to ...

Using Hibernate to 'order by' a column which having a expression(sum, max, ...)?

select CONTRACT_ID, sum(PO_SPEND) from V_CONTRACT_ANALYSIS_202 group by CONTRACT_ID order by sum(PO_SPEND) desc ...

Accessing the join table in a hql query for a many-to-many relationship in grails

I have 2 domain classes with a many-to-many relationship in grails: decks and cards. The setup looks like this: class Deck { static hasMany = [cards: Card] } class Card { static hasMany = [decks: Deck] static belongsTo = Deck } After I delete a deck, I want to also delete all cards which no longer belong to a deck. The easiest way t...

Fluent nHibernate - unfriendly many-to-one reference name

I define my data model using Fluent nHibernate POCO classes + mappings. I'm also using nHiberate schema to create database schema. All is working fine but there is one unpleasent fact. When I use many-to-one reference referece is named by something similair to GUID instead of any descriptive name. Here's a piece of SQL: alter table [Odb...

Hibernate, MySQL Views and hibernate.hbm2ddl.auto = validate

I can use MySQL views in Hibernate by treating them like tables - ie. the entity is no different than one created for a table. However my application won't deploy when Hibernate is set to validate the model as it can't find the View as it assumes it's a table. Is it possible to use Hibernate Entities with deploy time validation turned o...

Efficiency of Hibernate's table-per-subclass inheritance strategy

I'm thinking about table layout for a Hibernate-managed class hierarchy, and certainly the table per subclass technique strikes me as the most appropriate in a general sense. However, thinking through the logic I have some concerns about its performance especially as the number of subclasses scale. To give a very brief (and classic) ex...

When and why JPA entities should implement Serializable interface?

The question is in the title. Below I just described some of my thoughts and findings. When I had very simple domain model (3 tables without any relations) all my entities did NOT implement Serializable. But when domain model became more complex I got RuntimeException which said that one of my entities didn't implement Serializable. I...

How to select from HQL

Hi im a newbe to HQL and have a SQL expression I need converted but am unable to select the SQL statement is: select SenseDate as Time,SenseValue as Value from UserData where NetworkID = '23' and IODeviceID = '129' and SenseDate >= DateAdd("d",-1, GETDATE()) and SenseDate<=GETDATE() and can run this part in HQL without problems: from...