-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: How to get entitymanager in this program ?
PostPosted: Tue Mar 19, 2013 12:50 pm 
Newbie

Joined: Tue Mar 19, 2013 12:29 pm
Posts: 3
frist,I have applicationContext.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:cache="http://www.springframework.org/schema/cache"
   xsi:schemaLocation="
                    http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                    http://www.springframework.org/schema/tx
                    http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
                    http://www.springframework.org/schema/aop
                    http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
                    http://www.springframework.org/schema/context     
                    http://www.springframework.org/schema/context/spring-context-3.1.xsd
                    http://www.springframework.org/schema/cache
                    http://www.springframework.org/schema/cache/spring-cache-3.1.xsd">

   <context:annotation-config />

   <context:component-scan base-package="org.yinxin.cms">
      <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" />
   </context:component-scan>

   <context:property-placeholder location="classpath:jdbc.properties" />
   <bean id="dataSource" class="com.jolbox.bonecp.BoneCPDataSource"
      destroy-method="close">
      <property name="driverClass" value="${jdbc.driverClassName}" />
      <property name="jdbcUrl" value="${jdbc.url}" />
      <property name="username" value="${jdbc.username}" />
      <property name="password" value="${jdbc.password}" />
      <property name="idleConnectionTestPeriod"
         value="${BoneCP.idleConnectionTestPeriod}" />
      <property name="idleMaxAge" value="${BoneCP.idleMaxAge}" />
      <property name="maxConnectionsPerPartition"
         value="${BoneCP.maxConnectionsPerPartition}" />
      <property name="minConnectionsPerPartition"
         value="${BoneCP.minConnectionsPerPartition}" />
      <property name="partitionCount"
         value="${BoneCP.partitionCount}" />
      <property name="acquireIncrement"
         value="${BoneCP.acquireIncrement}" />
      <property name="statementsCacheSize"
         value="${BoneCP.statementsCacheSize}" />
      
      <property name="releaseHelperThreads"
         value="${BoneCP.releaseHelperThreads}" />
   </bean>

   <bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
      <property name="dataSource" ref="dataSource" />
      <property name="persistenceProvider" ref="persistenceProvider" />
      <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
      <property name="jpaDialect" ref="jpaDialect" />

      <property name="packagesToScan" value="org.yinxin.cms.entity" />

      <property name="jpaProperties">
         <props>
            <prop key="hibernate.dialect">
               org.hibernate.dialect.MySQL5Dialect
            </prop>
            <prop key="hibernate.connection.driver_class">
               com.mysql.jdbc.Driver
            </prop>
            <prop key="hibernate.max_fetch_depth">3</prop>
            <prop key="hibernate.jdbc.fetch_size">18</prop>
            <prop key="hibernate.jdbc.batch_size">10</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.format_sql">true</prop>
            <prop key="javax.persistence.validation.mode">
               none
            </prop>
            <prop key="hibernate.search.default.directory_provider">filesystem</prop>
            <prop key="hibernate.search.default.indexBase">d:/indexs</prop>
         </props>
      </property>
   </bean>
   <bean id="persistenceProvider"
      class="org.hibernate.ejb.HibernatePersistence" />
   <bean id="jpaVendorAdapter"
      class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
      <property name="database" value="MYSQL" />
   </bean>
   <bean id="jpaDialect"
      class="org.springframework.orm.jpa.vendor.HibernateJpaDialect" />
   <bean id="txManager"
      class="org.springframework.orm.jpa.JpaTransactionManager">
      <property name="entityManagerFactory"
         ref="entityManagerFactory" />
   </bean>
   <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter">
      <property name="messageConverters">
         <list>
            <bean class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter" />
         </list>
      </property>
   </bean>
</beans>


and dispatcher-servlet.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="
                http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                http://www.springframework.org/schema/context
                http://www.springframework.org/schema/context/spring-context-3.1.xsd
                http://www.springframework.org/schema/mvc
                http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd">

   <mvc:annotation-driven />
   
   <context:component-scan base-package="org.yinxin.cms.controller" />
   
   <mvc:resources mapping="/resources/**" location="/resources/"/>

   <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
      <property name="prefix" value="/WEB-INF/jsp/" />
      <property name="suffix" value=".jsp" />
   </bean>
</beans>


problem : I use @PersistenceContext protected EntityManager em to org.yinxin.cms.dao.common.DefultBaseDao,no problem,but I use
again @PersistenceContext protected EntityManager em to other class ,em don't work.

Because FullTextEntityManager need em,so why? How to get more EntityManager ?


Top
 Profile  
 
 Post subject: Re: How to get entitymanager in this program ?
PostPosted: Wed Mar 20, 2013 8:42 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
I'm not a Spring expert, but just take the entityManager as you would normally do without using Hibernate Search, then convert it to a FullTextEntityManager using

Code:
import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.jpa.Search;

...

FullTextEntityManager ftem = Search.getFullTextEntityManager( entityManager );

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
 Post subject: Re: How to get entitymanager in this program ?
PostPosted: Wed Mar 20, 2013 11:09 am 
Newbie

Joined: Tue Mar 19, 2013 12:29 pm
Posts: 3
sanne.grinovero wrote:
I'm not a Spring expert, but just take the entityManager as you would normally do without using Hibernate Search, then convert it to a FullTextEntityManager using

Code:
import org.hibernate.search.jpa.FullTextEntityManager;
import org.hibernate.search.jpa.Search;

...

FullTextEntityManager ftem = Search.getFullTextEntityManager( entityManager );



yes ,I know Search.getFullTextEntityManager( entityManager );

But now the problem is @PersistenceContext entityManager Only get once,

Again using is invalid ! So I want know "How to get more entitymanager "


Top
 Profile  
 
 Post subject: Re: How to get entitymanager in this program ?
PostPosted: Wed Mar 20, 2013 11:51 am 
Hibernate Team
Hibernate Team

Joined: Fri Oct 05, 2007 4:47 pm
Posts: 2536
Location: Third rock from the Sun
I'm sorry I don't understand your question. What is your question? What is the problem?

_________________
Sanne
http://in.relation.to/


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.