Hello everybody.
I'm starting a new project using Spring 3.0 and Hibernate 3.3, on MyEclipse 10.
I built the skeleton web application and deployed on JBoss 6.1, and it works.
I bult a sample application using Hibernate on MySql, and it works.
I have problems when moving the Hibernate stuff in the web project.
I put this in applicationContext.xml
This is a snippet of te entity class, generated by the database reverse engineering tools of MyEclipse
From what I can see, all annotations are correct
The tools also created a DAO, referenced also in applicationContext, where is injected the SessionFactory
Again, I can't see anything wrong there
I use the DAO in my simple controller
The URL mapping works great, but when I go to localhost:8080/MyApp/issues I only get an error:
I tried all other methods of the DAO, still same error or similar. It looks like the entity class is not parsed at all for annotations. In facts I expected to see some lines in the server console during startup indicating that some annotated classes were found, but I see nothing of this.
Am I forgetting something? The DB connection is OK, the same DAO and entity class used in the standalone test java app with annotations referenced in hibernate.cfg.xml with
<mapping class="net.tarrasque.springtest.db.TestIssue" />
work.
I really have no other ideas...
I'm starting a new project using Spring 3.0 and Hibernate 3.3, on MyEclipse 10.
I built the skeleton web application and deployed on JBoss 6.1, and it works.
I bult a sample application using Hibernate on MySql, and it works.
I have problems when moving the Hibernate stuff in the web project.
I put this in applicationContext.xml
Code:
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource">
<ref bean="TestDS" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="packagesToScan">
<list>
<value>net.tarrasque.springtest2.db</value>
</list>
</property>
<property name="configurationClass">
<value>org.hibernate.cfg.AnnotationConfiguration</value>
</property>
</bean>
<bean id="TestIssueDAO"
class="net.tarrasque.springtest2.db.TestIssueDAO">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>
Code:
package net.tarrasque.springtest2.db;
import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;
/**
* TestIssue entity. @author MyEclipse Persistence Tools
*/
@Entity
@Table(name = "test_issue", catalog = "coa")
public class TestIssue implements java.io.Serializable {
// Fields
private TestIssueId id;
...
The tools also created a DAO, referenced also in applicationContext, where is injected the SessionFactory
Code:
package net.tarrasque.springtest2.db;
import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
/**
* A data access object (DAO) providing persistence and search support for
* TestIssue entities. Transaction control of the save(), update() and
* delete() operations can directly support Spring container-managed
* transactions or they can be augmented to handle user-managed Spring
* transactions. Each of these methods provides additional information for how
* to configure it for the desired type of transaction control.
*
* @see net.tarrasque.springtest2.db.TestIssue
* @author MyEclipse Persistence Tools
*/
public class TestIssueDAO extends HibernateDaoSupport {
private static final Logger log = LoggerFactory
.getLogger(TestIssueDAO.class);
...
public List findAll() {
log.debug("finding all TestIssue instances");
try {
String queryString = "from TestIssue";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find all failed", re);
throw re;
}
}
...
Again, I can't see anything wrong there
I use the DAO in my simple controller
Code:
/**
*
*/
package net.tarrasque.springtest2.web;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.tarrasque.springtest2.db.TestIssue;
import net.tarrasque.springtest2.db.TestIssueDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
@Controller
public class IssueController extends MultiActionController {
@Autowired
private TestIssueDAO testIssueDAO;
@RequestMapping({"/issues"})
public ModelAndView list(HttpServletRequest request, HttpServletResponse response) {
List<TestIssue> list = testIssueDAO.findAll();
ModelMap modelMap = new ModelMap();
modelMap.addAttribute("issues", list);
return new ModelAndView("IssueList");
}
}
Code:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.hibernate3.HibernateQueryException: TestIssue is not mapped [from TestIssue]; nested exception is org.hibernate.hql.ast.QuerySyntaxException: TestIssue is not mapped [from TestIssue]
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:549)
javax.servlet.http.HttpServlet.service(HttpServlet.java:734)
javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
Am I forgetting something? The DB connection is OK, the same DAO and entity class used in the standalone test java app with annotations referenced in hibernate.cfg.xml with
<mapping class="net.tarrasque.springtest.db.TestIssue" />
work.
I really have no other ideas...