Points to remember
-----------------
Identity
Equality
SubTypes - inheritence using sub and super classes
Granularity
Associations
Object Graph navigation - minimize the numebr of requests to DB
Why ORM
------
Productivity
Maintainability
Performance
Vendor independence
Two-Phase Commits
Points to Ponder for ORM
-----------------------
1) Core Interfaces called by applications to perform basic CRUD
Session, SessionFactory,Configuration,Transaction,Query and Criteria
2) Callback interfaces that allow the application to react to events occurring inside Hibernate
Interceptor, Lifecycle, and Validatable.
3) Interfaces that allow extension of Hibernate’s powerful mapping functionality
Dialect,PropertyAccessor,Cache and CacheProvider,UserType, CompositeUserType, and IdentifierGenerator
4) makes use of existing Java APIs, including JDBC), Java Transaction API (JTA, and Java Naming and Directory Interface (JNDI).
5) Configuration in managed environments using Resource Manager and Transaction Manager
6) Configuration in non-managed environments using Conenction Pool and user-managed JDBC Connections.
7) write-behind
Hibernate executes SQL statements asynchronously. SQL statements are usually issued at the end of a transaction.
8) Addressing leakage of concerns
Domain model implementation shouldn’t depend on other Java APIs. shouldn’t perform JNDI lookups or call the database via the JDBC AP
9) Transparent and automated persistence
complete separation of concerns between the persistent classes of the domain model and the persistence logic
10) Hibernate doesn’t require that persistent classes implement Serializable. However, when objects are stored in an HttpSession or passed by value using RMI, serialization is necessary.
11) Hibernate requires a constructor with no arguments for every persistent class
12) object/relational mapping metadata
ORM tools require a metadata format for the application to specify the mapping between classes and tables, properties and columns, associations and foreign keys,
Java types and SQL types
13) The Hibernate mapping DTD should be declared in every mapping file Mappings are declared inside a <hibernate-mapping> element
14) Hibernate property mapping defines a JavaBeans property name, a database column name, and the name of a Hibernate type.
derived properties
<property name="averageBidAmount" formula="( select AVG(b.AMOUNT) from BID b ? where b.ITEM_ID = ITEM_ID )" type="big_decimal"/>
property access strategies
15) Support for fine-grained object models "more classes than tables" for implementing type-safety and behavior
16) An object of entity type has its own database identity (primary key value).
Entity classes are always mapped to the database using <class>, <subclass>,and <joined-subclass> mapping elements
An object of value type has no database identity; it belongs to an entity
17) aggregation "a part of" relationship. Aggregation is a strong form of association
18) Inheritance
Table per concrete class Discard polymorphism and inheritance
Table per class hierarchy Enable polymorphism by denormalizing using "discriminator" and "subclass"
Table per subclass Represent "is a" (inheritance) relationships as "has a"(foreign key) relationship using "joined-subclass"
19) Association
Simple = using getter methods from parent to child. Mapping file of parent will have <many-to-one> to class child.
Bidirctional = mapping file of child will have <Set> <one-to-many> to class parent with inverse="true"
20) The cascade attribute is directional: It applies to only one end of the association
cascade="none"
the default, tells Hibernate to ignore the association.
save-update:
cascades save and update actions from the parent to the child. Tells Hibernate to navigate the association when the
transaction is committed and when an object is passed to save() or update() and save newly instantiated transient instances and persist changes to
detached instances.
delete:
cascades the delete action from the parent to the child. Delete children that are shared with existing parents
tells Hibernate to navigate the association and delete persistent instances when an object is passed to delete()
All:
all actions are cascaded from the parent to the child. All is the union of save-update and delete
calls to evict and lock
all-delete-orphan:
Hibernate will delete any persistent entity instance that has been removed
all actions are cascaded from the parent to the child, orphan children are deleted
means the same as cascade="all" but, in addition, Hibernate deletes any persistent entity instance that has been removed
delete-orphan :
21) Transient objects
instantiated using the new operator aren’t immediately persistent.
Their state is transient, which means they aren’t associated with any database table row, and so their state is lost as soon as they’re dereferenced
22) Persistent objects
objects instantiated by the application and then made persistent by calling the save()
23) Detached objects - indicating that their state is no longer guaranteed to be synchronized with database state;
When a transaction completes, the persistent instances associated with the persistence manager still exist.
instances lose their association with the persistence manager when you close() the Session
24) persistence by reachability
instance becomes persistent when the application creates an object reference to the instance from another instance that is already persistent
25) Fetching strategies
Immediate fetching - The associated object is fetched immediately, using a sequential database read (or cache lookup).
Lazy fetching - The associated object or collection is fetched "lazily," when it’s first accessed.
This results in a new request to the database (unless the associated object is cached).
Eager fetching - The associated object or collection is fetched together with the owning object,
using an SQL outer join, and no further database request is required.
Batch fetching - This approach may be used to improve the performance oflazy fetching by retrieving a
batch of objects or collections when a lazy association is accessed.
(Batch fetching may also be used to improve the performance of immediate fetching.)
26) Isolation problems
Lost update
Dirty read - One transaction reads changes made by another transaction that hasn’t yet been committed
Unrepeatable read - reads a row twice and reads different state each time
Second lost updates problem
Phantom read - caused by another transaction inserting new rows between the execution of the two queries
27) Isolation levels
Read uncommitted - Permits dirty reads but not lost updates
Read committed - Permits unrepeatable reads but not dirty reads. momentary shared read locks and exclusive write locks
Repeatable read - Permits neither unrepeatable reads nor dirty reads. using shared read locks and exclusive write lock
Serializable - Provides the strictest transaction isolation
28) pessimistic lock
Lock that is acquired when an item of data is read and that is held until transaction completion
LockMode.NONE - Don’t go to the database unless the object isn’t in either cache.
LockMode.READ - Bypass both levels of the cache, and perform a version check to
verify that the object in memory is the same version that currently exists in the database
LockMode.UPDGRADE -
LockMode.UPDGRADE_NOWAIT -
LockMode.WRITE -
29) Optimistic Locking
version or timestamp columns
30) Collections
Set
Map and List - needs an index column to the database table
Sorted collection - Sorted in memory using a Java comparator.
Ordered collection - ordered at the database level using an SQL query with an order by clause
My Quotes
When U were born , you cried and the world rejoiced
Live U'r life in such a way that when you go
THE WORLD SHOULD CRY
Powered by Find-IP.net
Friday, April 13, 2012
Hibernate in a pocket
Wednesday, April 11, 2012
Clear DNS cache in various OS
To flush DNS cache in Microsoft Windows (Win XP, Win ME, Win 2000):-
- Start -> Run -> type cmd
- in command prompt, type ipconfig /flushdns
- Done! You Window DNS cache has just been flush.
To flush the DNS cache in Linux, restart the nscd daemon:-
- To restart the nscd daemon, type /etc/rc.d/init.d/nscd restart in your terminal
- Once you run the command your linux DNS cache will flush.
To flush the DNS cache in Mac OS X Leopard:-
- type lookupd -flushcache in your terminal to flush the DNS resolver cache.
- ex: bash-2.05a$ lookupd -flushcache
- Once you run the command your DNS cache (in Mac OS X) will flush.
To flush the DNS cache in Mac OS X:-
- type dscacheutil -flushcache in your terminal to flush the DNS resolver cache.
- ex: bash-2.05a$ dscacheutil -flushcache
- Once you run the command your DNS cache (in Mac OS X Leopard) will flush.
To flush the DNS cache in Solaris:-
Do a
- # ps -ef | grep nscd
This will find the PID for the NSCD daemon.
Now, do a
- #pkill <PID>
or
- #kill <PID>
Now, check if the nscd process is killed by using
- # ps -ef | grep nscd
Now, start the nscd daemon by using
- #/usr/sbin/nscd
This should start the nscd daemon and there you go, you have flushed the DNS Cache in your Solaris Server
Monday, January 30, 2012
SimpleDateFormat not available with GWT
Fix - Add the following lines of code in your .gwt.xml
<!-- see http://code.google.com/p/gwtx/ -->
<inherits name="com.googlecode.gwtx.Java" />
b. Add the gwtx-1.5.3.jar to your WEB-INF/lib
Unable to start Google APP Engine java.lang.NoSuchMethodError: org.mortbay.thread.Timeout
This usual indicates problems with the classpath. Do you have multiple versions of Jetty in your classpath by any chance?
To identify duplicate classes in eclipse, hit Ctrl+Shift+T to bring the 'Open Type' dialog. Search for the class org.mortbay.thread.Timeout. Ideally it should only come in gwt-dev.jar, but I suspect in your case some other jar file would also have it.
Also open .classpath in your eclipse
GWT container comes before the APP ENGINE
<classpathentry kind="con"
path="com.google.gwt.eclipse.core.GWT_CONTAINER"/>
<classpathentry kind="con"
path="com.google.appengine.eclipse.core.GAE_CONTAINER"/>
I had the same issue and I swapped the order of the classpath
and my errors are
gone now.
Mirroring Subversion Repository
Create a new repository to be the mirror:
· svnadmin create MIRROR_CONTAINER
· Create a "pre-revprop-change" action by creating a hook script by the same name.
o Go to MIRROR_CONTAINER\hooks.
o create a file named pre-revprop-change.bat
o The contents will be as follows
Change the <<SVN USER>> to the user who will be performing the sync
IF "%3" == "<<SVN USER>>" (goto :label1) else (echo "Only the syncuser user may change revision properties" >&2 )
exit 1
goto :eof
:label1
exit 0
· Save this file
· Initialize a path within the repository to contain the mirrored data, and specify the source by
o If the path has spaces then enlose them with the double quotes
o For example my remote repository (MIRROR_CONTAINER) was in my shared folder so I use like the following
· svnsync init --username <<SVN USER>> file:///"<<MIRROR_CONTAINER>>" <<BASE SVN location>> svn://162.66.224.77:48000/UFG
· svnsync sync --username <<SVN USER>> file:///"<<MIRROR_CONTAINER>>"
Eclipe SVN integration after deleting a project
Once you delete a project in eclipse, the SVN sharing will automatically go OFF.
Without knowing this, I was trying to update the SVN plugin again and again.
The easy way is to right click on the Project à Share Project à Choose SVN and give your SVN location again.
Its as simple as that
Tuesday, July 26, 2011
Shared libraries with Tomcat 6
Now that we have removed the WEB-INF\LIB folders your WAR files will not have them . So when you deploy the code into Tomcat, Tomcat will complain while deploying that these libs are not found (ClassNoutFoundException).
In order to prevent this, you can create the shared libs in Tomcat also.
The most preferred way is to put all the jar files into the location commonly used within a Tomcat 6 installation for shared code is$CATALINA_HOME/lib. JAR files placed here are visible both to web applications and internal Tomcat code.
This is because Tomcat 6.0 does not have any directory where we can put third-party jars (like our “<$pserver>/server/lib/ext” directory).
But there is the other way if you do not want to share this with Tomcat.
<<Tomcat Home>>\conf\catalina.properties
Look for the property
shared.loader=
change this to
shared.loader=<<your library folder>>\*.jar
prior to this version of Tomcat, external/third party jar could be placed inside following locations:
1) ${catalina.base}/shared/lib/ – jar needs to be shared by all the deployed applications only(to share classes across all web applications)
2)${catalina.base}/common/lib/ – jar need to be shared by web server and applications.
Subscribe to:
Posts
(
Atom
)