Programming Tutorials Browser Tutorials Articles Struts Tutorials Hibernate Tutorials

Search: 

  Tutorial: An annotation-based persistence framework

The getter/setter idiom has always been problematic; it allows too-broad access to the implementation of your classes, degrading maintainability as a consequence.

Tutorial Details:

The J2SE 5 annotation (or metadata) feature provides an alternative. Rather than using introspection to find get/set methods, you can \"tag\" an object with an annotation and then access that annotation at either compilation or at runtime.

I have talked at length in JavaWorld about the downside of the getter/setter idiom (see Resources). This idiom was originally introduced in the JavaBeans spec as a way of \"tagging\" properties of an object so that an external UI-layout tool (called a BeanBox) could build a property sheet for that object. You would \"tag\" the property by providing methods like the following:


String getFoo();
void setFoo( String newValue );



The BeanBox uses the introspection APIs of the Class class to get a list of methods, then it uses pattern matching to find the getter/setter pairs. From these, it infers that a property exists and determines the property\'s type. (In the current example, a property called Foo is a String.) You are never expected to call these methods yourself; they exist solely for use by the BeanBox.

Interestingly, the writers of the JavaBeans spec understood just how problematic this getter/setter tagging mechanism is. (The main downside, discussed in earlier articles, is that the getter/setter methods expose too much information about the object\'s implementation, thereby making the underlying class much harder to maintain.) Consequently, the designers provided a more object-oriented solution in the BeanInfo and Customizer interfaces. User-provided implementations of these interfaces let you build a GUI without the getters and setters. Unfortunately, this overly complicated object-oriented approach was described poorly in the spec. The getter/setter approach was easy, and if you didn\'t understand the object-oriented-related maintenance issues, then the getter/setter approach seemed reasonable. Consequently, the BeanInfo/Customizer approach fell by the wayside and getter/setter strategies have been propagating like rabbits. The fact that you see the idiom everywhere doesn\'t make it good, however.

Back when JavaBeans were first proposed, many people (including myself) argued for a new keyword in Java to eliminate the need for the getters and setters. With the ability to introduce a new keyword, the Foo property I described earlier could be represented as:


private @property String foo;



Since foo is private, exposing it to the BeanBox with the new keyword doesn\'t violate encapsulation. At the time, however, introducing new keywords was anathema, even keywords impossible to confuse with existing identifiers because they included an illegal symbol, like @.

With J2SE 5, however, Sun has gotten over its delicacy and made a few major syntactic changes to the language. Now, you can introduce a new keyword (called an annotation) into the language to specify an attribute that can be examined at either compile-time or runtime. You may introduce arbitrary keywords of your own choosing. The only requirements are: the annotation (the keyword) must be preceded with an @ sign, and you must use the annotation as an adjective. (Annotations can go anywhere that you might say static, final, or public.) Finally, you can toss the getters and setters for a much cleaner syntax that does the same thing.


 

Read Tutorial at: Click here to view the tutorial

Rate Tutorial:
An annotation-based persistence framework

View Tutorial:
An annotation-based persistence framework

Related Tutorials:

Displaying 1 - 50 of about 429 Related Tutorials.

What is Persistence Framework?
What is Persistence Framework? What is Persistence Framework? A persistence framework moves the program... store the database. The persistence framework manages the database and the mapping
 
Java Persistence API
is a lightweight framework based on POJO for object-relational mapping. Java language... annotation, and does not map as an entity by the Java Persistence provider... Java Persistence API Java Persistence API
 
Persistence O/R Mapping Plug-Ins For Eclipse
Persistence O/R Mapping Plug-Ins For Eclipse Persistence O/R Mapping Plug-Ins For Eclipse    ... framework. DataXtend CE benefits: Accelerated Development - Graphical tools
 
iBatis-Showing all data from database
;        iBatis is a Data persistence framework like Hibernate, JDO and EJB that maps objects to SQL statements. It is a lightweight framework and persistence API good for persisting POJOs( Plain Old
 
Collections Framework
. This framework is based on: Interfaces that categorize common collection types... Collections Framework Collections Framework...; Java provides the Collections Framework. In the Collection Framework
 
JPA Training
;    The Java Persistence API Training Course is a step-by-step introduction to build applications using the new Java persistence... based-applications interacting with the relational database. It uses the release
 
Struts Validator Framework
Struts Validator Framework Tutorial with Example Struts Validator Framework      ... introduces you the Struts Validator Framework. In this lesson you will learn how to use
 
Hibernate Synchronizer
generation tool to be used with the Hibernate persistence framework. The plugin
 
Introduction to Collections Framework
Introduction to Collections Framework, Advantages and Disadvantages of the Collection Framework Introduction to Collections Framework         
 
Collections Framework Enhancements
Collections Framework Enhancementsin Java SE 6,SE 6, SE6 Collections Collections Framework Enhancements  ...; In Collection framework, we are able to improve the performance hashing function
 
Struts Validator Framework Tutorial with Example
Struts Validator Framework Tutorial with Example Struts Validator Framework      ... introduces you the Struts Validator Framework. In this lesson you will learn how to use
 
Foundation Framework
Foundation Framework Foundation Framework                         
 
Ajax Framework
which was developed by company IT Mill.This framework is based on Java... and is not a pixel based web framework. Core features DHTML on the server, client...:- Rico is an JavaScript framework to create Ajax-based web applications
 
Advantages and Disadvantages of the Collection Framework
Advantages and Disadvantages of the Collection Framework Advantages and Disadvantages of the Collection Framework... Collection Framework. A collection is simply an object that groups multiple
 
Java Spring Framework Programmer
Java Spring Framework Programmer Java Spring Framework Programmer         ...;      Position Vacant: Java Spring Framework
 
Hello World in Echo3 framework
Hello World in Echo3 framework Hello World in Echo3 framework        ... Framework with the "Hello World" example in Echo3. We have
 
JDemo-Java Demonstration Framework
JDemo-Java Demonstration Framework JDemo-Java Demonstration Framework       ... framework. Its concept is similar to the one of JUnit. As supplement to test
 
Spring Framework Training
Spring Framework Training  Spring Framework...;    Spring Framework Training Course... . Spring Framework Training Course Outline
 
Java 6.0 Collection Framework
Java 6.0 New Features,Java Collection Framework,Java 6.0 Features,Introduction to Java 6 Java 6.0 Collection Framework            
 
OMF OpenBlueLab Modeling Framework
to configure easily the portal. The future editor will be based on TopCased wich permit
 
Introduction to Hibernate 3.0
persistence technology at the heart of J2EE EJB 3.0 is available for download... modes and business logic in the Java-based middle-tier. Hibernate allows transparent persistence that enables the applications to switch any database. Hibernate
 
JFire - Free Java ERP framework
JFire - Free Java ERP framework JFire - Free Java ERP framework                     
 
SortedMap (interface) example in java Collection Framework
SortedMap, Java Sorted Map Example SortedMap (interface) example in java Collection Framework                 
 
Java Complete Hibernate 3.0 Tutorial Tutorial
platform. It provides powerful, ultra-high performance object/relational persistence..., composition and the Java collections framework. The Hibernate Query Language, designed... to express queries using native SQL or Java-based Criteria and Example queries
 
Complete Hibernate 3.0 Tutorial
platform. It provides powerful, ultra-high performance object/relational persistence..., composition and the Java collections framework. The Hibernate Query Language, designed... to express queries using native SQL or Java-based Criteria and Example queries
 
Hibernate 3.1.2 Released
performance object/relational persistence and query service. Hibernate lets you develop
 
Hibernate 3.1.3 Released
performance object/relational persistence and query service. Hibernate lets you develop
 
Hibernate 3.1.1 Released
persistence and query service. Hibernate lets you develop persistent classes... including 2 default implementations (JTA based and ThreadLocal based
 
Spring Training
Spring Framework Training for the Developers Spring Framework Training for the Developers    ...; Hands-On: 70%  The Spring Framework training is specially designed
 
Open Source Frameworks
is a servlet based framework that allows experienced Java developers to quickly... framework Based on the best practices of web development, thoroughly tried... and Java based open source portal framework Light is an AJAX- and Java-driven
 
Struts integration with EJB in JBOSS3.2
using STRUTS FRAMEWORK. The EJB specification provides Enterprise-level services... of Entity Beans are CMP (Container Managed Persistence), BMP  (Bean Managed Persistence). In CMP, persistence code need not be written by the programmer
 
Hibernate Training
persistence engine. How to persist different types of objects using... for object/relational mapping with Hibernate Java Persistence API...; Transparent Persistence
 
Struts Guide
; This tutorial is extensive guide to the Struts Framework. In this tutorial you will learn how to develop robust application using Jakarta Struts Framework... the Jakarta Struts Framework. What is Struts? Struts Frame work
 
HiberObjects
tests for Java Persistence API (JPA) or Hibernate. PropertyChange support
 
Struts Frameworks
The StrutsLive Framework The StrutsLive framework builds upon several ideas... of extensions to the Apache Struts framework that improve upon its default...;      Xkins framework Xkins is a framework
 
WAST
to WAST   WAST is a framework for developing web application server
 
DDchange
is an Debugging Framework that automatically determines why your program fails..., it does not. Why?. This framework is intended to increase the efficiency..., this framework will improve the productivity of your development process. Brevity
 
Struts 2 - History of Struts 2
and extensibility.  Struts is a well-organized framework based on MVC... is an open-source framework that is used for developing Java web application... an excellent framework for developing application easily by organizing JSP
 
Struts 2 Downloads
;     Struts is one of the best framework for developing... framework for constructing enterprise applications. This page keep track of all.... Struts 2 is one of the leading framework for developing enterprise web
 
Struts 2 Training
as each class of the framework is based on an Interface and all the base classes... framework classes are based on interfaces and core interfaces are independent... controller framework based on many standard technologies like Java Filters, Java
 
Why Struts 2
of the Sturts action framework and Webwork. According to the Struts 2.0.1 release... classes instead of interfaces is one of design problem of struts1 framework that has been resolved in the struts 2 framework. Most of the Struts 2
 
Why Struts 2
of the Sturts action framework and Webwork. According to the Struts 2.0.1 release... classes instead of interfaces is one of design problem of struts1 framework that has been resolved in the struts 2 framework. Most of the Struts 2
 
Struts Alternative
framework built around the concepts of separation of concerns and component-based... Struts is very robust and widely used framework, but there exists the alternative to the struts framework. Here we have listed the listed
 
Struts Frameworks
The StrutsLive Framework The StrutsLive framework builds upon several ideas... of extensions to the Apache Struts framework that improve upon its default...;      Xkins framework Xkins is a framework
 
Introduction to Dojo
we will familiarize you with the Dojo framework. Dojo is another great JavaScript framework to develop ajax based application. What is Dojo?  Dojo is JavaScript framework released as open
 
Downloading and Installing Flex

 
Welcome to the Apache Struts Tutorial
applications based on MVC framework using JSP/Servlet as base.   ..., Struts Validation Framework, Java Script validations are covered... framework as compared to struts1. The table given below describes some differences
 
WebScarab for Eclipse
for Eclipse is an extensible framework for analyzing applications
 
Introduction to Struts 2 Tags
will introduce you with the tags provided along with Struts 2 framework. It is necessary to understand all the tags provided along with Struts 2 framework
 
Struts2 Training
;      Apache Struts is an open-source framework that is used to develop Java applications. Struts is an excellent framework... the architecture of WebWork2 with features including a plugin framework, a new API
 
Site navigation
 

 

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2006. All rights reserved.