0

I went through the Data Access With Spring tutorial and the in memory database they use in step 3 is working. But, I'm not clear on what I need to add/change to get it to query my development (Oracle) database now?

I want to use Hibernate, do I still need this JPAConfiguration class or would I have something Hibernate specific?

Please don't just post a link to the Hibernate reference. I'm reviewing that as well, but since I'm also using Spring, it's not clear to me the proper way to load the hibernate.cfg.xml and inject the Hibernate session in that context.

roark
  • 792
  • 1
  • 12
  • 29

1 Answers1

0

Don't be blocked by the fact that the class is called JPAConfiguration. You need to understand what the class does. Note that it has the annotation @Configuration which you can use along with AnnotationConfigApplicationContext to produce a Spring bean context.

That functionality is described in the Spring documentation for The IoC container.

What you need to change is how your DataSource and EntityManagerFactory beans are created. You'll need to use a DataSource that gets Connection instances from a JDBC Driver that supports Oracle databases.

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
  • Thanks, that's helpful. I'm not clear on where to put the DataSource configurations. Hibernate reference says `hibernate.cfg.xml` (http://docs.jboss.org/hibernate/orm/4.2/manual/en-US/html/ch01.html#tutorial-firstapp-configuration). Spring says this XML: http://stackoverflow.com/questions/7196311/spring-datasource-configuration-for-localhost-development-and-production. Spring Tool Suite didn't even come with any base Spring XML config files so they must be leaning towards annotations and POJO now..? Is there some class I'm looking for, i.e. new `Connection().setDriver(...)` ? – roark Oct 02 '13 at 15:47
  • @roark There's different ways to do it. The `DataSource` is just a wrapper for getting `Connection` instance from a `DriverManager` with a registered `Driver` (for Oracle in your case). It's up to you where you put this `DataSource`. It can be as a JNDI resource, in hibernate config file, directly as a `@Bean` method or `` declaration. If your other beans need to reference that instance however, you'll need to make it available in your bean context. – Sotirios Delimanolis Oct 02 '13 at 15:55
  • Ok.. I think I'm starting to get it. Is there something you'd recommend reading to get more of the big picture? – roark Oct 02 '13 at 17:30
  • @roark The IoC container document will explain the whole inner workings of Spring contexts. For JDBC try reading the chapter in the Spring documentation about Transaction Management. – Sotirios Delimanolis Oct 02 '13 at 17:31