P E N C I L
Login
JPA Spring
  1. Code
    1. @PersistenceContext private Entitmanager em;
      @Transactional()
      em.persist(entity
  2. Beans:
    <bean id="txManager" class="org.springframework.orm.jpa.JpaTransactionManager">
          <property name="entityManagerFactory" ref="entityManagerFactoryBean" />
    </bean>
    <bean id="entityManagerFactoryBean" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
         <property name="dataSource" ref="my-data-source"/>
         <property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"/>
         <property name="jpaVendorAdapter"><bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/></property>
         <property name="jpaProperties"><props>
    <!-- Explicitly setting the dialect prevents Hibernate from crashing on startup if the DB is down -->
    <!-- For all Oracle DB at Swissquote, the correct dialect is org.hibernate.dialect.Oracle10gDialect -->
    <!-- Despite its name, this dialect covers Oracle 10g AND all the later versions -->
    <!-- We recommend to make this value overridable via IT-Config, just in case it is necessary. -->
             <prop key="hibernate.dialect">${datasource.sqm-soa-sample>hibernate.dialect:org.hibernate.dialect.Oracle10gDialect}</prop>
          </props>
          </property>
    </bean>
  3. Persistence.xml
    <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_2_0.xsd" version="2.0">
         <persistence-unit name="com.swissquote.fox.plugin.watchlists.fox-watchlists-plugin">
              <class>com.swissquote.fox.plugin.watchlists.resources.v3.services.entity.QuoteListMobileParameters</class>
         </persistence-unit>
    </persistence>