hibernate

Hibernate, EHCache, Read-Write cache, adding item to a list

Hi all, I have an entity that has a collection in it. The collection is a OneToMany unidirectional relationship storing who viewed a particular file. The problem I am having is that after I load the entity and try to update the collection, I don't get any errors, but the collection is never updated: Entity: @OneToMany(cascade = Casc...

Problem with NHibernate and saving - NHibernate doesn't detect changes and uses old values.

When I do this: Cat x = Session.Load<Cat>(123); x.Name = "fritz"; Session.Flush(); NHibernate detects the change and UPDATEs the DB. But, when I do this: Cat x = new Cat(); Session.Save(x); x.Name = "fritz"; Session.Flush(); I get NULL for name, because that's what was there when I called Session.Save(). Why doesn't NHibernate det...

Hibernate - EhCache - Which region to Cache associations/sets/collections ??

Hi all, I am a newcomer to hibernate. It would be great if someone could comment over the following query that i have: Say i have a parent class and each parent has multiple children. So the mapping file of parent class would be something like: parent.hbm.xml <hibernate-mapping > <class name="org.demo.parent" table="parent" lazy="tru...

Optional parameters with named query in Hibernate?

Is there any way to specify optional parameters (such as when search parameters are provided from a form and not all parameters are required) in a named query when using Hibernate? I'm using a native SQL query, but the question is probably applicable to named HQL queries as well. I'm pretty sure the answer to this is 'no', but I haven'...

Hibernate aliastobean

Query query = getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery( "select proj_employee.employee_no as employeeNo, ... .setResultTransformer(Transformers.aliasToBean(User.class)); Inside User.class does the property employeNo need to be in capital letter? private String EMPLOYEENO //get/...

hibernat createSQLQuery use CacheQuery?

Query query=getHibernateTemplate().getSessionFactory().getCurrentSession().createSQLQuery( "select... getHibernateTemplate().setCacheQueries(true); List result= query.list(); getHibernateTemplate().setCacheQueries(false); return result; may i know when i do manual "createSQLQuery" how to use cacheQuery? the above does...

Entities equals(), hashCode() and toString(). How to correctly implement them?

I'm implementing equals(), hashCode() and toString() of my entities using all the available fields in the bean. I'm getting some Lazy init Exception on the frontend when I try to compare the equality or when I print the obj state. That's because some list in the entity can be lazy initialized. I'm wondering what's the correct way to fo...

DB2 Query to Hibernate Criteria

Hi, I have a specific DB2 query, and I would like to execute this query using criteria. The query: SELECT sum(units) as volume, location_id, aged FROM ( SELECT units, location_id, CASE WHEN daysinstock < 61 THEN 'NOT_AGED' WHEN daysinstock < 91 THEN 'AGED' ELSE 'OVER_AGED' END AS AGED FROM STOCK_T...

DAO, Spring and Hibernate

Correct me if anything is wrong. Now when we use Spring DAO for ORM templates, when we use @Transactional attribute, we do not have control over the transaction and/or session when the method is called externally, not within the method. Lazy loading saves resources - less queries to the db, less memory to keep all the collections fetch...

NHibernate Native SQL multiple joins

Hi all, I"m having some problems with Nhibernate and native sql. I've got an entity with alot of collections and I am doing an SQL Fulltext search on it. So when returning 100 or so entities, I dont want all collections be lazy loaded. For this I changed my SQL query: SELECT Query.* FROM (SELECT {spr.*}, {adr.*}...

How can this be done with (N)Hibernate?

I'm creating a windows forms application with NHibernate. It's an MDI application, so there is no limit to how many forms the user can have open at the same time (probably many). For most forms I want to have an "OK" and a "Cancel" button. Both close the form, but "OK" also saves the modified data to the DB. The forms can be pretty comp...

How do you see a good Spring+Hibernate DAO module design?

First, we create classes that represent db entities, ok, done. Let's say we use Hibernate session factory and JPA annotations. Now we must create a DAO: getUserById, getAllUsers() etc. What do you recommend about transaction management, session factory, how a good design to be made? ...

JPA/Hibernate Embedded id

I would like to do something like that: An object ReportingFile that can be a LogRequest or a LogReport file. ( both got the same structure) An object Reporting containing for one logRequest, a list of logReport with a date. I tryed to set an EmbededId, that would be an attribute of the logRequest. And that's the problem i got. I don...

How to configure RetryAdvice and ExceptionTranslation for Deadlocks using NHibernate and Spring

Hi, i am using Spring.net 1.2 with NHibernate 2.0.1. Within my project i'am facing some Deadlock issues and besides the database tweaks to minimize the occurence i would like to implement Springs RetryAdvice to handle this. I can't find any working example how to configure a this. The reference seems to be clear about how to use it but ...

Java data structure to use with Hibernate to store unknown number of parameters?

Following problem: I want to render a news stream of short messages based on localized texts. In various places of these messages I have to insert parameters to "customize" them. I guess you know what I mean ;) My question probably falls into the "Which is the best style to do it?" category: How would you store these parameters (they ma...

Hibernate - why use many-to-one to represent a one-to-one?

I've seen people use many-to-one mappings to represent one-to-one relationships. I've also read this in a book by Gavin King and on articles. For example, if a customer can have exactly one shipping address, and a shipping address can belong to only one customer, the mapping is given as: <class name="Customer" table="CUSTOMERS"> ....

HQL multiple updates. Is there a better way?

I have a Map, that I want to persist. The domain object is something like this: public class Settings { private String key; private String value; public String getKey() { ... } public String getValue() { ... } public void setKey(String key) { ... } public void setValue(String value) { ... } } The standard appr...

Grails: Problem with nested associations in criteria builder

I have a frustrating problem with the criteria builder. I have an application in which one user has one calendar, and a calendar has many entries. Seems straightforward enough, but when I try to get the calendar entries for a given user, I can't access the user property (MissingMethodException). Here's the code: def getEntries(User user...

How to make query on a property from a joined table in Hibernate using Criteria

Hello, I have the following mapping: <hibernate-mapping package="server.modules.stats.data"> <class name="User" table="user"> <id name="id"> <generator class="native"></generator> </id> <many-to-one name="address" column="addressId" unique="true" lazy="false" /> </class> <class name="Address...

ORM model and DAO in my particular case

I have the DB structure as follows: table STUDENT (say, id, surname, etc) table STUDENT_PROPERTIES (say, name_of_the_property:char, value_of_the_property:char, student_id:FK) table COURSE (id, name, statusofcourse_id) table STATUSOFSOMETHING (id, name_of_status:char ('active','inactive','suspended' etc)) table STUDENT_COURSE (studen...