赞
踩
- <persistence-unit name="com.demo" >
- <mapping-file>META-INF/orm.xml</mapping-file>
- <properties>
- <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
- <property name="hibernate.hbm2ddl.auto" value="validation" />
- <property name="hibernate.format_sql" value="true"/>
- <property name="hibernate.show_sql" value="false"/>
- </properties>
- </persistence-unit>
- <bean id="emfDemo"
- class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
- <property name="dataSource" ref="dataSourceDemo" />
- <property name="jpaVendorAdapter">
- <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
- <property name="generateDdl" value="true" />
- <property name="showSql" value="false" />
- </bean>
- </property>
- <property name="loadTimeWeaver">
- <bean
- class="org.springframework.instrument.classloading.InstrumentationLoadTimeWeaver" />
- </property>
- <property name="persistenceUnitName" value="com.demo" />
- </bean>
- <filter-mapping>
- <filter-name>OpenEntityManagerInViewFilter1</filter-name>
- <url-pattern>/*</url-pattern>
- </filter-mapping>
-
-
- <filter>
- <filter-name>OpenEntityManagerInViewFilter2</filter-name>
- <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
- <init-param>
- <param-name>entityManagerFactoryBeanName</param-name>
- <param-value>emfDemo</param-value>
- </init-param>
- </filter>
- @PersistenceContext(unitName="emfDemo")
- public EntityManager entityManager;
@GET @Path("/jpa/test") @Transactional public Response testJpaDemo(@QueryParam ("type") String type){ this.getService().getDao().findAll(); News news = this.getService().getDao().findOne(1L); News newsMaster = (News) entityManager.find(News.class,2L); logger.debug(news.getContent()); logger.debug(newsMaster.getContent()); News entity = new News(); entity.setContent("main"); this.getService().getDao().saveAndFlush(entity); News entityMaster = new News(); entity.setContent("master"); entityManager.persist(entityMaster); if(true) throw new GeneralException("", "test transaction"); return Response.ok().build(); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。