2012-12-13 41 views
1

我試圖解決一個問題,但jdbc讓我遠離。Apache Derby [Hibernate框架] dosn't看到創建表。 [Java EE + JSP]

我已經創建表USERS,並希望插入一些數據與休眠,但我無法。 我不明白爲什麼,因爲我以前更簡單的例子有相同的數據庫配置,它的工作正常。 下面是從我的bean的代碼部分:

public void newUser() throws ParseException{ 
    SessionFactory sessionFactory = HibernateUtil.getSessionFactory(); 
    Session session = sessionFactory.openSession(); 
    Transaction tran = session.beginTransaction(); 

    java.sql.Date dt = new java.sql.Date(year-1900,month,day); 

    entity.Users user = new entity.Users(); 
    user.setBirthdate(dt); 
    user.setFirstname(inputName); 
    user.setLastname(inputSurname); 
    user.setEmail(inputEmail); 
    user.setPassword(inputPassword); 
    user.setGender(selectedGender); 

    Rights t = new Rights(3,"user"); 

    user.setPrivilageType(t); 

    session.save(user); 
    tran.commit(); 
} 

和堆棧跟蹤:

javax.faces.el.EvaluationException: org.hibernate.exception.SQLGrammarException: could not insert: [entity.Users] 
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102) 
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102) 
    at javax.faces.component.UICommand.broadcast(UICommand.java:315) 
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794) 
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259) 
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81) 
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) 
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) 
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) 
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550) 
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281) 
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175) 
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655) 
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595) 
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161) 
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331) 
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231) 
    at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317) 
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195) 
    at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860) 
    at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757) 
    at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056) 
    at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229) 
    at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137) 
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104) 
    at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90) 
    at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79) 
    at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54) 
    at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59) 
    at com.sun.grizzly.ContextTask.run(ContextTask.java:71) 
    at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532) 
    at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513) 
    at java.lang.Thread.run(Thread.java:722) 
Caused by: org.hibernate.exception.SQLGrammarException: could not insert: [entity.Users] 
    at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67) 
    at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43) 
    at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:40) 
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158) 
    at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638) 
    at org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48) 
    at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250) 
    at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298) 
    at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181) 
    at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107) 
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187) 
    at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33) 
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172) 
    at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27) 
    at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70) 
    at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:535) 
    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:523) 
    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:519) 
    at beans.RegistrationBean.newUser(RegistrationBean.java:155) 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:601) 
    at javax.el.BeanELResolver.invokeMethod(BeanELResolver.java:779) 
    at javax.el.BeanELResolver.invoke(BeanELResolver.java:528) 
    at javax.el.CompositeELResolver.invoke(CompositeELResolver.java:257) 
    at com.sun.el.parser.AstValue.invoke(AstValue.java:248) 
    at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:302) 
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105) 
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88) 
    ... 32 more 
Caused by: java.sql.SQLSyntaxErrorException: Table/View 'USERS' does not exist. 
    at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source) 
    at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source) 
    at org.apache.derby.client.am.Connection.prepareStatement(Unknown Source) 
    at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:505) 
    at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:94) 
    at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:30) 
    ... 59 more 
Caused by: org.apache.derby.client.am.SqlException: Table/View 'USERS' does not exist. 
    at org.apache.derby.client.am.Statement.completeSqlca(Unknown Source) 
    at org.apache.derby.client.net.NetStatementReply.parsePrepareError(Unknown Source) 
    at org.apache.derby.client.net.NetStatementReply.parsePRPSQLSTTreply(Unknown Source) 
    at org.apache.derby.client.net.NetStatementReply.readPrepareDescribeOutput(Unknown Source) 
    at org.apache.derby.client.net.StatementReply.readPrepareDescribeOutput(Unknown Source) 
    at org.apache.derby.client.net.NetStatement.readPrepareDescribeOutput_(Unknown Source) 
    at org.apache.derby.client.am.Statement.readPrepareDescribeOutput(Unknown Source) 
    at org.apache.derby.client.am.PreparedStatement.readPrepareDescribeInputOutput(Unknown Source) 
    at org.apache.derby.client.am.PreparedStatement.flowPrepareDescribeInputOutput(Unknown Source) 
    at org.apache.derby.client.am.PreparedStatement.prepare(Unknown Source) 
    at org.apache.derby.client.am.Connection.prepareStatementX(Unknown Source) 
    ... 63 more 

我很樂意幫忙。

+0

這個相關的問題有一些事情要嘗試:http://stackoverflow.com/questions/6579180/tables-not-getting-auto-created-in-apache-derby-when-using-ejb3-hibernate?rq= 1 –

+0

謝謝你的回答!不幸的是,當我嘗試從您提供的案例中使用解決方案時,沒有任何變化。此外,我已正確配置休眠文件。他們在我擁有的其他項目上工作。 – elharion

回答

0

好吧,我已經解決了這個問題。這很簡單。我只需將表名從小寫更名爲大寫。