hibernate

How to uniquify resultset from NHibernate

Hi I have this multi-criteria, which works very well, except that I'm getting multiple of the same entities in the collections. I know this is by design, and I know you should be able to use a ResultTransformer to avoid it or filtering through a hashed set after quering. My query looks like this: IMultiCriteria criteria = session.Crea...

hibernate result ordering

how do i sort the result( list ) returned byhibernate dynamically.Means i dont want to put the order by clause in hbm file. This is because i want to sort then differntly at different times. i want to do nested sorting also. Consider the following. i have a course object which has a set of applications applications have attributes like ...

hibernate sorting

hey i want to do nested sorting in hibernate. i has a set of application in course object .application has a time and type attribute I want to sort by type first and then within application of particular type i want to sort it by time. can i use it as follows?? order-by="type desc,time asc " note that type should be sorted descending...

Hibernate @Version Field error

I am using hibernate, spring, struts framework for my application. In my application, each of the table has one field called as Version for tracking updation of any records. Whenever i am updating existing record of my Country table which has version 0, it works fine & update the record update the version field to 1. But whenever i am...

hibernate deletion problem please help urgent

i have a course object. The course object has a set of tutorials and a set of applications. When i delete a course objects i want the assocated set of tutorials and applications to get deleted. My course.hbm is as follows and my application.hbm contains <property name="appdatetime" type="timestamp"> <column name="appdatetime" lengt...

How to determine Collection changes in a Hibernate PostUpdateEventListener?

In Hibernate, implementing a PostUpdateEventListener allows you to plug into Hibernate's workflow and gives you the opportunity to inspect and compare the old and new values of an Entity's properties as it is being saved (PostUpdateEvent has methods getOldState() and getState() that return an array of these values). For standard properti...

Extending JPA entity mapping

I'm looking for an easy way to extend existing JPA mapping. The idea is as follows: I have an EAR project with EJB3+JPA module which has ClassA annotated and mapped to table class_a. But I want some other module (another EJB module) to have ClassB which adds more properties to ClassA (extend?). One way that I though about, is just to a...

how do i pass EntityManager to @PostUpdate

I want to save history of changes, so in @PostUpdate i want to create new instance of another entity and save it, how do i pass EntityManager to that method? ...

Using Property Type Info Hibernate NamingStrategy

I am writing a Hibernate NamingStrategy for our schema. Our legacy schema (for some reason!) includes type information in column names. For example: strproperty intcustomer I am implementing the following method from the NamingStrategy interface: public String propertyToColumnName(String propertyName) I would like to know the Java...

Best place for index call when using hibernate

Hi, currently i'm thinking on where's the best place in my code where i must put the call method to my indexing services (solR). The fact is that i must assure that every entity which is stored in the db is indexed, i'm using hibernate and i will try to implement it with interceptors. Any advice | idea ? ...

NHibernate won't decode UTF-8 from MySql

Hey, I have populated a MySQL table with utf-8 strings (using a python script). You can assume that the string in the DB was correctly encoded (I've verified this by extracting the string from MySQL Query Browser and running a utf-8 decode... got my original unicode string). Now the problem begins when I try to load this string using N...

Design of account e-mail activation (with Hibernate in mind)

Hi, I have a design problem which I would like some input on. Here are the constraints: Each user must have a working e-mail address when registering their account. When registering their user account an activation email should be sent, containing a link with an activation code which must be followed for the account to be activated. E...

How to create a hibernate idbag with a collection-id that has a default value?

...

How can I get the database name I am connected to through Hibernate?

I am trying to get the name of the database I am connected to in SQL Server. I tried doing: Query query = session.createQuery("SELECT db_name()"); List<String> dbNames = query.list(); However, I got the following error: [ERROR PARSER:35] *** ERROR: <AST>:0:0: unexpected end of subtree Exception in thread "main" java.lang.IllegalState...

EJB3 Query + in clause

I need to use an IN clause like the following SQL SELECT * FROM tableA WHERE colA in (1, 2,3) How can i do this in EJBQL? i've tryed the following, which obviously failed: SELECT tab FROM tableA tab WHERE tab.colA in (:colValues) then in java i did query.setParameter("colValues","1,2,3") that gives me the following exception ...

Transitioning from Castor to JPA

I am trying to make my java application more standards compliant and one of the biggest issues i am facing is transitioning our ORM framework from Castor JDO to a JPA implementation (thinking either Hibernate or DataNucleus). We have our own persistent data abstraction layer so the basic refactoring can easily be done by adding a JPA imp...

NHibernate - Updating a table with a trigger on it causes an error - Unexpected row count: 2; expected: 1

So I'm trying to update an object in my MS SQL 2005 database using NHibernate. Please keep in mind that this is a legacy database used in many live systems and I can't remove the triggers. When my data provider tries to .SaveOrUpdate() a row I get two returns (one for the actual update, and one when the trigger executes) The raw retur...

Setup and Tear Down of Complex Database State With Hibernate / Spring / JUnit

I have a class I'm unit testing that requires fairly extensive database setup before the individual test methods can run. This setup takes a long time: for reasons hopefully not relevant to the question at hand, I need to populate the DB programatically instead of from an SQL dump. The issue I have is with the tear-down. How can I eas...

Good books or online resources for learning Hibernate

What I found so far are some online resources like this: http://www.torsten-horn.de/techdocs/java-hibernate.htm (GER) https://www.hibernate.org/5.html (Hibernate Docs) http://docs.jboss.org/hibernate/stable/core/reference/en/html/tutorial.html http://www.manning.com/bauer2/chapter2.pdf (Sample chapter of Java Persistence with Hiberna...

Hibernate vs. JDBC

I am working on a project that previously used Hibernate. Honestly, it seems like Hibernate complicates it more than JDBC would have. Also, it seems that a lot of the power of the relational database is lost. What are the advantages of using Hibernate over JDBC? ...