-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Error While Creating Session Factory
PostPosted: Sun Jan 09, 2011 9:19 am 
Newbie

Joined: Sun Jan 09, 2011 9:08 am
Posts: 2
Im new to hibernate, While im tring my first program with struts2 at that time i got this error how to solve this.

Awaiting for replay:

In Tomcat Server While Starting:
Quote:
INFO: Named query checking : enabled
Jan 9, 2011 1:11:14 PM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
Unable to instantiate default tuplizer [org.hibernate.tuple.entity.PojoEntityTuplizer]
######### HIBERNATE SP EXECEPTION #########
Jan 9, 2011 1:11:16 PM com.opensymphony.xwork2.util.logging.commons.CommonsLogger info


While Accessing file at that time
Quote:
java.lang.NullPointerException
com.treselle.sp.examples.hsex1.customer.action.CustomerAction.listCustomer(CustomerAction.java:82)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)


Customer Action file contains;
Code:
SessionFactory sessionFactory =
                (SessionFactory) ServletActionContext.getServletContext().getAttribute(HibernateListener.KEY_NAME);
        System.out.println("^^^^^^^^^^^^^^^^ sessionFactory : "+ sessionFactory);

        Session session = sessionFactory.openSession();   //line 82


my hbm file
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="com.treselle.sp.examples.hsex1.customer.model.Customer"
   table="customer" catalog="sample">

        <id name="customerId" type="java.lang.Long">
            <column name="CUSTOMER_ID" />
            <generator class="identity" />
        </id>
        <property name="name" type="string">
            <column name="NAME" length="45" not-null="true" />
        </property>
        <property name="address" type="string">
            <column name="ADDRESS" not-null="true" />
        </property>
        <property name="createdDate" type="timestamp">
            <column name="CREATED_DATE" length="19" not-null="true" />
        </property>
    </class>
</hibernate-mapping>


My Entity Pojo:
Code:
package com.treselle.sp.examples.hibernatestruts.customer.model;

import java.util.Date;

/**
*
* @author prakash
*/
public class Customer implements java.io.Serializable {

    private Long customerId;
    private String name;
    private String address;
    private Date createdDate;

    public Customer()
    {
    }

    public Customer(String name, String address, Date createdDate)
    {
        this.name = name;
        this.address = address;
        this.createdDate = createdDate;
    }

    public Long getCustomerId()
    {
        return this.customerId;
    }

    public void setCustomerId(Long customerId)
    {
        this.customerId = customerId;
    }

    public String getName()
    {
        return this.name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getAddress()
    {
        return this.address;
    }

    public void setAddress(String address)
    {
        this.address = address;
    }

    public Date getCreatedDate()
    {
        return this.createdDate;
    }

    public void setCreatedDate(Date createdDate)
    {
        this.createdDate = createdDate;
    }
}


Top
 Profile  
 
 Post subject: Re: Error While Creating Session Factory
PostPosted: Mon Jan 10, 2011 5:47 am 
Newbie

Joined: Sun Jan 09, 2011 9:08 am
Posts: 2
Thanks to every one who try to give solution:

When we used hibernate-3.2.GA.jar at that time we need to use asm-3.1.jar and cglib-2.2.jar
I Changed this and my problem is rectified.

The Solution is:

1: Ensure that the getter and setter functions are in the format: getVariablename, and setVariablename. The variable names will have to be the same as the ones listed inside the bean. E.g. if the variable is username, the getter and setter will be getUsername and setUsername

2: Add javassist.jar

3: U will get this error if you don't have the getter and the setter of a variable.

4: If you add a getter method not on a variable you need to annotate it with @Transient (hibernate will leave that getter out)

5: Maybe the cause are jar files you have added to classpath

6: replace old cglib-2.1.jar to cglib-2.2.jar

7: replace old asm-1.3.1 to asm-3.1

Thanks
Prakash.S


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.