-->
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: null pointer exception
PostPosted: Sun Mar 14, 2010 9:26 am 
Beginner
Beginner

Joined: Fri Feb 26, 2010 8:23 am
Posts: 29
i have try with association as u said but i am getting the same null pointer exception.

once again i send the modified outer join query with the foreign key mapping.

help me it is very urgent.where i have done the mistake

my main class
package simple;

import org.hibernate.Query;
import org.hibernate.MappingException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import java.util.*;
import simple.Contact;
import simple.Insurance;
public class Inner {
public static void main(String[] args) {
// TODO Auto-generated method stub
Session sess = null;
try{
SessionFactory fact = new
Configuration().configure().buildSessionFactory();
sess = fact.openSession();
String sql_query = "select emp.firstname,Insurance.InsuranceName,Insurance.InvestmentAmount FROM simple.Contact emp left outer join fetch simple.Insurance Insurance where emp.InsID = Insurance.InsID";
Query query = sess.createQuery(sql_query);
Iterator ite = query.list().iterator();
System.out.println("First Name\t"+"Insurance Name\t"+"InvestmentAmount");
while ( ite.hasNext() ) {
Object[] pair = (Object[]) ite.next();
Contact con = (Contact) pair[0];
Insurance ins = (Insurance) pair[1];
System.out.print(con.getFirstName());
System.out.print("\t"+ins.getInsuranceName());
System.out.print("\t\t"+ins.getInvestementAmount());
System.out.println();
/*System.out.println("First Name:"+pair[0]);
System.out.println("Insurance name:"+pair[1]);
System.out.println("InvestmentAmount:"+pair[2]);*/


}
sess.close();
}
catch(Exception e ){
System.out.println(e.getMessage());
e.printStackTrace();
}

}

}






package simple;
import java.util.*;
public class Contact {
private String firstName;
private String lastName;
private int insid;
private int id;
private List insurance;
public List getInsurance()
{
return insurance;
}
public void setInsurance(List insurance)
{
this.insurance = insurance;
}

/**
* @return insid
*/

/**
* @return First Name
*/

public String getFirstName() {
return firstName;
}

/**
* @return Last name
*/
public String getLastName() {
return lastName;
}


public int getinsid() {
return insid;
}

/**
* @param string Sets the Insid
*/

public void setinsid(int i) {
insid = i;
}

/**
* @param string Sets the First Name
*/
public void setFirstName(String string) {
firstName = string;
}

/**
* @param string sets the Last Name
*/
public void setLastName(String string) {
lastName = string;
}
public int getId() {
return id;
}

/**
* @param l Sets the ID
*/
public void setId(int i) {
id = i;
}

}

package simple;

import java.util.List;

public class Insurance {

private String insuranceName;
private double investementAmount;
private int id;
private List Contact;
public List getContact()
{
return Contact;
}
public void setContact(List Contact)
{
this.Contact = Contact;
}


public String getInsuranceName() {
return insuranceName;
}

public void setInsuranceName(String insuranceName) {
this.insuranceName = insuranceName;
}

public double getInvestementAmount() {
return investementAmount;
}

public void setInvestementAmount(double investementAmount) {
this.investementAmount = investementAmount;
}


public int getId() {
return id;
}
public void setId(int Id) {
this.id = id;
}
}
contact.hbm.xml
<?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 package="simple" >
<class name="Contact" table="emp">
<id name="id" type="int" column="ID" >
<generator class="increment"/>
</id>

<property name="firstName" column ="firstname"/>
<property name="lastName" column ="lastname"/>
<property name="insid" column ="InsID"/>
<bag name="insurance" inverse="
true" cascade="all,delete-orphan">
<key column="InsID"/>
<one-to-many class="simple.Insurance"/>
</bag>
</class>
</hibernate-mapping>
}
insurance.hbm..xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="simple">
<class name="Insurance" table="Insurance">
<id name="id" column ="InsID" type="int">
<generator class="increment"/>
</id>
<property name="insuranceName" column="InsuranceName type="string" />
<property name="investementAmount" column="InvestmentAmount" type="double"/>

<many-to-one name="Contact" class="simple.Contact" column="InsID"
insert="false" update="false"/>

</class>

</hibernate-mapping>

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">

com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">

jdbc:mysql://localhost/sakthi</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">admin</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="hibernate.jdbc.batch_size">50</property>
<property name="show_sql">true</property>
<property name="connection.autocommit">false</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="contact.hbm.xml"/>
<mapping resource="insurance.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject: Re: null pointer exception
PostPosted: Sun Mar 14, 2010 9:45 am 
Beginner
Beginner

Joined: Fri Feb 26, 2010 8:23 am
Posts: 29
here is my exception java.lang.NullPointerException

please reply for me it is very urgent

at org.hibernate.hql.ast.LiteralProcessor.lookupConstant(LiteralProcessor.java:67)
at org.hibernate.hql.ast.DotNode.resolve(DotNode.java:171)
at org.hibernate.hql.ast.FromReferenceNode.resolve(FromReferenceNode.java:87)
at org.hibernate.hql.ast.HqlSqlWalker.createFromJoinElement(HqlSqlWalker.java:266)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.joinElement(HqlSqlBaseWalker.java:2475)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:2323)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2232)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:498)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:356)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:184)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:140)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:414)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:814)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:773)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at simple.Inner.main(Inner.java:21)


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.