hibernate

Threadlocal reference to hibernate session impl, causing session impl not to get garbage collected

Hello, I am using thread local to manage my hibernate sessions. Recently I have been seeing OutOfMemory exceptions on my production server. I ran Eclipse MAT on the heap_dump and saw a lot of my sessions are not getting garbage collected even though they are being closed due to them being referenced by tomcatse ThreadWithAttributes obje...

Hibernate Criteria, Joins, Or

I'm trying to accomplish ad-hoc queries using joined tables, using an Restrictions.or and Restrictions.ilike My entities look like: @Entity @Table(name="CASE_REVIEW") public class CaseReview { @Id @Column(name = "REVIEW_ID", unique = true, nullable = false, length = 19) private Long reviewId; @ManyToOne(fetch = FetchT...

Grails/Hibernate: Null Pointer Exception on versioning

Working with a legacy codebase in Grails. Under some conditions (we're unclear exactly what) we get a mysterious NPE, stack trace as below, while doing a findBy. So far we're sort of stymied; this appears in several fora for Hibernate but the responses seem to come down to "something is wrong with your schema." It would be wonderful t...

Calling a Stored Procedure in Hibernate

I just started learning hibernate last night and its rather fun. I am some trouble calling a stored procedure as a sql-query with hibernate. I have attached the source and the error, please help me. Thanks :) <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "hibernate-...

jpa 2 hibernate setting a lock on EntityManager.find

Hi guys: a little strange problem.. I'm doing a few testcases on an hibernate project: when I call EntityManager em = getEntityManager(); em.find(Foo.class, 1) I get the entity as I expect, but when I invoke: EntityManager em = getEntityManager(); em.find(Foo.class, 1, LockModeType.WRITE) I'm getting null. Also, w...

How should I reset a JPA-controlled database before every test?

Is there a best-practice pattern for completely resetting a database to a freshly-paved schema with JPA before a unit test? I have been using a testing persistence unit with hbml2ddl.auto=create-or-drop and recreating EMFs before each test, but I wonder if there's a cleaner way to do it. ...

hibernate many-to-many association and spring hibernatetemplate doesn't work

I am using Spring HibernateTemplate, OpenSessionInViewFilter(actually I extended this class and created my own to switch to FLUSH.AUTO Mode) and Mysql for implementing hibernate many-to-many association. However when I save an object, corresponding many-to-many table's values are not inserted. Does anybody can help me? Thank you. here i...

How to log values that Hibernate binds to prepared statements?

How can I make Hibernate log the values it binds to prepared statements? If I set property hibernate.show_sql=true I get following kind of logging: insert into tablename (field1, field2) values (?, ?) I'd like also to know what values are bound to question marks. I am using Hibernate 3.2.7.ga. ...

Hibernate order by with nulls last

Hibernate used with PostgreSQL DB while ordering desc by a column puts null values higher than not null ones. SQL99 standard offers keyword "NULLS LAST" to declare that null values should be put lower than not nulls. Can "NULLS LAST" behaviour be achieved using Hibernate's Criteria API? ...

Criteria for SELECT bla1, bla2 FROM foo

I want a criteria that only selects bla1 and bla2 from all attributes of a given domain Foo.findAll() or def c = Foo.createCriteria() def results = c {} have: SELECT * FROM foo results = List of all attributes of given domain foo want SELECT bla1,bla2 FROM foo written as Criteria def c = Foo.createCriteria() def results = c {...

How to use ThreadLocal within Hibernate by Spring

Hello everyone, Currently we use a session per Operation (anti-) Pattern with Hibernate/Spring for our Swing client/server application. The application grew and requests got more and more complex, which resulted in bad performance issues. Because of that, we decided to reuse the session for complex requests, which need to perform more r...

HIbernate+JPA Composite Key problem: generating select sql with wrong columns

Here is my sample codes. PrimaryKey Class: public class ReplAreaElemDataCompositeKey implements Serializable{ private static final long serialVersionUID = 1L; private int imageElementID; private int variableID; public ReplAreaElemDataCompositeKey() { super(); } /** * @param imageElementID * @param variableID */ public Re...

Hibernate: How do I write the HQL for getting records of an entity without records for its identifying relation

I have Hibernate Objects defined as Class SomeText{ private Long textId; private Set<Tag> Tags = new HashSet<Tag>(); @ManyToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE }) @JoinTable(name = "text_tag_reln", joinColumns = { @JoinColumn(name = "textId") }, inverseJoinColumns = { @JoinColumn(name = "tagId") }) pu...

Composite Foreign Key lost in merge() operation (JPA/Hibernate)

Imagine an Employee Entity that references a Department using a Compound Key: @Entity public class Employee { ... @ManyToOne @JoinColumns({ @JoinColumn(name="dept_country", referencedColumnName="country"), @JoinColumn(name="dept_id", referencedColumnName="id") }) private Department dept; ... In a Stateles...

Spring app cant find hmb.xml mapping file

Hi, i am working on a spring mvc app using hibernate and i am having some trouble compiling and running my code. This is because it cannot find my FileObject.hmb.xml whenever i try to create a session factory bean. my bean looks like this <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">...

jpa2 hibernate, a testcase to test lock over an entity

Hi!, I'm using Hibernate 3.5.5.Final and JPA2 How can make a testcase to test if the hibernate lock is working? I wrote this, but seems that the test not pass in the current hibernate version (works fine in the previous version) @Test(expected=OptimisticLockException.class) public void testLock() { EntityManager em = getEntityMa...

How to create Id on hibernate entity that is a byte[] that maps to a varbinary value in mysql

I am trying to create an Entity that has a byte[12] id in hibernate. It seems like it does not like to have a byte[] as a primary key and as another column it sets it up as a tinyblob in the backing mysql db. I have tried to create a String, but the problem is that the string in java is 2 bytes per char, while it is one byte per char i...

How do i access an out parameter in a pl/sql proc via hibernate

I have a pl/sql procedure with the following signature PROCEDURE pr_log_process_started ( p_process_id IN log_process_status.process_id%TYPE, p_run_id IN OUT log_process_status.run_id%TYPE); How can i make a call to this proc via Hibernate and access the value of the second parameter after the call? ...

How to explicit set NULL value in a column in hibernate using setter method ?

I am reading an Excel file to populate a database table using Hibernate + Apache POI XSSF. For inserting the data, I am using the SETTER methods of the hibernate properties along with session.save() instead of using the traditional INSERT approach. The problem is that I want to explicitly set NULL values into nullable columns using s...

How to properly implement a domain object with composite id in Hibernate?

I have the following domain objects: public class Department { private long departmentId; } public class Manager { private long managerId; } public class Project { private ProjectId compositeId; @ManyToOne private Department department; @ManyToOne private Manager manager; } public class ProjectId...