Org.hiNNATE.HiBERNateException: Keine Sitzung für den aktuellen Thread 5 gefundenJava

Java-Forum
Anonymous
 Org.hiNNATE.HiBERNateException: Keine Sitzung für den aktuellen Thread 5 gefunden

Post by Anonymous »

Ich weiß, dass dieses Problem viel gefragt wird, aber ich stecke fest. I am basing my project off of this tutorial: http://www.cavalr.com/blog/Spring_3_and ... _4_Example

This is my root-context.xml

Code: Select all
















classpath:db.properties









org.hibernate.dialect.MySQL5InnoDBDialect
true












< /code>

Dies ist mein Servlet-context.xml < /p>



















< /code>

Dies ist mein AbstractDaOImpl < /p>

public abstract class AbstractDaoImpl implements AbstractDao {

private Class entityClass;

protected AbstractDaoImpl(Class  entityClass) {
this.entityClass = entityClass;
}

@Autowired
private SessionFactory sessionFactory;

public Session getCurrentSession() {
return sessionFactory.getCurrentSession();
}

@SuppressWarnings("unchecked")
@Override
public E findById(I id) {
return (E) getCurrentSession().get(entityClass, id);
}

@Override
public void saveOrUpdate(E e) {
getCurrentSession().saveOrUpdate(e);
}

@Override
public void delete(E e) {
getCurrentSession().delete(e);
}

@Override
public List findByCriteria(Criterion criterion) {
Criteria criteria = getCurrentSession().createCriteria(entityClass);
criteria.add(criterion);
return criteria.list();
}
}
< /code>

Dies ist mein requiredaoImpl < /code> Klasse < /p>

@Repository
public class RecipeDaoImpl extends AbstractDaoImpl implements RecipeDao {

protected RecipeDaoImpl() {
super(Recipe.class);
}

@Override
public boolean saveRecipe(Recipe r) {
return saveRecipe(r);
}

@Override
public Recipe getRecipe(String recipeId) {
return findById(recipeId);
}

@SuppressWarnings("unchecked")
@Override
public List findRecipes(String keyword) {
return findByCriteria( Restrictions.and( Restrictions.like("name", keyword, MatchMode.ANYWHERE),
Restrictions.like("keywords", keyword, MatchMode.ANYWHERE) ) );
}
}
< /code>

Dies ist mein RezepteserviceImpl < /code> Klasse < /p>

@Service("recipeService")
@Transactional(readOnly = true)
public class RecipeServiceImpl implements RecipeService {
@Autowired
private RecipeDao recipeDao;

@Override
@Transactional(readOnly = false)
public boolean saveRecipe(Recipe r) {
return recipeDao.saveRecipe(r);
}

@Override
public Recipe getRecipe(String recipeId) {
return recipeDao.getRecipe(recipeId);
}

@Override
public List findRecipes(String keyword) {
return recipeDao.findRecipes(keyword);
}
}
< /code>

Dies ist mein Recreecontroller < /code> < /p>

/**
* Handles requests for the application home page.
*/
@Controller
public class RecipeController {

private static final Logger logger = LoggerFactory.getLogger(RecipeController.class);

@Autowired
private RecipeService recipeService;

/**
* Adds recipes to the DB
*/
@RequestMapping(value = "/add", method = RequestMethod.GET)
public String add(Locale locale, Model model) {
return "add";
}

/**
* Searches for recipes
*/
@RequestMapping(value = "/search", method = RequestMethod.POST)
public String search(@RequestParam(value="keyword", required=true) String keyword, Model model) {

List recipes = recipeService.findRecipes(keyword);
System.out.println( "Results:"+ recipes.size() );
return "results";
}

/**
* Logs in the user
*/
@RequestMapping(value = "/login", method = RequestMethod.POST)
public String login(Locale locale, Model model) {

return "login";
}
}
< /code>

Ich habe versucht, die @Transactional < /code> in die requireDaOImpl < /code> -Klasse und die AbstractDaOImpl < /code> klassifiziert und nicht funktioniert zu haben.public Session getCurrentSession() {
Session session = null;
try {
session = sessionFactory.getCurrentSession();
} catch ( HibernateException he ) {
session = sessionFactory.openSession();
}
return session;
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post