hibernate

hibernate mapping file for a grails domain class conundrum

I have a legacy database table to map to with a grails app I have to use a hibernate mapping file for a grails domain class in order to get some decimal precision values correct. I tried all sorts of tricky ways to do it with straight grails constraints and it is like herding cats. And so column size and precision value do not map qui...

A Maven2 mojo that uses Hibernate: how to control logging?

I have a maven2 plugin that calls hibernate as configured in a Spring context. Hibernate, of course, logs. I'm trying to control the logging. 0 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.2.6 So, I explicitly put slf4j into the plugin's dependencies, along with the log4j package. And I configure Spring to use log4j, ...

Hibernate Subclass which has multiple discriminator values

Hello I have a Subclass which needs to cover multiple Discriminator Values. something like: @DiscriminatorValue(value = "ACT","DNR","ATT" ) would do me perfect. we have existing data where several discriminators can be mapped to one class (as they are similar types of what our system will consider the same thing) ...

Hibernate reverse engineering

I have a structure where the main table is USER, other tables include CATEGORY (contains user_id). What I got after the standard reverse engineering procedure was: the class User contained a collection of categories, the class Category didn't contain the foreign key (user_id) but it did contain the User object. Why did it not cont...

hibernate - Postgres- target lists can have at most 1664 entries

We are using hibernate, postgres 8.3x Our entities are many to one mapped with eager fetching. We have multiple associations with Many to one mapping. As we added new columns to any other existing entities, We are getting below error: target lists can have at most 1664 entries I searched internet and they say this is due to More num...

Can you use custom objects in a Hibernate filter?

I have a hibernate filter that needs to evaluate using two different columns in the database. I have another existing hibernate object that contains both of those fields, and I would like to be able to pass the other hibernate object into the session.enableFilter.setParameter() call, rather than pass both the values contained in it sepa...

Using a Hibernate MapKey that's not unique within a table

This is a Hibernate/JPA question. I have a set of Schedule objects, each including several Steps of various StepTypes. Each StepType is unique within a schedule, so the steps are stored as a Map<StepType, Step>. The code is annotated as: @Entity public class Schedule implements Serializable { @MapKey(name="type") @OneToMany(c...

Hibernate configuration - session factory scanning?

We have this hibernate.cfg.xml file. Is there a way to tell Hibernate to just scan a directory instead of having to add an entry here for each class? <hibernate-configuration> <session-factory> <mapping class="com.abc.domain.model.A" /> <mapping class="com.abc.domain.model.B" /> <mapping class="com.abc.domain.model...

DBunit generates java.lang.ClassCastException: java.lang.String cannot be cast to oracle.sql.CLOB when trying to load a CLOB field

I am using the latest version of DBUnit (2.4.7), on Oracle 11GR2. I'm using Java 6 (1.6.0_15) and the latest version of Oracle's client jar (jdbc6.jar) I've been unable to successfully load any data referenced by a CLOB Oracle field from an XML file into the database. I've used all sorts of combinations of versions of the: Oracle JDB...

Hibernate database connection configuration

We have 2 different server environments using the same Hibernate configuration. One server has JNDI support for datasource, but the other does not. Currently the Hibernate configuration is configured to use JNDI, which is causing problem on the server that does not support JNDI. I have also tried to put the direct JDBC configuration tog...

MySQL Hibernate sort on 2 columns

I have a table as follows Table item { ID - Primary Key content - String published_date - When the content was published create_date - When this database entry was created } Every hour (or specified time interval) I run a process to update this table with data from different sources (websites). I want to display the results accordi...

Web service under JBoss using Hibernate: first steps

What's the difference between building a stand-alone application based on Hibernate and a web service (JBoss) based on Hibernate? I'm refering at the creation of the SessionFactory, Configuration and Sessions. What special concerns should I take care when building a web service with Hibernate persistence? I would really appreciate a bas...

Best practice to return a result Flag after saveOrUpdate in hibernate ?

Often we have to use some of the methods which don't return anything useful. If I invoke saveOrUpdate() in hibernate , I don't know whether it has been performed successfully . I use a implementation like this (which I think is a bit awkward) : public int saveOrUpdateA(A a) { int resultFlag = 0 ; try { // obtaining ...

Hibernate: Parent/Child relationship in a single-table

I hardly see any pointer on the following problem related to Hibernate. This pertains to implementing inheritance using a single database table with a parent-child relationship to itself. For example: CREATE TABLE Employee ( empId BIGINT NOT NULL AUTO_INCREMENT, empName VARCHAR(100) NOT NULL, managerId BIGINT, CONSTRAINT pk_empl...

How to populate Java (web) application with initial data using Spring/JPA/Hibernate

I want to setup my database with initial data programmatically. I want to populate my database for development runs, not for testing runs (it's easy). The product is built on top of Spring and JPA/Hibernate. Developer checks out the project Developer runs command/script to setup database with initial data Developer starts application (...

Consuming XML directly in AXIS2

Hi, I have a scenario where I get XML from client to server which exposes REST web services using AXIS2. I want to directly store this XML to DB (without converting into Java object), with some more information like user to whom XML belongs etc. I might store XML as We also have hibernate in the same application for ORM. Now my questi...

Why use Hibernate/nHibernate?

I have found myself doing a lot of work to get nHibernate setup and am left wondering: Why use a framework like Hibernate/NHibernate? I am sure that quite a few people love the framework but I am unclear on the advantages and disadvantages. What are the advantages and disadvantages of lazy loading, and are there other features to Hiber...

Java equivalent for database schema changes like South for Django?

I've been working on a Django project using South to track and manage database schema changes. I'm starting a new Java project using Google Web Toolkit and wonder if there is an equivalent tool. For those who don't know, here's what South does: Automatically recognize changes to my Python database models (add/delete columns, tables etc...

Is there a way to combine streaming data retrieval with hibernate?

For the purposes of handling very large collections (and by very large I just mean "likely to throw OutOfMemory exception"), it seems problematic to use Hibernate because normally collection retrieval is done in a block, i.e. List values=session.createQuery("from X").list(), where you monolithically grab all N-million values and then pr...

TransactionRequiredException on OptimisticLockException

Hi there. I have the following class that generates sequencial Card Numbers. I'm trying to recover from OptimisticLockException, by calling recursively the same method. however, i'm getting TransactionRequiredException. Dows anyone knows how to recover from OptimisticLockException in my case? Thanks a lot in advance @Name("simpleAutoI...