aspose file tools*
The moose likes Object Relational Mapping and the fly likes null pointer exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "null pointer exception" Watch "null pointer exception" New topic
Author

null pointer exception

sakthi ramaraj
Greenhorn

Joined: Feb 23, 2010
Posts: 7
i am new to hibernate i am getting the null pointer exception as shown below

i am trying left outer join with unidirectional foreign key mapping

could you please point out where i had done the mistake.

java.lang.NullPointerException
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 sample.Inner.main(Inner.java:24)
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 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(pair[0]+"\t"+pair[1]+"\t"+pair[2]+"\n");
/*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();
}

}

}
Contact.java
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;
}

}

Insurance.java
package simple;

import java.util.List;

public class Insurance {

private String insuranceName;
private double investementAmount;
private int insid;
private Contact contact;
public Contact getContact()
{
return contact;
}
public void setContact(Contact 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 getinsid() {
return insid;
}

public void setinsid(int Id) {
this.insid = insid;
}
}
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="insid" column ="InsID"/>
<property name="firstName" column ="firstname"/>
<property name="lastName" column ="lastname"/>

<bag name="Insurance" inverse="true" cascade="all,delete-orphan" >
<key column="InsID" not-null="true"/>
<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="insid" 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>

hibernate.cfg.xml
<?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>












David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please UseCodeTags when posting code or configuration. Unformatted code and configuration is unnecessarily difficult to read. It's also helpful to remove unnecessary comments (does a simple getter or setter really need a comment anyway??) and so on to help reduce the amount of code we have to read in order to help.

You can edit your post by using the button.

And welcome to JavaRanch!
sakthi ramaraj
Greenhorn

Joined: Feb 23, 2010
Posts: 7
thanks for your reply
sorry hereafterwards i will use code tags

i am new to hibernate i am getting the null pointer exception as shown below

i am trying left outer join with unidirectional foreign key mapping

could you please point out where i had done the mistake.

java.lang.NullPointerException
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 sample.Inner.main(Inner.java:24)


















David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Unindented code is just as bad.

What line does the exception correspond to?
sakthi ramaraj
Greenhorn

Joined: Feb 23, 2010
Posts: 7
it is showing in this line as shown below
but i try with inner join it is working i have just use the same code
i dont know what is the problem in the left outer join

you please verify the query and tell me and also check whether i had made mistake in mapping files


reply me it is very urgent.
 
jQuery in Action, 2nd edition
 
subject: null pointer exception