• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DataSource vs SessionFactory

 
cempaka melati
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having a hard time describing the differences between a DataSource and a SessionFactory (like what is provided by Hibernate) to a client. How they are different, what the pros and cons are for each.

If any of you can give me an example (not code but verbal example) or analogies that would be awesome.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well a DataSource is a "Connection" to the database. The Session Factory is so that you can complete "queries" on the database and include it in a Transaction if you want. The session is kind of like a Transaction in that you can do some updates and it will be in cache not hitting the "database" yet, until you commit.

Now my description is high level and not as accurate as if it was a detailed description, but it should give you a basic idea of the difference.

A DataSource defines and makes connection to the database, a Session is used to do work on the data.

Mark
 
cempaka melati
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thought of this a bit more but not sure if it is a good analogy

The datasource is like the phone line. The phone book is JNDI since the datasource you created can be looked up in the JNDI directory. SessionFactory is a lawyer that knows what his clients want (mapping objects ot database) and wanting to use the datasource phone line in order to send/store the message.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic