hibernate

Hibernate Table per Hierarchy How to

I would like to use hibernate to contain a hierarchy of objects, however the discriminator column is a foreign key to another table that contains the CODE defining the subclass type. Is it possible to specify the code from the joined table as the discriminator, or do I have to use the key values and hope the keys stay consistent? e.g...

Mapping an Oracle Date to a Java object using Hibernate

I get the message "literal does not match format string". For instance, here are some methods from a Java class: public String getDateTime(); public void setDateTime(String date_time); Here is the mapping from the Hibernate config file for that class: <property name="dateTime" column="date_time"> and here is the DDL for that col...

Expressions in hibernate criteria

Hi there, Let's say I have a persistent class Item with a quantity field and a price field. Is there a way to build a Criteria that calculates the sum of quantity*price? ...

Proper way of writing a HQL in ( ... ) query

Assuming that I want to write the following HQL query: FROM Cat c WHERE c.id IN (1,2,3) what is the proper way of writing this as a parametrized query, e.g. FROM Cat c WHERE c.id IN (?) ...

Converting from Hibernate hbm.xml to annotations

I have a rather large program that uses Hibernate for its ORM needs. Due to the age of the project it is using hbm.xml to configure it. I would like to convert it to annotations but I'm vary of investing days (weeks?) in manually adding the annotations and then testing everything. Is there any tool out there that can help facilitate thi...

Hibernate: Used mappedBy on class that extends another class annotated as JoinedSubclass?

The following doesn't work: @Entity class Owner { @OneToMany(mappedBy="owner", cascade = {CascadeType.ALL}) protected Set<B> getBSet() { .. } } @Entity @Inheritance(strategy=InheritanceType.JOINED) class A { @ManyToOne public Owner getOwner() { ... } } @Entity class B extends A { } It causes an exception a...

XML to Relational with DB2 and Java (and Hibernate?)

What I have here is a bunch of XML-Files containing data and a nice ER-Model to which the data belongs. What my problem is: I need to get this data into a db2. The tables with all necessary attributes and keys are already created. I was thinking of three different solutions: Parsing the XML and creating SQL-Queries from it. This solut...

How to lazy load a one-to-one composition via hql

If have an entity A with a bidirectional one-or-zero-to-one mapping with entity B. The mapping is as follows: <class name="EntityA" table="TABLE_A" mutable="true" lazy="true"> <id name="idA" type="long" column="pk_a" unsaved-value="null"> <generator class="sequence"> <param name="sequence">pk_a_seq</param> ...

Display Hibernate Query in JTable

I'm seeking an efficient way to display an SQL table queried via Hibernate in a JTable. Query q = em.createNamedQuery("Files.findAll"); List rl = q.getResultList(); It would probably be preferable to use the List returned by that (In this case, that would make a list of Files objects (where Files is an internal class, not java...

HQL Order by query giving problem

I have following query written in HQL for Hibernate. ======================================================================== select new map(ret.retailerDesc as ret_name, ret.id.retailerId as ret_id, ret.id.serviceId as service_id, (select count(distinct i.inspectionId) as inspections from Inspection i inner join i.c...

Hibernate load UserType object from repository

Setting: I have an object (AProduct) persisted by hibernate in my database. This object references another object (AComponent) stored in a repository. In the database table of the product only the ID of the component should be stored. By loading the product, I want to load the correct component from my repository. My solution so far is ...

How to avoid hardcoded field names in HQL, Hibernate?

Suppose that I have the following HQL: String hql = "select e.aField from MyEntity as e"; If I want to refactor and change the name of the MyEntity's member variable aField to something else, I also have to change all occurrences in the whole code in Strings. If I forget to change one hql string the code breaks. How can I avoid this ...

Hibernate NullPointerException when using criteria in a EntityMode.DOM4J session

Hi, I'm running into a null pointer exception if I try to use the following code: //Spring JPA entityManager allow us to retriver the underlying session. org.hibernate.Session session = (org.hibernate.Session)entityManager.getDelegate(); org.hibernate.Session dom4jSession = session.getSession(org.hibernate.EntityMode.DOM4J); org.hibern...

Compatibility Issue of ASM 3.1 and HIbernate and JAX-RS

Hi, I have found out that "Hibernate cannot be combined with the reference implementation of JAX-RS." on the link http://lists.jboss.org/pipermail/hibernate-issues/2009-May/015628.html So i am unable to combine JAX-RS (jersey) with hibernate, does anybody know a work around for this ? ...

Hibernate error: cannot resolve table

I'm trying to make work the example from hibernate reference. I've got simple table Pupil with id, name and age fields. I've created correct (as I think) java-class for it according to all java-beans rules. I've created configuration file - hibernate.cfg.xml, just like in the example from reference. I've created hibernate mapping for...

eclipse hibernate plugin

Hi folks, Can somebody guide me how to install Hibernate tools in Eclipse. I am using Eclipse 3.3 ( I can upgrade to 3.4). I can use Hibernate 3.0 or 2.0. I am not able to install the plugin. Its not getting detected. The update site gives error saying that WTP is required. When I try to install that, it again give some dependency erro...

how to create hbm files from java files??

Hello, Is there any eclipse plugin available to create hibernate hbm file from java file?? I want to create hbm from java files and hence the database. ...

Performance overhead for Hibernate and Spring due to reflection.

Spring and Hibernate uses reflection for bean creation (in case of spring) and POJO mapping (in case of Hibernate). Does it negatively impacts on performance ? Because reflection is slower compare to direct object creation. ...

Join without association in HQL

Lets say I have two tables(A, B) like: A {id, a, c} B {id, b, c} I have also their entities. I want to write an HQL so that the result set will be like (where A.c = B.c): (a1, b1, c1) (a2, b2, c2) (a3, b3, c3) ... Since on clauses are not supported by hibernate I am stuck and I don't know how to write the query. ...

In memory filtering of not persistent collection with Hibernate

Ok. What I wanted was: With Hibernate, to load once a list of MyEntity objects and have that list as the internal data of a model of a jtable. I also have a jTextField and when a key is typed, i call a method of my model that takes the text of the jtextfield as argument and filters the internal list of MyEntitys and fires the tablemod...