Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

DataSource in Spring wiht Hibernate

 
Prav Chau
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone send me code snippet for implementing my own spring datasource and using in HibernateDAO class.

Thanks
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you mean your own datasource? Do you want to implement the DataSource interface in a custom datasource class?

Otherwise you just configure it in your xml file using one of Springs DataSource classes. www.springframework.org has the documentation in Core Spring.

Good Luck

Mark
 
Prav Chau
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Basically I want to create custom Datasource which I can pass to Hibernate or JDBC through spring.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prav Chau wrote:Yes, Basically I want to create custom Datasource which I can pass to Hibernate or JDBC through spring.


OK, I am still confused at what you want.

You plan on doing this???

public class MyCustomDataSource implements DataSource {...}

If so, I must ask why you want to do this? I would never do this, since others have created better DataSource objects than I could ever create.

The only reason why you might do this yourself is if you are creating Spring Framework or creating your own App Server. Otherwise, just use the ones that they created.

But if you do want to do it, then you just create a class that implements the DataSource interface. Then in Spring when you declare your datasource bean, you just have the class attribute point to your class you created. It is just the same as if you used someone else's DataSource class.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic