• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Learning to code my first web app using servlets hibernate

 
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm fairly new to Java programming and I'm trying to learn Servlets and Hibernet framework currently. For this I've been trying to code a web application that would do the following tasks ( Note : I'm using Netbeans IDE 7.1.2 & the default derby db that comes with it).

1. This app when executed will create the First html page which will have two sections - 1. Login section for existing users. 2. Registration link for new users. (HTML code = First.html)
2. If a user clicks on to the registration link, he will get another HTML page where he can enter his first name, last name, address, sex ( a radio button), a user name and a password. On clicking the register button, RegisterUser.java application will be invoked. (HTML code = Register.html)
3. RegisterUser.java is a servlet that will create the request object using the post method that register.html would invoke and store the values entered by the user in the users table in the derby db. I've used a bean class userbean for the data objects and made it available to RegisterUser.java using an import statement. The issues that I ran into are as follows.

a. The code would accept the values and print welcome user but the database doesn't get updated. I have no idea what is wrong and where. If I create a simple java hibernet application, I am able to update my database but not in the current case. I don't even know if this applicationis even creating a session object. Please help. I know userName shouldn't be a long value but when I create this as a string and gave this field as the primary key it wasn't working. I think I'll work on fixing and understanding that part later.


My code is as follows. Could somebody please help me understand what's wrong with it.

First.html ( Hierarchy - WebApplication2-Webpages -First.html ) is as follows.



Register.html ( Hierarchy - WebApplication2-Webpages -Register.html ) is as follows.



Web.xml (Hieracrchy = WebApplication2 -WEB-INF) is as follows.


4. UserBean Class ( Hierarchy = WebApplication2 - Source Packages -com -UserBean.java)

5. Hibernet mapping File UserBean.hbm.xml (WebApplication2 - Source Packages -com )<?xml version="1.0" encoding="UTF-8"?>

6. Hibernet Config File hibernate.cfg.xml (Hierarchy WebApplication2 - Source Packages -<Default Package>)

7. Servlet RegisterUser.java ( WebApplication2 - Source Packages- hibernetapplication2- RegisterUser.java)






 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, it's not a good practice that you place your database access codes right in a servlet. You should have a separate reusable set of classes that do the database stuffs.

Chan Go wrote:



So you are sinking the possible exceptions to the stream of System.out. Unless the thrown exception has its own toString() implementation to show up something more, you are hiding the stack trace too. A little good approach would be e.printStackTrace(), however.
Did you check the logs to see if some exception has been caused.

 
Author
Posts: 3473
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you are learning, you can get it to work "quick and dirty" way so that you understand how different artifacts wire up together.

Then go and refactor your code as suggested by Devaka to include proper patterns and practices.
 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your responses. I replaced the System.out.println(e) with e.printStackTrace() method. Given below is the log. I got so many run time errors
It's actually depressing. Kindly help..

Sorry it's still the dirty code :-) I'm still learning/to learn the graceful ways of coding java apps.

Using CATALINA_BASE: "C:\Users\UserXYZ\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base"
Using CATALINA_HOME: "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.22"
Using CATALINA_TMPDIR: "C:\Users\UserXYZ\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\temp"
Using JRE_HOME: "C:\Program Files\Java\jdk1.7.0_04"
Using CLASSPATH: "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.22\bin\bootstrap.jar;C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.22\bin\tomcat-juli.jar"
Sep 14, 2012 7:54:56 PM 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\Java\jdk1.7.0_04\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;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\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Lenovo\Bluetooth Software\;C:\Program Files\Lenovo\Bluetooth Software\syswow64;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Java\jdk1.7.0_04\bin;.
Sep 14, 2012 7:54:56 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8084"]
Sep 14, 2012 7:54:56 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Sep 14, 2012 7:54:56 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 596 ms
Sep 14, 2012 7:54:56 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Sep 14, 2012 7:54:56 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.22
Sep 14, 2012 7:54:56 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor manager.xml from C:\Users\UserXYZ\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\conf\Catalina\localhost
Sep 14, 2012 7:54:56 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor ROOT.xml from C:\Users\UserXYZ\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\conf\Catalina\localhost
Sep 14, 2012 7:54:56 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor WebApplication1.xml from C:\Users\UserXYZ\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\conf\Catalina\localhost
Sep 14, 2012 7:54:57 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor WebApplication2.xml from C:\Users\UserXYZ\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\conf\Catalina\localhost
Sep 14, 2012 7:54:57 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8084"]
Sep 14, 2012 7:54:57 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Sep 14, 2012 7:54:57 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1253 ms
Sep 14, 2012 8:05:54 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/WebApplication2] has started
Sep 14, 2012 8:05:55 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/WebApplication2] is completed
Sep 14, 2012 8:06:07 PM org.apache.catalina.startup.HostConfig checkResources
INFO: Undeploying context [/WebApplication2]
Sep 14, 2012 8:06:14 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor WebApplication2.xml from C:\Users\UserXYZ\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\conf\Catalina\localhost
Sep 14, 2012 8:06:14 PM org.apache.catalina.util.LifecycleBase start
INFO: The start() method was called on component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/WebApplication2]] after start() had already been called. The second call will be ignored.
Sep 14, 2012 8:06:38 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
Sep 14, 2012 8:06:38 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Sep 14, 2012 8:06:38 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Sep 14, 2012 8:06:38 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Sep 14, 2012 8:06:38 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Sep 14, 2012 8:06:38 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : com/UserBean.hbm.xml
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: com.UserBean -> USERS
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Sep 14, 2012 8:06:39 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Sep 14, 2012 8:06:39 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Sep 14, 2012 8:06:39 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Sep 14, 2012 8:06:39 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.apache.derby.jdbc.ClientDriver at URL: jdbc:derby://localhost:1527/sample
Sep 14, 2012 8:06:39 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=app, password=****}
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Apache Derby, version: 10.8.1.2 - (1095077)
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Apache Derby Network Client JDBC Driver, version: 10.8.1.2 - (1095077)
Sep 14, 2012 8:06:39 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.DerbyDialect
Sep 14, 2012 8:06:39 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Sep 14, 2012 8:06:39 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Sep 14, 2012 8:06:39 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Sep 14, 2012 8:06:39 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Sep 14, 2012 8:06:39 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Sep 14, 2012 8:06:39 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Sep 14, 2012 8:06:40 PM org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: -1, SQLState: 23502
Sep 14, 2012 8:06:40 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Column 'PASSWORD' cannot accept a NULL value.
Sep 14, 2012 8:06:40 PM org.hibernate.event.def.AbstractFlushingEventListener performExecutions
SEVERE: Could not synchronize database state with session
org.hibernate.exception.ConstraintViolationException: could not insert: [com.UserBean]
Hibernate: insert into USERS (FIRST_NAME, LAST_NAME, ADDRESS, SEX, PASSWORD, USER_NAME) values (?, ?, ?, ?, ?, ?)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2267)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
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:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at hibernetapplication2.RegisterUser.doPost(RegisterUser.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:304)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.sql.SQLIntegrityConstraintViolationException: Column 'PASSWORD' cannot accept a NULL value.
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.PreparedStatement.executeUpdate(Unknown Source)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2247)
... 32 more
Caused by: org.apache.derby.client.am.SqlException: Column 'PASSWORD' cannot accept a NULL value.
at org.apache.derby.client.am.Statement.completeExecute(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parseEXCSQLSTTreply(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.readExecute(Unknown Source)
at org.apache.derby.client.net.StatementReply.readExecute(Unknown Source)
at org.apache.derby.client.net.NetPreparedStatement.readExecute_(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.readExecute(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.flowExecute(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.executeUpdateX(Unknown Source)
... 35 more

org.hibernate.exception.ConstraintViolationException: could not insert: [com.UserBean]
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2267)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2660)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:56)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:234)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141)
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:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:106)
at hibernetapplication2.RegisterUser.doPost(RegisterUser.java:98)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:304)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:224)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:405)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:964)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:515)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:304)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.sql.SQLIntegrityConstraintViolationException: Column 'PASSWORD' cannot accept a NULL value.
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.PreparedStatement.executeUpdate(Unknown Source)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2247)
... 32 more
Caused by: org.apache.derby.client.am.SqlException: Column 'PASSWORD' cannot accept a NULL value.
at org.apache.derby.client.am.Statement.completeExecute(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.parseEXCSQLSTTreply(Unknown Source)
at org.apache.derby.client.net.NetStatementReply.readExecute(Unknown Source)
at org.apache.derby.client.net.StatementReply.readExecute(Unknown Source)
at org.apache.derby.client.net.NetPreparedStatement.readExecute_(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.readExecute(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.flowExecute(Unknown Source)
at org.apache.derby.client.am.PreparedStatement.executeUpdateX(Unknown Source)
... 35 more
 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is resolved. The error was in the way I had created the table in the derby database.
 
Ranch Hand
Posts: 930
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you send the updated table structure
 
Chan Ag
Rancher
Posts: 1090
14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Table structure

Column Name = FIRST_NAME, Nulls Allowed = yes(checked means yes), Data Type = varchar, column Size 30, decimal digits 0, Position 1
Column Name = LAST_NAME, Nulls Allowed = yes, Data Type = varchar, column Size 30, decimal digits 0, position 2
Column Name = Address, Nulls Allowed = yes, Data Type = varchar, column size 30, decimal digits 0, position 3
Column Name = SEX, Nulls Allowed = yes, Data Type = varchar, column size 1, decimal digits 0, position 4
Column Name = USER_NAME, Nulls allowed = no ( unchecked means no), data type = Integer, column size 10, decimal digits 0, Position 5
Column Name = PASSWORD, Nulls allowed = no (unchecked means no), data type = varchar, column size = 12, decimal digits 0, Position 6.

I tried to grab the table structure and got a file with .grab extension. I opened it with notepad and then decided against attaching it :-) It looks weird.

My hbm file is as follows.



Configuration file is as follows.


And doPost method is overridden as follows.



New log after I ran it today.

Using CATALINA_BASE: "C:\Users\Someone\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base"
Using CATALINA_HOME: "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.22"
Using CATALINA_TMPDIR: "C:\Users\Someone\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\temp"
Using JRE_HOME: "C:\Program Files\Java\jdk1.7.0_04"
Using CLASSPATH: "C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.22\bin\bootstrap.jar;C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.22\bin\tomcat-juli.jar"
Oct 27, 2012 4:40:00 PM 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\Java\jdk1.7.0_04\bin;C:\windows\Sun\Java\bin;C:\windows\system32;C:\windows;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\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files\Lenovo\Bluetooth Software\;C:\Program Files\Lenovo\Bluetooth Software\syswow64;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Java\jdk1.7.0_04\bin;.
Oct 27, 2012 4:40:00 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-8084"]
Oct 27, 2012 4:40:00 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["ajp-bio-8009"]
Oct 27, 2012 4:40:00 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 581 ms
Oct 27, 2012 4:40:00 PM org.apache.catalina.core.StandardService startInternal
INFO: Starting service Catalina
Oct 27, 2012 4:40:00 PM org.apache.catalina.core.StandardEngine startInternal
INFO: Starting Servlet Engine: Apache Tomcat/7.0.22
Oct 27, 2012 4:40:00 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor manager.xml from C:\Users\Someone\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\conf\Catalina\localhost
Oct 27, 2012 4:40:01 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor ROOT.xml from C:\Users\Someone\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\conf\Catalina\localhost
Oct 27, 2012 4:40:01 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor WebApplication1.xml from C:\Users\Someone\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\conf\Catalina\localhost
Oct 27, 2012 4:40:01 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor WebApplication2.xml from C:\Users\Someone\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\conf\Catalina\localhost
Oct 27, 2012 4:40:01 PM org.apache.catalina.startup.HostConfig deployDescriptor
INFO: Deploying configuration descriptor WebApplication4.xml from C:\Users\Someone\.netbeans\7.1.2\apache-tomcat-7.0.22.0_base\conf\Catalina\localhost
Oct 27, 2012 4:40:01 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8084"]
Oct 27, 2012 4:40:01 PM org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["ajp-bio-8009"]
Oct 27, 2012 4:40:01 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1150 ms
Oct 27, 2012 4:40:41 PM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.2.5
Oct 27, 2012 4:40:41 PM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
Oct 27, 2012 4:40:41 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: Bytecode provider name : cglib
Oct 27, 2012 4:40:41 PM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
Oct 27, 2012 4:40:41 PM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
Oct 27, 2012 4:40:41 PM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
Oct 27, 2012 4:40:41 PM org.hibernate.cfg.Configuration addResource
INFO: Reading mappings from resource : com/UserBean.hbm.xml
Oct 27, 2012 4:40:41 PM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: com.UserBean -> USERS
Oct 27, 2012 4:40:41 PM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
Oct 27, 2012 4:40:41 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
Oct 27, 2012 4:40:41 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
Oct 27, 2012 4:40:41 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
Oct 27, 2012 4:40:42 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.apache.derby.jdbc.ClientDriver at URL: jdbc:derby://localhost:1527/sample
Oct 27, 2012 4:40:42 PM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=app, password=****}
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: RDBMS: Apache Derby, version: 10.8.1.2 - (1095077)
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC driver: Apache Derby Network Client JDBC Driver, version: 10.8.1.2 - (1095077)
Oct 27, 2012 4:40:42 PM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.DerbyDialect
Oct 27, 2012 4:40:42 PM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Using default transaction strategy (direct JDBC transactions)
Oct 27, 2012 4:40:42 PM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Connection release mode: auto
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL inserts for batching: disabled
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
Oct 27, 2012 4:40:42 PM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JPA-QL strict compliance: disabled
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.NoCacheProvider
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: disabled
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
Oct 27, 2012 4:40:42 PM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Named query checking : enabled
Oct 27, 2012 4:40:42 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Oct 27, 2012 4:40:42 PM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
Hibernate: insert into USERS (First_Name, Last_Name, Address, Sex, Password, User_Name) values (?, ?, ?, ?, ?, ?)


It actually inserted the record into the table. So it worked.

I had coded this example to just see how things work together. There may be clumsy and ungraceful coding constructs used in the above mentioned code. I'm still learning just the core java currently.

 
Ranch Hand
Posts: 466
1
IntelliJ IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
reply
    Bookmark Topic Watch Topic
  • New Topic