hibernate

Hibernate @OrderBy with referenced class

Hi All, I have a class say: "ClassA" which has a collection of "ClassB" @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name = "COLUMN_NAME") private List<ClassB> lotsOfClasses; "ClassB" has a mapped class "ClassC" using plain old mapping annotations: public class ClassB { ... @ManyToOne @JoinColumn...

Why are life-cycle listeners in Hibernate Serializable?

The Hibernate interfaces that you implement to provide event listeners, for example: org.hibernate.event.PostInsertEventListener; all extend Serializable. However, it doesn't seem to explain anywhere why your listeners need to be serializable. We've been injecting DAOs with database connections into them for a while, and it hasn't faile...

JPA/Hibernate: code based validation of jpa queries.

What is the right way do validate a jpa query programmatically. Hibernate validates all annotation based named queries on entities. But how can I call this validation routine on programmatically builded jpa queries, to check for errors? @Entity public class Foo { @Id public int id; public String name; } main(...) { Query q = ...

Duplicate entry error in MySQL/Hibernate

Hi all, I am facing the following problem and can't find a proper solution. I have a relation A with the attributes id, x (foreign key), y (sequence number) and z (content). Further there is a uniqueness constraint on x-y. That is usually I have tuples like (455, 159, 1, ...), (456, 159, 2, ...), (457, 159, 3, ...), etc. I'm using Hiber...

bidirectional hibernate relationship

hi, i have a webapplication, using hibernate and the following entities. What do I wrong: ... @Entity public class Registration implements BaseEntity { ... @OneToMany(cascade = {CascadeType.PERSIST}, mappedBy = "registration", fetch = FetchType.EAGER) private List<OrderedProduct> orderedProducts = new ArrayList<OrderedProduct>(); ... pu...

Hibernate dynamic instantiations with collections, is it possible?

I would like to write a hql query using a dynamic instantiation with a list as one of it's parameters. Simplified example: A HQL query with a dynamic instantiation: select new x.y.UserDto(u.name, u.contacts) from User u where u.xyz=:param1 ... and my dto class constructor is: public class UserDto { private String name; privat...

How to test HQL queries?

I'm searching for a fast (really fast) way to test changes to hibernate queries. I have a huge application with thousands of different HQL queries (in XML files) and 100+ mapped classes and i dont want to redeploy the whole application to just test one tiny change to a query. How would a good setup look like to free me from redeployment...

Hibernate Exception help: TransientObjectException

Hello all, I am getting the following exception when I try to update an object: org.hibernate.TransientObjectException: object references an unsaved transient instance - save the transient instance before flushing: ...... Can anyone help??? The object that I am trying to update has the 'lazy' attribute set to false in the mapping fil...

hibernate restrictions and/or order

Hi, small questions about Restrictions.or and Restrictions.and If I do something like this: ... criterion = criterionA; criterion = Restrictions.and(criterion, criterionB); criterion = Restrictions.or(criterion, criterionC); criterion = Restrictions.and(criterion, criterionD); Will this be treated as: (A and B) or (C and D) (follow...

Using Grails/Hibernate with old Databases. How to create missing functions?

Hello again, So Hibernate Supports the latest Version of Firebird, which is really great. But... I got here an Firebird 1.5.2 Database. My Grails App using this Database via Hibernate...so far everything great. My Apps sends Queries with Functions that are not known to my Database. For Example the Function LOWER, which is now supporte...

Hibernate: Specifying columns in a one-to-many relationship

I'm trying to build a Hibernate layer for a database schema I have essentially no control over. Simplified, there are two tables. Table parent has two important columns: parent_id, integer, primary key, autoincremented parent_code, string, unique key, generated by a black box somewhere (let's say this is a UUID for sanity's sake) Plu...

Using Hibernate with Dynamic Eclipse Plug-ins

I have classes that are named exactly the same across different plug-ins that I use for my application, and I'd like to be able to configure them properly with Hibernate. The problem is that it looks like Hibernate dynamically generates a class' package name when trying to find a class when it's doing its mapping. With one plug-in this s...

How to add greater than/less than to Hibernate filters

How can you add greater than or less than symbols to the condition on a Hibernate filter specified in the hbm.xml file? I am trying to add a filter to limit the collection to a specific date range: <filter name="limitTalksByDateRange" condition="talkstart >= :tstart and talkstart <= :tend" /> Unfortunately this breaks the XML parsing...

What is the best way to serialize an EMF model instance?

I have an Eclipse RCP application with an instance of an EMF model populated in memory. What is the best way to store that model for external systems to access? Access may occur during and after run time. Reads and writes of the model are pretty balanced and can occur several times a second. I think a database populated using Hiberna...

The proper way to deploy a Hibernate-based J2EE app to a remote server..

I have a pretty monstrous Java app in development here. As of now, it's only ever been deployed on my locally installed Tomcat/MySQL setup. For completeness, the app is an online game server written using Spring, Hibernate with MySQL currently on the backend. Now, I can easily package up the WAR and get that on the remote server.. The ...

How to test materialized view in java

Is there any way to write automated tests for materialied views using Hibernate framework? I don't know how to make it work. My first approach was to use DBMS_MVIEW.REFRESH stored procedure. But, it is not what I need - all test data is commited after refreshing the view. Is there any different way to test the view? ...

how to read my blob column from mysql to string type in hibernate

how to read my blob column from mysql to string type in hibernate I have try this way but alway return me: [B@196f4b5 Article article2=f.daoArticle.findById(article.getSrcUrl()); String vbody = article2.getArticle(); System.out.println(vbody); \\hbm <class catalog="ariso" name="countaword.ariso.dao.Article" table="a...

Disable Hibernate auto update on flush on read only synonyms

I have a table and two databases which have the same table, but one is a symlink of the other one and only read is permitted on this table. I have mapped the table to Java using Hibernate and I use spring to set the Entity Manager's data source as one of the two databases based on some input criteria. I call only read only operations ...

When to use inverse=false on NHibernate / Hibernate OneToMany relationships?

I have been trying to get to grips with Hibernate's inverse attribute, and it seems to be just one of those things that is conceptually difficult. The gist that I get is that when you have a parent entity (e.g. Parent) that has a collection of Child objects using a one-to-many mapping, setting inverse=true on the mapping tells Hibernat...

generate sql scripts

is there any hibernate utitliy that i can use to connect to database. list all the tables, and generate sql script for "creating tables + data" and save as *.sql ? ...