This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Mappings vs Annotations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Mappings vs Annotations" Watch "Mappings vs Annotations" New topic
Author

Mappings vs Annotations

Jonathan Huang
Ranch Hand

Joined: Jun 23, 2006
Posts: 35
Is there any significant improvement in SessionFactory Startup in using annotations over mappings?

I know there are a lot of factors that effect startup time such as complexity and length of the mapping, but because hibernate doesn't have to read in XML to map with annotations, I would guess that annotations are quicker overall.

Is this a false statement? Im trying to do some tests to find out, but because of WTP 0.7 and HibTools, im having difficulty right now. Just thought I'd ask the community.

Thanks in advance!
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

I don't think there is much of a difference in speed. I think it is more of whether you want to manually make seperate XML mapping files, or include that with Annotations. Annotations use Inspection of the Java classes to make Objects that get created at startup, where of course XML uses an IO Reader to load the XML and create the objects.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Jonathan Huang
Ranch Hand

Joined: Jun 23, 2006
Posts: 35
I did some tests, (finally got WTP and hibtools working).

The more mapping files you have the time it takes to startup is linear. Depending on the size and complexity of your mapping files.

In my tests I used 2 mappings. A small mapping file (25 lines), then a large one (125 lines). They weren't complex, just property tags mostly.

My annotated class was a rewrite of the small mapping file. I'd show you the code, but I am not permited to do so. Just think of them as <id> and <property> tags. No sets or collections.

As you can see below the mappings take a bit longer, but not by very much. But their times are a more steep startup.

Large Mappings:
Loading 1 file averaged 1850 millis
Loading 5 files averaged 2150 millis
Loading 10 files averaged 2550 millis
Loading 20 files averaged 3200 millis

Annotated Class:
Loading 1 file:
1) 2172 millis
2) 1906 millis
3) 1875 millis
4) 1750 millis
5) 2005 millis

Loading 5 files:
1) 1874 millis
2) 1922 millis
3) 2172 millis
4) 1905 millis
5) 2020 millis

Loading 10 files:
1) 2625 millis
2) 1938 millis
3) 1937 millis
4) 1937 millis
5) 2101 millis

Loading 20 files:
1) 2266 millis
2) 2093 millis
3) 2156 millis
4) 2109 millis
5) 2102 millis
[ July 24, 2006: Message edited by: Jonathan Huang ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Thanks for the information about startup, it is good information to know.

Mark
[ July 28, 2006: Message edited by: Mark Spritzler ]
Venkat Srinivas
Greenhorn

Joined: Aug 02, 2006
Posts: 5
Annotations and Mappings both have their own disadvantages

annotations when the table names and field names have to be changed need

recompilation...when Mappings don't need that...
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Mappings vs Annotations
 
Similar Threads
Hibernate Recipes: debugging
JPA - need help with query
Can i have a filter collection?
ManyToOne Composite Key with Transient Field
could not read mapping from resource