hibernate

How to get Clob data from native query

I have tried this: List resultList = session.createSQLQuery("select pack.FuncName ClobData from dual").list() whereis FuncName it is the name of function that returns clob data. But in resultList I see some proxy object (for example $Proxy189). I believe... It is something simple and I don't want ising reflection to get my data. ...

Using natural keys as part of equals and hashCode

I know that this topic has been discussed umpteen number of times, but still need some clarifications on the issue we are facing. Hibernate best practices talk about using natural keys for the equals / hashCode methods. We do have a composite key which consists of 2 parameters (say String name, Organization org) to which a particular obj...

No Row inserted when using hibernate example

Hi, I, trying to use Hibernate 3.5.3 with Postgresql 8.4 and PostGreSQL-8.4.701.jdbc4.jar and after transaction completed no actually data inserted into table. this is the table: CREATE TABLE doolloop2.dluser ( id bigint NOT NULL, firstname character varying(255), lastname character varying(255), email character varying(2...

Hibernate cascade vs manual delete

I am using Hibernate and a few times had to implement cascading DELETE operation from parent object to its children. I used the following two options. One option is to expose getChildren() on the parent object, add the child to the returned collection of children and allow Hibernate to cascade DELETE automatically. The disadvantage of ...

why is Hibernate selecting same columns twice?

Hibernate: /* load entities.Department */ select department0_.name as name4_0_, department0_.id as id4_0_ from J_DEPT department0_ where department0_.name=? Hibernate: /* load one-to-many entities.Department.employees */ select employees0_.dept as dept4_1_, employees0_.i...

Why does Hibernate re-implement functionality that databases already have?

For example: @Table(name = "stock", catalog = "mkyong", uniqueConstraints = { @UniqueConstraint(columnNames = "STOCK_NAME"), @UniqueConstraint(columnNames = "STOCK_CODE") }) or @Column(name = "STOCK_NAME", unique = true, nullable = false, length = 20) Constraints like 'unique', 'nullable', even field length are core database featu...

Why does Hibernate attempt to "cache" and how does this work in a clustered environment?

Say you have a 4-node J2EE application server cluster, all running instances of a Hibernate application. How does caching work in this situation? Does it do any good at all? Should it simply be turned off? It seems to me that data on one particular node would become stale quickly as other users hitting other nodes make changes to databa...

where to find a open source project which uses one of more of (spring,struts2,hibernate,JSF)

Hi everyone, I would like to involve in a open source project, since I prefer web development and frameworks such as spring, struts2, Hibernate and JSF, I'd like to find such a project to get involved. Can someone point me to right direction or correct me if I'm search something that didn't exists? Thank in advance, Nuwan ...

How to swap out hibernate.cfg.xml properties?

Hello all! I've got a hibernate configuration file called hibernate.cfg.xml. In this file there are hard-coded property names like: <hibernate-configuration> <session-factory> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">mysecretpassword</property> ... </s...

Partially object loading in Hibernate

I have a class that sometimes is not necessary to load fully. Can I load it partially, or I need to create light version of class (and new mappings for it)? For example: class Message with id, title, body, author, timestamp. When I want to delete message i need only two fields id, author. ...

Selecting specific fields in JPA Queries

I am using Hibernate JPA implementation org.hibernate:hibernate-entitymanager:3.4.0.GA at central maven repo. I have two classes. Class A extends Class B When I execute a query like "SELECT b FROM B b", the result list, as expected, contains Class A instances too. Is there a way to retrieve only the Class B instances without any fie...

hibernate lazy init not lazy at all!

Hi, I have an entity which has a collection as one of its attributes. That collection is mapped with a @ManyToMany annotation with fetch type lazy. The target entity also has collections as attributes, some are @OneToMany and some are @ManyToMany. When fetching the first entity (via entityManager.find(id)) its collection attribute is ...

Why do i have a mapping exception?

Hi! Right now i want to make a small java application, in order to learn the hibernate framework. But it gives me the org.hibernate.MappingException: Repeated column in mapping for entity: model.Book column: author (should be mapped with insert="false" update="false"). And if I delete the author column mapping from entities.hbm.xml, the...

getCurrentSession hibernate in web

Hi, I am writing a web based application with hibernate and jsp/servert. I have read about sessionFactory.getCurrentSession and sessionFactory.openSession methods. I know the basic difference between them [using getCurrentSession you dont have to close connection and when you commit the trasaction, your session automatically close]. Acc...

JPA OneToOne clarifications

I was reading this book. Explaing about "@OneToOne unidirectional", the author has taken the following Customer, Address example: @Entity public class Customer{ @Id @GeneratedValue private Long id; private String name; private Address address; //few other columns, getters/setters } @Entity public class Address{ @Id @G...

org.hibernate.QueryException: Not all named parameters have been set

Hi all, I'm getting extremely weird behavior out of JPA 2.0 Criteria API with Hibernate 3.5.1-Final as a provider. I'm trying to build a dynamic query that looks like this in JPQL: SELECT e FROM Employee e WHERE lower(e.firstName) like lower(:employeeName) OR lower(e.lastName) like lower(:employeeName) but keep getting the er...

Hibernate: How to persist Class that contains Map<String, List<String>>

I want to persist the following class, including 'bar' Class Foo { Map<String, List<String>> bar; // ... // other stuff..... } How do I do this in Hibernate? If possible, how to do this in Hibernate with annotations? Oh, the nature of the Map key String is that there are a small number of them (5-40), and they are the same acr...

about frameworks

How many web-frameworks do we have and what are they? ...

How to get the most recently added row from a certain table

How to get the most recently added row from a certain table, which satisfies a certain condition. If I use javax/persistence/Query.html#getSingleResult() we get a NonUniqueResultException if there are multiple rows satisifying the query. I need the equivalent of findOne from the list. I would prefer not to paginate by setting the rowsPe...

Convert a SQL query to HQL

Hi my question is simple but may a little bit rude. Could please one of you convert two SQL Query to hql :> Select statistic.* FROM statistic INNER JOIN (SELECT MAX(st_id) AS id " + "FROM statistic WHERE status = 'N' GROUP BY bc_id) ids ON statistic.st_id = ids.id" + "ORDER BY bussinessprocessID; Select post_id, u_post_id FROM statist...