我试图在jsp文件中从数据库中读取一些表。它给了我2个错误,到目前为止我找不到任何解决方案...
以下是JSP文件的相关部分:
<div class="col-lg-12">
<hr>
<h2 class="intro-text text-center">
Capitolul <strong><%= request.getParameter("capitol") %></strong>
</h2>
<hr>
<hr class="visible-xs">
<p id="titles"></p>
<%
QuestionDAO quest = new QuestionDAO();
questions = quest.getQuestions();
out.println(questions.size());
for(Question q:questions){
out.println(questions.size());
out.println(q.getQuestion());
}
out.println("Asdfasdf");
%>
</div>
这是QuestionDAO课程:
public class QuestionDAO {
private static final Log LOGGER = LogFactory.getLog(QuestionDAO.class);
private static SessionFactory factory;
@SuppressWarnings("unchecked")
public List<Question> getQuestions(){
List<Question> q = new ArrayList<Question>();
Transaction tx=null;
try{
Configuration configuration = new Configuration().configure("hibernate.cfg.xml");
SessionFactory sessionFactory = configuration.buildSessionFactory();
Session session = sessionFactory.openSession();
tx = session.beginTransaction();
Query query = session.createQuery("FROM Question");
q = query.list();
System.out.println(q.size()+"!!!");
for(int i=0; i<q.size(); i++) {
q.add(q.get(i));
}
tx.commit();
}catch (HibernateException e) {
if (tx != null) {
tx.rollback();
}
LOGGER.error("", e);
}
return q;
}
public Question addQuestion(Question question) {
int questionId = -1;
Session session = factory.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
questionId = (Integer) session.save(question);
question.setId(questionId);
tx.commit();
} catch (HibernateException e) {
if (tx != null) {
tx.rollback();
}
LOGGER.error("", e);
} finally {
session.close();
}
return question;
}
@SuppressWarnings("unchecked")
public Question findQuestion(int id) {
Session session = factory.openSession();
Transaction tx = null;
List<Question> questions = null;
try {
tx = session.beginTransaction();
Query query = session.createQuery("FROM Question WHERE id = :id");
query.setParameter("id", id);
questions = query.list();
tx.commit();
} catch (HibernateException e) {
if (tx != null) {
tx.rollback();
}
LOGGER.error("", e);
} finally {
session.close();
}
return questions != null && !questions.isEmpty() ? questions.get(0) : null;
}
public Question deleteQuestion(int id) {
Session session = factory.openSession();
Transaction tx = null;
Question question = (Question)session.load(Question.class, id);
try {
tx = session.beginTransaction();
session.delete(question);
tx.commit();
} catch (HibernateException e) {
if (tx != null) {
tx.rollback();
}
LOGGER.error("", e);
} finally {
session.close();
}
return question;
}
}
休眠cfg文件:
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/licenta</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="hibernate.dialect">org.hibernate.dialectMySQL5Dialect</property>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="hbm2ddl.auto">validate</property>
<mapping resource="user.hbm.xml"/>
<mapping resource="chapter.hbm.xml"/>
<mapping resource="comments.hbm.xml"/>
<mapping resource="problems.hbm.xml"/>
<mapping resource="questions.hbm.xml"/>
</session-factory>
</hibernate-configuration>
问题hbm(如果需要的话):
<hibernate-mapping>
<class name="models.Question" table="questions">
<meta attribute="class-description">
This class contains the questions detail.
</meta>
<id name="id" type="int" column="id">
<generator class="native" />
</id>
<property name="question" column="question" type="string" />
<property name="dateAsked" column="date_asked" type="date" />
<many-to-one name="User" class="models.User"
column="user_id" not-null="true"
cascade="all" />
</class>
</hibernate-mapping>
错误跟踪就是这个:
aa DEBUG org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator: JDBC version : 4.0
aa WARN org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator: HHH000342: Could not obtain connection to query metadata : Unable to resolve name [org.hibernate.dialectMySQLDialect] as strategy [org.hibernate.dialect.Dialect]
aa ERROR dao.QuestionDAO:
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:271)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:233)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:242)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:210)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:352)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:111)
at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:83)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:418)
at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:87)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:691)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:726)
at dao.QuestionDAO.getQuestions(QuestionDAO.java:39)
at org.apache.jsp.forum_002dcapitol_jsp._jspService(forum_002dcapitol_jsp.java:188)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:439)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:395)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:339)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:218)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:110)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:169)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [org.hibernate.dialectMySQLDialect] as strategy [org.hibernate.dialect.Dialect]
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:126)
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:194)
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:152)
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveDefaultableStrategy(StrategySelectorImpl.java:139)
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:133)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.constructDialect(DialectFactoryImpl.java:74)
at org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:51)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137)
at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:259)
... 41 more
aa DEBUG org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl: Connection pool now considered primed; min-size will be maintained
我提到我不使用Maven。你能在这里看到问题吗? 非常感谢你!
答案 0 :(得分:0)
我认为你错过了一个点(。)
你可以试试吗
org.hibernate.dialect.MySQLDialect
或者
org.hibernate.dialect.MySQL5Dialect
答案 1 :(得分:0)
将其更改为
org.hibernate.dialect.MySQL5Dialect