473,327 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Exception in thread "main" java.lang.NullPointerException

Please help me, I am new in hiernate.

I am using hibernate 3 and postgresql database.

I am using the below classes and xml:

Expand|Select|Wrap|Line Numbers
  1. package org.javabrains.koushik.dto;
  2.  
  3. import javax.persistence.Entity;
  4. import javax.persistence.Id;
  5.  
  6. @Entity
  7. public class UserDetails {
  8.     @Id
  9. private int userId;
  10. private String userName;
  11. public int getUserId() {
  12.     return userId;
  13. }
  14. public void setUserId(int userId) {
  15.     this.userId = userId;
  16. }
  17. public String getUserName() {
  18.     return userName;
  19. }
  20. public void setUserName(String userName) {
  21.     this.userName = userName;
  22. }
  23.  
  24. }
  25.  
************************************
Expand|Select|Wrap|Line Numbers
  1.  package org.koushik.hibernate;
  2.  
  3. import org.hibernate.Session;
  4. import org.hibernate.SessionFactory;
  5. import org.hibernate.cfg.Configuration;
  6. import org.javabrains.koushik.dto.UserDetails;
  7.  
  8. public class HibernateTest {
  9.  
  10.     /**
  11.      * @param args
  12.      */
  13.     static Session session;
  14.     public static void main(String[] args) {
  15.         UserDetails user=new UserDetails();
  16.         user.setUserId(1);
  17.         user.setUserName("First User");
  18.         try
  19.         {
  20.         SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
  21.         session=sessionFactory.openSession();
  22.         session.beginTransaction();
  23.         session.save(user);
  24.         }
  25.         catch(Exception e)
  26.         {
  27.         session.getTransaction().commit();
  28.         }
  29.     }
  30.  
  31. }
********************************************
Expand|Select|Wrap|Line Numbers
  1.   <?xml version="1.0" encoding="utf-8" ?> 
  2. - <!--   ~ Hibernate, Relational Persistence for Idiomatic Java
  3.   ~
  4.   ~ Copyright (c) 2010, Red Hat Inc. or third-party contributors as
  5.   ~ indicated by the @author tags or express copyright attribution
  6.   ~ statements applied by the authors.  All third-party contributions are
  7.   ~ distributed under license by Red Hat Inc.
  8.   ~
  9.   ~ This copyrighted material is made available to anyone wishing to use, modify,
  10.   ~ copy, or redistribute it subject to the terms and conditions of the GNU
  11.   ~ Lesser General Public License, as published by the Free Software Foundation.
  12.   ~
  13.   ~ This program is distributed in the hope that it will be useful,
  14.   ~ but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  15.   ~ or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
  16.   ~ for more details.
  17.   ~
  18.   ~ You should have received a copy of the GNU Lesser General Public License
  19.   ~ along with this distribution; if not, write to:
  20.   ~ Free Software Foundation, Inc.
  21.   ~ 51 Franklin Street, Fifth Floor
  22.   ~ Boston, MA  02110-1301  USA
  23.  
  24.   --> 
  25.  <!DOCTYPE hibernate-configuration PUBLIC
  26. "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
  27. "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
  28. - <hibernate-configuration>
  29. - <session-factory>
  30. - <!--  Database connection settings 
  31.   --> 
  32.   <property name="connection.driver_class">org.postgresql.Driver</property> 
  33.   <property name="connection.url">jdbc:postgresql://localhost:5432/hibernatedb</property> 
  34.   <property name="connection.username">postgres</property> 
  35.   <property name="connection.password">password</property> 
  36. - <!--  JDBC connection pool (use the built-in) 
  37.   --> 
  38.   <property name="connection.pool_size">1</property> 
  39. - <!--  SQL dialect 
  40.   --> 
  41.   <property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property> 
  42. - <!--  Disable the second-level cache  
  43.   --> 
  44.   <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> 
  45. - <!--  Echo all executed SQL to stdout 
  46.   --> 
  47.   <property name="show_sql">true</property> 
  48. - <!--  Drop and re-create the database schema on startup 
  49.   --> 
  50.   <property name="hbm2ddl.auto">create</property> 
  51. - <!--  Names the annotated entity class 
  52.   --> 
  53.   <mapping class="org.javabrains.koushik.dto.UserDetails" /> 
  54.   </session-factory>
  55.   </hibernate-configuration>
Jan 24 '13 #1
0 1503

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: JeffRoot | last post by:
I receive the following error message when I try to run the Database Configuration Assistant on Solaris 8 / Oracle 9i. Does anyone know the solution to this problem? I thought it might have...
1
oll3i
by: oll3i | last post by:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Zad21.Cennik.getCenna(Cennik.java) at Zad21.KwiaciarniaView$1.actionPerformed(KwiaciarniaView.java) at...
3
sammyboy78
by: sammyboy78 | last post by:
Hello again, This time I'm creating a program that creates an array of CD objects and then displays the information. I've created a CD class, a CDInventory class and then a CDInventoryDisplay to...
1
by: GHKASHYAP | last post by:
Hi this is the exception i am getting when i am trying to run this application: Exception in thread "main" java.lang.NullPointerException thanks in advance.. package...
2
by: josephx | last post by:
Hello, I got some of these errors listed below after executing an HTTP Post MIDlet on CLDC/MIDP platform, "Nokia S40 DP 2.0 SDK 1.1" and "S40 5th Edition SDK Feature Pack 1" and even for S60's...
1
by: ksrashmi | last post by:
HI I am getting following exception when i use mxml tags in jsp <%@ taglib uri="FlexTagLib" prefix="mm" %> can any one tell why i am getting this exception type Exception report message...
3
by: ohadr | last post by:
hi, i get Exception in thread "main" java.lang.NullPointerException when i run my application. the exact error is: "Exception in thread "main" java.lang.NullPointerException at...
1
by: onlinegear | last post by:
HI i am writing this for college i know i have loads of combo boxes with nothing in the i havent got that far yet. but every time i run this is comes up with this erro run: Exception in thread...
3
by: makweatan | last post by:
Hello guys... Data is not updated into table. I got this error : java.lang.NullPointerException 00000030 SystemErr R java.lang.NullPointerException 00000030 SystemErr R at...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.