hardy.ferentschik wrote:
toxor wrote:
I just annotated the service-class with @Repository and @Transaction.
I assume you mean @Transactional, right?
Oops I did it again, so sry, you are right its ofc @Transactional.
hardy.ferentschik wrote:
In which container are your running. Depending on the container you need to pick the right transaction manager.
This is my remaining db config :
Code:
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${db.driverClassName}"/>
<property name="jdbcUrl" value="${db.url}"/>
<property name="user" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</bean>
<bean id="myEmf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="generateDdl" value="true"/>
</bean>
</property>
<property name="persistenceUnitName" value="myTool"/>
</bean>
hardy.ferentschik wrote:
I mean what happens in your DAOs or with other words within your transactional methods. In this type of setup you don't have an explicit call to open and close of the entity manager, but that does not mean they don't exist. The framework (spring in this case is taking care of it).
Ah ok, yes that is what I thought. My DAOs just look like this :
Code:
public class OneDAOimpl implements IOneDAO {
@PersistenceContext
private EntityManager em;
public void save(One one) {
em.persist(one);
}
public One findById(long Id) {
return em.find(One.class, Id);
}
public void update(One one) {
em.merge(one);
}
public void remove(One one) {
em.remove(one);
}
public void updateIndex() {
...
}
public List<One> searchByKey(String key) {
FullTextEntityManager fullTextEntityManager = org.hibernate.search.jpa.Search.getFullTextEntityManager(em);
QueryBuilder qb = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity( One.class ).get();
org.apache.lucene.search.Query query = qb.keyword().onFields("two.three.name").matching(key).createQuery();
javax.persistence.Query persistenceQuery = fullTextEntityManager.createFullTextQuery(query, One.class);
@SuppressWarnings("unchecked")
List<One> result = persistenceQuery.getResultList();
return result;
}
}