hibernate – config properties 4 ways to set

Four “equivalent” methods:

1) xml — Traditional

2) properties file — Traditional

3) set programmatically in source code

4) pass in on java command line as -D


hibernate losing popularity on Wall St?


I’m always rather suspicious about newer app-dev technologies – android, distributed cache, weblogic, ruby, php, jaxb, xls, web service… I feel all of these (including superpowers Spring and WPF) will have to stand more tests of time.

With the decline of EJB, I don’t know what weblogic, websphere and JBoss are good for. Servlet containers? But tomcat is quite adequate?

Now I feel hibernate is not as popular as it used to be, at least in finance. My recent Wall St projects all decided not to use hibernate. We chose JDBC. It’s not that we don’t know hibernate. We know it well enough to avoid it.

It actually took these many years (5 +) for wall st developers to see the value/cost/benefit/limitations of Hibernate. Therefore, in the first few years of a new technology, it’s hard to predict if it will catch on, dominate and become entrenched. Over the past 30 years, only a small number of app development technologies achieved that status – SQL, MOM, threading, browser-based enterprise app, Excel, socket, javascript, and of course java/c++.

hibernate mock interview question

short and imprecise? ok
[m=answer found in official hibernate manual such as http://www.hibernate.org/hib_docs/v3/reference/en/html/tutorial.html ]
page numbers -> [[ java enterprise in a nutshell ]]

  1. how do you process a bunch of records when you select half the columns? What kind of data structure does hibernate return? P 650
  2. how do u update a “disconnected object”
  3. why proxy?
  4. Lazy loading? (seems to be important)
  5. write a finder statement used in your (pushmail) DAO class to illustrate the difference hql ^ sql
  6. big signature of Session.load(). AR-revealing!
  7. access modifier for fields in a domain object? P 630
  8. name the 2 types of hib config files
  9. generator class=”native” means? P 627
  10. what typical java types to use for persistent fields?
  11. what happens if there’s a clash in an id field/column when writing to DB? P627
  12. describe exactly when hibernate writes to DB. I think this is covered in my blog. P643
  13. what’s a bag?
  14. describe the session object
  15. describe the query object
  16. what’s the difference between the properties file vs the xml file
  17. what performance issues did you face using hibernate?
  18. how did you integrate hibernate with proc?
  19. 2 types of hibernate caching? (2nd-level caching)

non-iview questions:
* how does hibernate manage connection pool(s)? P641
* what if you try to load one object and all the linked objects are loaded and it takes huge memory and db query resources?

hibernate m:1 LotException

        <many-to-one name="lotBean" column="LotId"
          insert=”false” update=”false”
          not-null=”false” not-found=”ignore”/> —–> ignore if a LotException object has a null lotBean or an invalid lotBean which doesn't exist in the lotBean table.
Also note LotId column in this table is mapped twice.

Hibernate basic 2-table join — nested scan implemented in java

Zhu Rong,

To my dismay, hibernate (a popular,stable,fast java ORM framework) implements a 2 table join with individual SELECT’s on the inner table. As you explained, it’s more efficient to join inside the database?

Here’s my experiment. Hibernate supports a basic many-to-one mapping. Student object/table joining Course object/table. if i load 22 Student objects, hibernate uses lazy loading to delay querying the Course table until necessary. When it does query Course, it uses CourseId (join column, but not necessarily a PK or FK) to select just one Course. If 22 students are in 11 courses, hibernates runs 11 queries!

real world challenges using hibernate

1) performance. Hierbernate holds up well for mid-sized databases. For one GS system, we employ 3 techniques
* configuation on cachsing, lazy loading etc
* customize important queries using HQL
* hand-written SQL, when the generated SQL isn't optimized, but this tends to disable builtin performance features such as caching.
2) doens't work easily with stored procedures
3) if another db operation is already coded using jdbc, then one transaction can't easily span both

hibernate interceptors

In one GS system, we use interceptor to incercept inserts or deletes. As a standard, we don't put business logic in interceptors.
We put in lastUpdated and lastUpdatedBy and such things. It's somewhat similar to triggers but more efficient.

template objects in spring framework

*JMS — a template instance is a jms session
** anon inner class

*JDBC — a template instance is a database connection
** callback — an anon inner class

*hibernate — a template instance is a hibernate Session

*transaction — a template instance is a … transaction session?
** callback — an anon inner class

Spring Templates follow template-method design pattern. The callback objects provide the missing steps int the template method.

tibRV transport^connection^session

In JMS, session represents (roughly) a connection, or a socket. More precisely, one or more sessions are created from a single live connection. In JMS, sessions are single-threaded.

In RV, transport is the terminology. Means the same as a session, a socket, a connection to the “network”, to the daemon… Transport is a real object in memory.

In hibernate, session represents a connection to the DB. More precisely, a hibernate session HAS-A real connection object in memory