Caros,
Estou com um problema para poder inserir em uma tabela que recebe Foreing Keys de outras tabelas, utilizando Hibernate.
Quando tento fazer a inserção, ocorre o erro:
09/05/2011 15:51:07 org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files (x86)\Java\jre6\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/Program Files (x86)/Java/jre6/bin/client;C:/Program Files (x86)/Java/jre6/bin;C:\oraclexe\app\oracle\product\10.2.0\server\bin;C:\Program Files\Common Files\Microsoft Shared\Windows Live;C:\Program Files (x86)\Common Files\Microsoft Shared\Windows Live;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\OEM\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\OEM\12.0\DLLShared\;C:\Program Files (x86)\Roxio\OEM\AudioCore\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;C:\Program Files\TortoiseSVN\bin
09/05/2011 15:51:07 org.apache.tomcat.util.digester.SetPropertiesRule begin
AVISO: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:aula1_projeto2_exerc' did not find a matching property.
09/05/2011 15:51:07 org.apache.tomcat.util.digester.SetPropertiesRule begin
AVISO: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:PROJETORH' did not find a matching property.
09/05/2011 15:51:08 org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8083
09/05/2011 15:51:08 org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 348 ms
09/05/2011 15:51:08 org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
09/05/2011 15:51:08 org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.29
log4j:WARN No appenders could be found for logger (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider).
log4j:WARN Please initialize the log4j system properly.
09/05/2011 15:51:08 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
INFO: Parsing configuration file [struts-default.xml]
09/05/2011 15:51:08 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
INFO: Parsing configuration file [struts-plugin.xml]
09/05/2011 15:51:08 com.opensymphony.xwork2.config.providers.XmlConfigurationProvider register
INFO: Parsing configuration file [struts.xml]
09/05/2011 15:51:08 org.apache.struts2.config.Settings getLocale
AVISO: Settings: Could not parse struts.locale setting, substituting default VM locale
09/05/2011 15:51:08 com.opensymphony.xwork2.util.ObjectTypeDeterminerFactory <clinit>
INFO: Detected GenericsObjectTypeDeterminer, initializing it...
09/05/2011 15:51:08 com.opensymphony.xwork2.util.XWorkConverter getInstance
INFO: Detected AnnotationXWorkConverter, initializing it...
09/05/2011 15:51:09 org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8083
09/05/2011 15:51:09 org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
09/05/2011 15:51:09 org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/13 config=null
09/05/2011 15:51:09 org.apache.catalina.startup.Catalina start
INFO: Server startup in 1018 ms
Hibernate: select funcionari0_.id_funcionario as id1_0_, funcionari0_.de_nome as de2_0_, funcionari0_.de_sexo as de3_0_, funcionari0_.dt_nasc as dt4_0_, funcionari0_.de_cpf as de5_0_, funcionari0_.de_rg as de6_0_, funcionari0_.de_fone_celular as de7_0_, funcionari0_.de_fone_residencial as de8_0_, funcionari0_.de_end as de9_0_, funcionari0_.de_cidade as de10_0_, funcionari0_.ch_uf as ch11_0_, funcionari0_.fl_transporte as fl12_0_, funcionari0_.de_login as de13_0_, funcionari0_.de_senha as de14_0_, funcionari0_.txt_obs as txt15_0_ from funcionario funcionari0_ where de_login='osvaldo' and de_senha='123'
Hibernate: select departamen0_.id_departamento as id1_9_, departamen0_.de_departamento as de2_9_ from departamento departamen0_ order by id_departamento
Hibernate: select funcionari0_.id_funcionario as id1_16_, funcionari0_.de_nome as de2_16_, funcionari0_.de_sexo as de3_16_, funcionari0_.dt_nasc as dt4_16_, funcionari0_.de_cpf as de5_16_, funcionari0_.de_rg as de6_16_, funcionari0_.de_fone_celular as de7_16_, funcionari0_.de_fone_residencial as de8_16_, funcionari0_.de_end as de9_16_, funcionari0_.de_cidade as de10_16_, funcionari0_.ch_uf as ch11_16_, funcionari0_.fl_transporte as fl12_16_, funcionari0_.de_login as de13_16_, funcionari0_.de_senha as de14_16_, funcionari0_.txt_obs as txt15_16_ from funcionario funcionari0_ order by id_funcionario
Hibernate: select cargo0_.id_cargo as id1_26_, cargo0_.de_cargo as de2_26_, cargo0_.fl_salario as fl3_26_, cargo0_.fl_refeicao as fl4_26_ from cargo cargo0_ order by id_cargo
Hibernate: select hibernate_sequence.nextval from dual
Hibernate: insert into contrato (_id_departamento_id_departamento, _id_funcionario_id_funcionario, _id_cargo_id_cargo, dt_admissao, dt_demissao, id_contrato) values (?, ?, ?, ?, ?, ?)
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:254)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:266)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:167)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1001)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:339)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at app.dao.ContratoDAO.inserirContrato(ContratoDAO.java:28)
at app.services.GerenciaContrato.inserirContrato(GerenciaContrato.java:11)
at app.action.ContratoAction.cadastroContrato(ContratoAction.java:27)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:399)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:262)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:213)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.intercept(ParametersInterceptor.java:161)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.intercept(PrepareInterceptor.java:115)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:507)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:421)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Caused by: java.sql.BatchUpdateException: ORA-00911: caractere inválido
at oracle.jdbc.driver.DatabaseError.throwBatchUpdateException(DatabaseError.java:343)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:10657)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:48)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:247)
... 120 more
Hibernate: select contrato0_.id_contrato as id1_43_, contrato0_._id_departamento_id_departamento as column5_43_, contrato0_._id_funcionario_id_funcionario as column4_43_, contrato0_._id_cargo_id_cargo as column6_43_, contrato0_.dt_admissao as dt2_43_, contrato0_.dt_demissao as dt3_43_ from contrato contrato0_ order by id_contrato
09/05/2011 15:51:38 org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet default threw exception
java.sql.SQLException: ORA-00911: caractere inválido
at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:112)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:331)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:288)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:743)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:216)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:799)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1038)
at oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:839)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1133)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3285)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3329)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:187)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1791)
at org.hibernate.loader.Loader.doQuery(Loader.java:674)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
at org.hibernate.loader.Loader.doList(Loader.java:2217)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2108)
at org.hibernate.loader.Loader.list(Loader.java:2103)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:378)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:340)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1122)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at app.dao.ContratoDAO.listarContrato(ContratoDAO.java:62)
at app.services.GerenciaContrato.consultarContrato(GerenciaContrato.java:23)
at app.action.ContratoAction.cadastroContrato(ContratoAction.java:28)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:399)
at com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:262)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:224)
at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:213)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:150)
at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:48)
at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.ParametersInterceptor.intercept(ParametersInterceptor.java:161)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:105)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:83)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:207)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:74)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:127)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at org.apache.struts2.interceptor.ProfilingActivationInterceptor.intercept(ProfilingActivationInterceptor.java:107)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:206)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:115)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:143)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.PrepareInterceptor.intercept(PrepareInterceptor.java:115)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:170)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:123)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:219)
at com.opensymphony.xwork2.DefaultActionInvocation$2.doProfiling(DefaultActionInvocation.java:218)
at com.opensymphony.xwork2.util.profiling.UtilTimerStack.profile(UtilTimerStack.java:455)
at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:216)
at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:50)
at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:507)
at org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:421)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
Seguem abaixo o script das tabelas relacionadas e as classes relacionadas nesse processo de insersão.
SCRIPT BANCO:
//TABELA: CARGO
CREATE TABLE "CARGO"
( "ID_CARGO" NUMBER NOT NULL ENABLE,
"DE_CARGO" VARCHAR2(50) NOT NULL ENABLE,
"FL_SALARIO" NUMBER(10,2) NOT NULL ENABLE,
"FL_REFEICAO" NUMBER(10,2) NOT NULL ENABLE,
CONSTRAINT "CARGO_PK" PRIMARY KEY ("ID_CARGO") ENABLE
)
/
CREATE SEQUENCE "CARGO_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLE
/
CREATE OR REPLACE TRIGGER "BI_CARGO"
before insert on "CARGO"
for each row
begin
select "CARGO_SEQ".nextval into :NEW.ID_CARGO from dual;
end;
/
ALTER TRIGGER "BI_CARGO" ENABLE
/
//============================
//TABELA: FUNCIONARIO
CREATE TABLE "FUNCIONARIO"
( "ID_FUNCIONARIO" NUMBER NOT NULL ENABLE,
"DE_NOME" VARCHAR2(50),
"DE_SEXO" NVARCHAR2(1) NOT NULL ENABLE,
"DT_NASC" DATE,
"DE_CPF" VARCHAR2(11),
"DE_RG" VARCHAR2(25),
"DE_FONE_CELULAR" VARCHAR2(25),
"DE_FONE_RESIDENCIAL" VARCHAR2(25),
"DE_END" VARCHAR2(100),
"DE_CIDADE" VARCHAR2(50),
"CH_UF" NVARCHAR2(2),
"FL_TRANSPORTE" NUMBER(10,2),
"DE_LOGIN" VARCHAR2(25),
"DE_SENHA" VARCHAR2(25),
"TXT_OBS" CLOB,
CONSTRAINT "FUNCIONARIO_PK" PRIMARY KEY ("ID_FUNCIONARIO") ENABLE
)
/
CREATE SEQUENCE "FUNCIONARIO_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLE
/
CREATE OR REPLACE TRIGGER "BI_FUNCIONARIO"
before insert on "FUNCIONARIO"
for each row
begin
select "FUNCIONARIO_SEQ".nextval into :NEW.ID_FUNCIONARIO from dual;
end;
/
ALTER TRIGGER "BI_FUNCIONARIO" ENABLE
/
//============================
//TABELA: DEPARTAMENTO
CREATE TABLE "DEPARTAMENTO"
( "ID_DEPARTAMENTO" NUMBER NOT NULL ENABLE,
"DE_DEPARTAMENTO" VARCHAR2(50) NOT NULL ENABLE,
CONSTRAINT "DEPARTAMENTO_PK" PRIMARY KEY ("ID_DEPARTAMENTO") ENABLE
)
/
CREATE SEQUENCE "DEPARTAMENTO_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLE
/
CREATE OR REPLACE TRIGGER "BI_DEPARTAMENTO"
before insert on "DEPARTAMENTO"
for each row
begin
select "DEPARTAMENTO_SEQ".nextval into :NEW.ID_DEPARTAMENTO from dual;
end;
/
ALTER TRIGGER "BI_DEPARTAMENTO" ENABLE
/
//============================
//TABELA PRINCIPAL: CONTRATO
CREATE TABLE "CONTRATO"
( "ID_CONTRATO" NUMBER NOT NULL ENABLE,
"ID_DEPARTAMENTO" NUMBER NOT NULL ENABLE,
"ID_FUNCIONARIO" NUMBER NOT NULL ENABLE,
"ID_CARGO" NUMBER NOT NULL ENABLE,
"DT_ADMISSAO" DATE NOT NULL ENABLE,
"DT_DEMISSAO" DATE,
CONSTRAINT "CONTRATO_PK" PRIMARY KEY ("ID_CONTRATO") ENABLE,
CONSTRAINT "CONTRATO_FK" FOREIGN KEY ("ID_DEPARTAMENTO")
REFERENCES "DEPARTAMENTO" ("ID_DEPARTAMENTO") ENABLE,
CONSTRAINT "CONTRATO_FK2" FOREIGN KEY ("ID_FUNCIONARIO")
REFERENCES "FUNCIONARIO" ("ID_FUNCIONARIO") ENABLE,
CONSTRAINT "CONTRATO_FK3" FOREIGN KEY ("ID_CARGO")
REFERENCES "CARGO" ("ID_CARGO") ENABLE
)
/
CREATE SEQUENCE "CONTRATO_SEQ" MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLE
/
CREATE OR REPLACE TRIGGER "BI_CONTRATO"
before insert on "CONTRATO"
for each row
begin
select "CONTRATO_SEQ".nextval into :NEW.ID_CONTRATO from dual;
end;
/
ALTER TRIGGER "BI_CONTRATO" ENABLE
/
CLASSES
BEAN: Contrato
package app.bean;
import java.sql.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name = "contrato")
public class Contrato {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id_contrato")
private int _id_contrato;
@ManyToOne(cascade = CascadeType.PERSIST)
private Departamento _id_departamento;
@ManyToOne(cascade = CascadeType.PERSIST)
private Funcionario _id_funcionario;
@ManyToOne(cascade = CascadeType.PERSIST)
private Cargo _id_cargo;
@Column(name = "dt_admissao")
private Date _dt_admissao;
@Column(name = "dt_demissao")
private Date _dt_demissao;
public void set_id_contrato(int idContrato) {
_id_contrato = idContrato;
}
public int get_id_contrato() {
return _id_contrato;
}
public void set_dt_admissao(Date dtAdmissao) {
_dt_admissao = dtAdmissao;
}
public Date get_dt_admissao() {
// String _dt_admissao = this._dt_admissao.toString().substring(8, 10)+"/"+this._dt_admissao.toString().substring(5, 7)+"/"+this._dt_admissao.toString().substring(0, 4);
return _dt_admissao;
}
public void set_dt_demissao(Date dtDemissao) {
_dt_demissao = dtDemissao;
}
public Date get_dt_demissao() {
// String _dt_demissao = this._dt_demissao.toString().substring(8, 10)+"/"+this._dt_demissao.toString().substring(5, 7)+"/"+this._dt_demissao.toString().substring(0, 4);
return _dt_demissao;
}
public void set_id_departamento(Departamento idDepartamento) {
_id_departamento = idDepartamento;
}
public Departamento get_id_departamento() {
return _id_departamento;
}
public void set_id_funcionario(Funcionario idFuncionario) {
_id_funcionario = idFuncionario;
}
public Funcionario get_id_funcionario() {
return _id_funcionario;
}
public void set_id_cargo(Cargo idCargo) {
_id_cargo = idCargo;
}
public Cargo get_id_cargo() {
return _id_cargo;
}
}
ACTION: ContratoAction
package app.action;
import java.util.List;
import app.bean.Cargo;
import app.bean.Contrato;
import app.bean.Departamento;
import app.bean.Funcionario;
import app.services.GerenciaContrato;
public class ContratoAction {
private Departamento departamento;
private Funcionario funcionario;
private Cargo cargo;
private Contrato contrato;
private List<Contrato> contratos;
//CADASTRAR
public String cadastroContrato(){
contrato.set_id_departamento(departamento);
contrato.set_id_funcionario(funcionario);
contrato.set_id_cargo(cargo);
boolean ok = new GerenciaContrato().inserirContrato(contrato);
contratos = new GerenciaContrato().consultarContrato();
if (ok)
return "sucesso";
else
return "erro";
}
//EXCLUIR
public String excluirContrato(){
boolean ok = new GerenciaContrato().excluirContrato(contrato);
contratos = new GerenciaContrato().consultarContrato();
if (ok)
return "sucesso";
else
return "erro";
}
//ALTERAR
public String alterarContrato(){
contrato.set_id_departamento(departamento);
contrato.set_id_funcionario(funcionario);
contrato.set_id_cargo(cargo);
boolean ok = new GerenciaContrato().alterarContrato(contrato);
contratos = new GerenciaContrato().consultarContrato();
if (ok)
return "sucesso";
else
return "erro";
}
//LISTAR
public String consultarContrato(){
contratos = new GerenciaContrato().consultarContrato();
if (contratos != null)
return "sucesso";
else
return "erro";
}
//CONSULTAR POR ID
public String consultaContratoPorId(){
contrato = new GerenciaContrato().consultaContratoPorId(contrato);
if (contrato != null)
return "consultado";
else
return "erro";
}
public void setContratos(List<Contrato> contratos) {
this.contratos = contratos;
}
public List<Contrato> getContratos() {
return contratos;
}
public void setFuncionario(Funcionario funcionario) {
this.funcionario = funcionario;
}
public Funcionario getFuncionario() {
return funcionario;
}
public Departamento getDepartamento() {
return departamento;
}
public void setDepartamento(Departamento departamento) {
this.departamento = departamento;
}
public Cargo getCargo() {
return cargo;
}
public void setCargo(Cargo cargo) {
this.cargo = cargo;
}
public Contrato getContrato() {
return contrato;
}
public void setContrato(Contrato contrato) {
this.contrato = contrato;
}
}
ACTION: UtilAction
//ESSA CLASSE ALIMENTA AS COMBOBOX (<s:Select>) DO FORMULÁRIO cadastrocontrato.jsp
package app.action;
import java.util.List;
import app.bean.Cargo;
import app.bean.Departamento;
import app.bean.Funcionario;
import app.services.GerenciaCargo;
import app.services.GerenciaDepartamento;
import app.services.GerenciaFuncionario;
public class UtilAction {
private List<Departamento> departamentos;
private List<Funcionario> funcionarios;
private List<Cargo> cargos;
public String carregaCadastro(){
departamentos = new GerenciaDepartamento().consultarDepartamento();
funcionarios = new GerenciaFuncionario().consultarFuncionario();
cargos = new GerenciaCargo().consultarCargo();
return "cadastroContrato";
}
public List<Departamento> getDepartamentos() {
return departamentos;
}
public void setDepartamentos(List<Departamento> departamentos) {
this.departamentos = departamentos;
}
public List<Funcionario> getFuncionarios() {
return funcionarios;
}
public void setFuncionarios(List<Funcionario> funcionarios) {
this.funcionarios = funcionarios;
}
public List<Cargo> getCargos() {
return cargos;
}
public void setCargos(List<Cargo> cargos) {
this.cargos = cargos;
}
}
SERVICES: GerenciaContrato
package app.services;
import java.util.List;
import app.bean.Contrato;
import app.dao.ContratoDAO;
public class GerenciaContrato {
public boolean inserirContrato (Contrato contrato){
return new ContratoDAO().inserirContrato(contrato);
}
public boolean excluirContrato (Contrato contrato){
return new ContratoDAO().excluirContrato(contrato);
}
public boolean alterarContrato(Contrato contrato){
return new ContratoDAO().inserirContrato(contrato);
}
public List<Contrato> consultarContrato (){
return new ContratoDAO().listarContrato();
}
public Contrato consultaContratoPorId (Contrato contrato){
return new ContratoDAO().contratoPorId(contrato);
}
}
DAO: ContratoDAO
package app.dao;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;
import app.bean.Contrato;
import app.util.HibernateUtil;
public class ContratoDAO {
private Session s;
private Transaction t;
public ContratoDAO() {
s = HibernateUtil.getSession();
t = s.beginTransaction();
}
// INSERIR ou ALTERAR
public boolean inserirContrato(Contrato contrato) {
boolean ok = true;
try {
s.saveOrUpdate(contrato);
t.commit();
ok = true;
} catch (HibernateException e) {
e.printStackTrace();
t.rollback();
ok = false;
} finally {
s.close();
}
return ok;
}
//EXCLUIR
public boolean excluirContrato (Contrato contrato){
boolean ok;
try{
s.delete(contrato);
t.commit();
ok = true;
}catch (HibernateException e){
t.rollback();
ok = false;
}finally{
s.close();
}
return ok;
}
//LISTAR TODOS
@SuppressWarnings("unchecked")
public List<Contrato> listarContrato(){
//monta o comando
Query q = s.createQuery("from Contrato order by id_contrato");
//executa a consulta
List<Contrato> contratos = q.list();
s.close(); //fecha a conexao
return contratos; //retorna a lista
}
//LISTAR POR ID
public Contrato contratoPorId(Contrato contrato){
//monta o comando
Query q = s.createQuery("from Contrato where id_contrato = " + contrato.get_id_contrato());
Contrato contratoBuscado = (Contrato) q.uniqueResult();
s.close(); //fecha a conexao
return contratoBuscado; //retorna a lista
}
}
UTIL: HibernateUtil
package app.util;
import java.io.Serializable;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
public class HibernateUtil implements Serializable {
/**
*
*/
private static final long serialVersionUID = -6000489077286000220L;
public static Session getSession() {
SessionFactory f = new AnnotationConfiguration().configure()
.buildSessionFactory();
return f.openSession();
}
}
CONFIG XML: hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- CONECTA COM O BANCO DE DADOS -->
<property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="hibernate.connection.password">projetorh</property>
<property name="hibernate.connection.url">jdbc:oracle:thin:@localhost:1521:XE</property>
<property name="hibernate.connection.username">projetorh</property>
<!-- SQL DIALETO -->
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<!-- MOSTRA O COMANDO SQL NO CONSOLE -->
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<!-- <property name="hbm2ddl.auto">create</property> -->
<mapping class="app.bean.Funcionario"/>
<mapping class="app.bean.Departamento"/>
<mapping class="app.bean.Cargo"/>
<mapping class="app.bean.Contrato"/>
</session-factory>
</hibernate-configuration>
STRUTS: struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml" />
<package name="default" extends="struts-default">
<action name="login!*" method="login" class="app.action.LoginAction">
<result name="sucesso">/index.jsp</result>
<result name="erro">/errologin.jsp</result>
</action>
<action name="cadastroDepartamento!*" method="cadastro" class="app.action.DepartamentoAction">
<result name="sucesso">/listadepartamento.jsp</result>
<result name="erro">/errodepartamento.jsp</result>
<result name="consultado">/alterardepartamento.jsp</result>
</action>
<action name="cadastroCargo!*" method="cadastro" class="app.action.CargoAction">
<result name="sucesso">/listacargo.jsp</result>
<result name="erro">/errocargo.jsp</result>
<result name="consultado">/alterarcargo.jsp</result>
</action>
<action name="cadastroFuncionario!*" method="cadastro" class="app.action.FuncionarioAction">
<result name="sucesso">/listafuncionario.jsp</result>
<result name="erro">/errofuncionario.jsp</result>
<result name="consultado">/alterarfuncionario.jsp</result>
</action>
<action name="util!*" class="app.action.UtilAction">
<result name="cadastroContrato">/cadastrocontrato.jsp</result>
</action>
<action name="cadastroContrato!*" method="cadastro" class="app.action.ContratoAction">
<result name="sucesso">/listacontrato.jsp</result>
<result name="erro">/errocontrato.jsp</result>
<result name="consultado">/alterarcontrato.jsp</result>
</action>
</package>
</struts>
FORM: cadastrocontrato.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Cadastro Contrato</title>
</head>
<body>
<s:form action="cadastroContrato!cadastroContrato">
<s:select label="Departamento"
name="departamento._id_departamento"
list="departamentos"
headerValue="--SELECIONE--"
headerKey="0"
listKey="_id_departamento"
listValue="_de_departamento"/>
<s:select label="Funcionario"
name="funcionario._id_funcionario"
list="funcionarios"
headerValue="--SELECIONE--"
headerKey="0"
listKey="_id_funcionario"
listValue="_de_nome"/>
<s:select label="Cargo"
name="cargo._id_cargo"
list="cargos"
headerValue="--SELECIONE--"
headerKey="0"
listKey="_id_cargo"
listValue="_de_cargo"/>
<s:textfield name="contrato._dt_admissao" label="Data de Admissão"/>
<s:textfield name="contrato._dt_demissao" label="Data de Demissão"/>
<s:submit value="Gravar"/>
</s:form>
</body>
</html>
O sistema acima não consegue nem inserir no banco, apesar de conseguir gerar o ID_CONTRATO. Agradeço a quem puder me ajudar.