Skip to content

Spring – Hibernate

July 23, 2008


That is your application context can be read as a system property by log4j properties file – it becomes a system property.

Question is : Who makes this like a system property?
Answer is : WebAppRootListener of web.util in spring.
Keep it unique for tomcat.

To enable a read of log4j after sometime – use the param. else without refresh loaded once only: Use only if local logging.

Log4j’s watchdog thread does not terminate until VM shutdown
Dont use it in production – pooh pooh. Need an admin update of properties then!.

Two types of logging setup:
Global:   VM-wide log4j setup Jboss  or JDK 1.4’s   logging

ContextLoaderListener – loads all contexts

Use the DataAccessException which is an unchecked exception raised for irrespective of any of the frameworks that you are using. This helps ur code by framework agnostic. And also that it is an unchecked exception which is raised – which you may or may not catch.

Template pattern:
Templates manage the fixed part of the
process while your custom data access code is handled in the callbacks

DAO Support classes along with  DAO Template classes.h

`-NamedParameterJdbcTemplate : named param
`-SimpleJdbcTemplate : use varargs for dynamic arr [] params.
use ParameterizedRowMapper – autobox val

Using DAO support class – eliminates the need to explicitly declare
a JdbcTemplate bean in Spring.  that is all. you still need to give it the datasource reference.

Lazy loading – load objects later.
Eager Fetching: graph entire objects.
Cascading – push changes to relatives as well.

toplink, hibernate, iBatis, Apache OJB.

~ DataSource -> SessionBean
~ SessionBean -> HibSessionFactory
~ HibSessionFactory-> HibTemplate

HDaoSupp – no need to inject hibTemplate directly.

iBatis and Hibernate – Difference
Factors:  query-language support, performance, and portability
Relational database technology emphasizes data and its relationships, whereas the object-oriented paradigm used in Java concentrates not on the data itself, but on the operations performed on that data. Hence, when these two technologies are required to work together, there is a conflict of interests.

Also, ORM cannot be used when there is a mismatch between the object model and the data model. As we’ve mentioned, JDBC code was once the common solution to such problems, but it introduced a lot of database code within application code, making applications harder to maintain. A persistence layer is needed to decouple the application and the database

iBatis uses a data mapper which maps objects to output and not a metadata wrapper (Hiber)  that wraps objects to tables in the dtatabase

*  SQLMapConfig.xml has datasource configuration
* SQLMap.xml

iBATIS : SQL-centric,
fully ORM tools generate SQL, whereas iBATIS uses SQL directly.

iBATIS is also inappropriate for non-relational databases, because such databases do not support transactions and other key features that iBATIS uses – Use it when do not have control over DB schema –

HQL queries are case insensitive, except for the names of the Java classes and properties being used Use it when you have control over db and app.

Hiber has two interfaces — Session and Transaction — along with the Query interface, which is in the persistence layer of the application

No comments yet

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: