hibernate

Performance difference between annotating fields or getter methods in Hibernate / JPA

I was curious if anyone had any hard numbers around the performance difference between annotating Entities using private fields instead of public getter methods. I've heard people say that fields are slower because they're called "through reflection" but then again so are the getter methods, no? Hibernate needs to set the accessibility...

Is Hibernate good for batch processing? What about memory usage?

I have a daily batch process that involves selecting out a large number of records and formatting up a file to send to an external system. I also need to mark these records as sent so they are not transmitted again tomorrow. In my naive JDBC way, I would prepare and execute a statement and then begin to loop through the recordset. As ...

SQl Query to Hibernate Query

I have a MYSQL query that I use to retrieve random rows from a table. The query is : SELECT * FROM QUESTION WHERE TESTID=1 ORDER BY RAND() LIMIT 10; Now I need to change this query to Hibernate. Did a bit of Googling but couldn't find the answer. Can someone provide help on this. Thanks ...

Refactoring a Hibernate entity into subclasses

I have a class that is currently mapped as an entity in a database table using Hibernate. This class should be refactored into an abstract class containing some field common to all of its subclasses. I'm using annotations for mapping hibernate entities/relationships classes. I would like suggestions/variants on how to do this refactori...

"Session closed" error when trying to get a blob from DB using getBinaryStream()

I'm using Hibernate 3.1 and Oracle 10 DB. The blob is defined as @Lob @Basic @Column in the Hibernate entity which corresponds to the relevant DB table. The error -java.sql.SQLException: Closed Connection- seem to appear once in while, not in every attempt to get the blob from the DB. This seems like a hibernate fetching issue, so I tho...

Hibernate and Spring transactions - using private constructors/static factory methods

We have a Hibernate/Spring application that have the following Spring beans: <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager" /> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" /> When wiring the application together we get...

What is First and Second Level caching in Hibernate?

in simple words, any one? ...

How do I ensure a value being updated with Hibernate hadn't been changed in the meantime since I read it?

I have a problem where I want to read an object from the database using Hibernate, change a value, and save the object. If changing the value takes some time, what's the best way to ensure the underlying object in the database has not changed? I am doing this in one transaction (and one session). The code looks something like: // Load...

Null Pointer when populating Grails Domain object with Oracle 10g long field

We are trying to populate a domain object from an oracle 10g database. The field in question is defined as a string in the domain object with the following constraints. zdata(blank:false,maxSize:3000000) The size of the data is approximately 70K of XML. The table definition looks like this: ZDATA NOT NULL ...

How many .hbm files are needed to represent Hibernate Inheritance?

In order to represent inheritance how many hbm files are needed? How do I represent the relationship between base and subclasses in the subclass hbm file? I want hbm and pojo class of super and sub class. ...

Mapping ORACLE's NUMBER Type with Hibernate

Hello, I have a table in a ORACLE 10g database with a column "kzCode NUMBER(1)". If I try to map this with Hibernate annotations in JBOSS Server WebApp like this: @Column(nullable=false) private Integer kzCode; I got an error: org.hibernate.HibernateException: Wrong column type: kzCode, expected: integer I also tried @Column(nulla...

hibernate: LazyInitializationException: could not initialize proxy

Hi all, Here's one that has me perplexed. I'm trying to implement a basic Hibernate DAO structure, but am having a problem. Here's the essential code: int startingCount = sfdao.count(); sfdao.create( sf ); SecurityFiling sf2 = sfdao.read( sf.getId() ); sfdao.delete( sf ); int endingCount = sfdao.count(); assertTrue( startin...

(N)Hibernate Selecting Constants in Query

does anyone know if you can do something like this using the (N)Hibernate criteria api: Select 1 AS obj.Property0, obj.Property1, obj.Property2 from Class Baiscally I want to select a constant value for one of my properties in the query. I can do this easy enough using HQL but I was wondering if anyone knew a way using the criteria ap...

How to install Hibernate Tools in Eclipse?

What is the proper way to install Hibernate Tools in Eclipse as a plugin? The Hibernate site doesn't really give any instructions. Looking at the Hibernate Tools binary HibernateTools-3.2.4.Beta1-R200810311334.zip, it appears that I can just unzip this in my eclipse directory. Do I just unzip it in my eclipse directory? This seems like ...

How to see SQL query using Hibernate Tools in Eclipse?

Having installed Hibernate Tools in Eclipse, how can I view the would-be generated SQL query of from the JPA query language? (I'm using Hibernate as my JPA implementation) My Java DAO class looks something like: public List<Person> findById(int id) { return entityManager.find(Person.class, id); } public List<Person> find(String nam...

Problem connecting to a remote database using hibernate

I'm trying to connect to a remote database (hosted on Netfirms www.netfirms.ca if anyone is curious) using hibernate. My mapping file is as follows: <hibernate-configuration> <session-factory> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:...

How can I represent a many to many relationship to the same table/entity in hibernate?

Is that possible? I mean, can both ends of the many to many relationship point to the same table? ...

How do I use Hibernate from an Eclipse Plug-in?

I am writing an Eclipse plug-in that loads resources from a central database. I would like to use Hibernate to access that database. So how would I add this as a dependency to my plug-in project? I've tried Google but only get hits on about plug-ins for editing Hibernate configuration files. ...

Hibernate: How to make Hibernate delete records from child table when deleting parent if child is linked to parent with many-to-one?

Lets say I have two tables - "child" and "parent" with many-to-one relation. What I need is to delete child entries if parent record is deleted. It is not a problem if I link child table from parent by creating one-to-many association in parent.hbm and set cascade="all-delete-orphan". The problem is I don't want one-to-many relation o...

Many returned records cause stackoverflow with Hibernate

If there are many return records from DB. It will get stackoverflow problem. User is a class, which has a one to many relationship (to 3 other classes). When I print out the SQL, i found that the system runs the same query many time to get the data from DB. Does anyone know what the problem is? result.addAll(getCurrentSession().cr...