www.webdeveloper.com
Results 1 to 3 of 3

Thread: Hibernate problem...

  1. #1
    Join Date
    Feb 2012
    Posts
    12

    Hibernate problem...

    Hai friends,

    i am inserting datas through Hibernate into my java program.I am using netbeans 7.1 IDE and apache tomcat 6.0 .I am not getting errors but data is not properly inserted into my mysql database.

    Can any one please help me. i am waiting for you replys.

    Thank You

    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>
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/jithin</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.connection.password">traise</property>
    <property name="hibernate.current_session_context_class">thread</property>
    <property name="hibernate.hbm2ddl.auto">create</property>
    <mapping class="org.jith.java.dto.UserDetails"></mapping>
    </session-factory>
    </hibernate-configuration>



    packagerg.jith.java.dto
    UserDetails.java

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package org.jith.java.dto;

    import javax.persistence.Entity;
    import javax.persistence.Id;

    /**
    *
    * @author alfredannaalphonsa
    */
    @Entity
    public class UserDetails {
    @Id
    private int userId;
    private String username;

    public int getUserId() {
    return userId;
    }

    public void setUserId(int userId) {
    this.userId = userId;
    }

    public String getUsername() {
    return username;
    }

    public void setUsername(String username) {
    this.username = username;
    }

    }

    Packagerg.jith.hibernate
    Class:HibernateTest.java

    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package org.jith.hibernate;

    import org.hibernate.Session;
    import org.hibernate.SessionFactory;
    import org.hibernate.cfg.Configuration;
    import org.jith.java.dto.UserDetails;

    /**
    *
    * @author alfredannaalphonsa
    */
    public class HibernateTest {



    public static void Main(String[]args){
    UserDetails user=new UserDetails();
    user.setUserId(1);
    user.setUsername("First Name");

    SessionFactory sessionFactory=new Configuration().configure().buildSessionFactory();
    Session session=sessionFactory.openSession();
    session.beginTransaction();
    session.save(user);
    session.getTransaction().commit();

    }


    }

  2. #2
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    6,119
    what do you mean by "but data is not properly inserted", can you please elaborate a bit?
    Cheers

    Khalid

    Message Posting Guidelines In These Forums, Please read these before posting any question.
    Web site: webapplikations.com
    Web Resources Page:Web Resources

  3. #3
    Join Date
    Feb 2012
    Posts
    12
    hai,

    while executing the program,in netbeans default iam getting index.jsp(web.xml)
    page and there is no error is showing also.But when checking the database, the data is not inserting..How to run this file .ANy modifications in the mapping file...???

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles