Wednesday, August 29, 2012

Spring Framework with Hibernate JPA

The few articles prior to this discussed the conjunctive use of
  • GWT as REST client
  • JAX-RS REST service
  • JPA2
  • A POJO data transfer schema shared across the three frameworks

This article furthers the conjunction by including the deployment of Spring Framework. Therefore, the technology conjunctivitis now comprises
  • GWT
  • RestyGWT
  • RestEasy
  • Hibernate 3.x in JPA 2.x mode
  • Spring Framework's inversion of control to configure Hibernate.
Reason for Spring Framework
The reason for including Spring Framework is to exploit its ability to turn away from Hibernate's persistence.xml hard-coded values towards Spring's ability to make the persistence definition agile and adaptive. I should have used the term "dynamic" definition rather than agile/adaptive. 

However, being dynamic would mean we would change those configuration in the middle of playing the game. Not so, we only want to adaptively define those values during application loading. We want to place variables in Hibernate connectivity that are resolved during application loading.

So that we do not have to manually, or write an application within an application to, modify persistence.xml hard-coded values when deploying the app across disparate systems.

The issue at hand is
how to use Spring Framework to configure Hibernate as a JPA 2.x provider.

The usual persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
  version="1.0">
    <persistence-unit name="obamacare"
      transaction-type="RESOURCE_LOCAL">
    <provider>
      org.hibernate.ejb.HibernatePersistence
    </provider>
    <exclude-unlisted-classes>
      false
    </exclude-unlisted-classes>
    <!-- Scan for annotated classes and Hibernate mapping XML files -->
    <properties>
      <property name="hibernate.archive.autodetection"
        value="class, hbm"/>
      <property name="javax.persistence.jdbc.driver"
        value="oracle.jdbc.driver.OracleDriver"/>
      <property name="javax.persistence.jdbc.url"
        value="jdbc:oracle:thin:@holymoly.kacang.putty"/>
      <property name="javax.persistence.jdbc.user"
        value="durian"/>
      <property name="javax.persistence.jdbc.password"
        value="langsat"/>
      <property name="hibernate.dialect"
        value="org.hibernate.dialect.OracleDialect"/>
     <property name="hibernate.show_sql"
        value="true"/>
    </properties>
  </persistence-unit>
</persistence>

The goal is to conceptually be able to do this:
    <properties>
      <property name="hibernate.archive.autodetection"
        value="class, hbm"/>
      <property name="javax.persistence.jdbc.driver"
        value="${zzz.rambutan.driver}"/>
      <property name="javax.persistence.jdbc.url"
        value="${zzz.rambutan.url}"/>
      <property name="javax.persistence.jdbc.user"
        value="${zzz.rambutan.user}"/>
      <property name="javax.persistence.jdbc.password"
        value="${zzz.rambutan.password}"/>
      <property name="hibernate.dialect"
        value="${zzz.rambutan.hibernate.dialect}"/>
     <property name="hibernate.show_sql"
        value="${zzz.rambutan.isDebug}"/>
    </properties>

However, neither JPA nor Hibernate is able to accept variables in the persistence.xml file. Therefore, we would have to depend on Spring's ApplicationContext.xml ability to accept variables.

5 comments:

  1. Picking a new book to read can be a daunting task. Books can eat up hours of your day and in today world no one has time to waste thumbing through a boring tale. And Canada can receive customized suggestions from the works of bestselling novelist Stephen King directly from their smart speaker.. (Michael Kors Black And White Crossbody Bag)

    Province legal argument notes that while city clerk office has indicated election officials can run a 25 ward election on Oct. 22, they are not confident about reverting back to a 47 ward model by that date if ordered to by the court. And it notes the city plan to increase the size of council to 47 seats won achieve voter parity until 2026, while a 25 ward model does that immediately.. (Michael Kors Raven Bag Black)

    Red White Blue Coach Purse, Book Lover Delight: The Best Bookstores In CambridgeDo you prefer the turning of a paper page to swiping an e reader? Here are some top spots to venture next time you in the mood for a good read. At Fenway Park. It will move down Lansdowne Street, take a right on Ipswich Street, a left on Boylston Street all the way down to Tremont, where the duck boats will turn left and head to Cambridge Street and then right on to Staniford Street where the parade will end..

    Pink And White Leather Coach Purse, The Toyota Corolla compact sedan offers reliable, inexpensive transportation. The Corolla delivers high value for its moderate price. It looks fresh, with crisp lines, it's quiet underway, and it boasts all the technology expected by today's compact car shoppers.

    He was the one I mentioned earlier who taught the class on behavior analysis and had us read the two Skinner books. I think he truly embodied the behavioral worldview in everything he did. By this I mean that the behavioral worldview is one of determinism a world in which no individual's behavior is "outside the causal stream" though I don't like talking in terms of "causes." If one takes this view then one can truly be compassionate towards others as one cannot "blame the organism" for their behavior. (Michael Kors Black Suede Purse)

    ReplyDelete
  2. Air Jordan 1 Black Sail White Gym Red Stockx, While major brands such as Nike and Adidas may be willing to offload unsold product via outlets, others such as RYU don't discount their merchandise.RYU's quality products come from the top. Each item is designed by fashion tycoon and CEO Marcello Leone to achieve a professional level of performance. Leone is personally involved in the design and testing of each product on RYU's line, ensuring each item will perform after every use.

    On the one hand were the superhumanly fit Russians, who had won the last four Olympic golds and not lost to the US since 1960. {tag: Adidas Yeezy Boost 350 V2 Cream White ????}Maple sugaring season is winding down, but I made 5 quarts from my backyard trees. {tag: Yeezy Cream White Size 12}

    Air Jordan 1 Mid Black Black Black, The series against Toronto was just as intense, a 3 2 extra time result in every game other than a 2 1 Leafs win at the Forum. Richard won Game 2 to even the series. In Game 5, the hero could well have been Tod Sloan, a cousin of future Leafs captain Dave Keon, who scored late on Gerry McNeil to push the game to OT.

    They just got (tight end) Hayden Hurst. {tag: Adidas Yeezy White 350 V2}Air Jordan 6 Vi Retro Black Infrared, Millions of people out of work, said House Speaker Nancy Pelosi, D Calif. "This is really a very, very, very sad day. We come to the floor with nearly 50,000 deaths, a huge number of people impacted, and the uncertainty of it all.

    They cost around, I think, $230, retail should be able to sell for about $600.. {tag: Off White Yeezy 750}"Air Jordan 1 Black And Red Retro, This series is the first seven in forty paintings. I have no idea when all forty will be finished, maybe never, but my goal is to finish forty paintings on paper, Using cotton on the bottom half with different images for the top halves. I suppose the idea for these images came as the result of viewing the paintings of Helga by Andrew Wyeth.

    ReplyDelete