-->
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.  [ 3 posts ] 
Author Message
 Post subject: Error while fetching All records from the DB
PostPosted: Sat Feb 25, 2006 10:34 am 
Newbie

Joined: Sat Feb 25, 2006 10:17 am
Posts: 2
Hi Guys / Girls,

I am a newbee on hibernate. Have ben working on hibernate for the past 4 days. I have a small problem. I have 2 tables namely Validator and ValidatorType.

ValidatorType is the parent table and Validator is the child table, i.e. Validator has a foreign key from ValidatorType many to one relationship.

The problem is that when ever i execute the fetch query for ValidatorType it works. But when i execute the fetch query for Validator it throws me the following error:

Exception in thread "main" java.lang.NullPointerException
at org.hibernate.tuple.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:372)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:3121)
at org.hibernate.event.def.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:232)
at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:173)
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:891)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:859)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:266)
at org.hibernate.type.EntityType.resolve(EntityType.java:303)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:113)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:842)
at org.hibernate.loader.Loader.doQuery(Loader.java:717)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1129)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at com.insync.ems.event.ValidatorManager.getAllValidators(ValidatorManager.java:124)
at com.insync.ems.event.EventManager.getAllValidators(EventManager.java:964)
at TestEvent.main(TestEvent.java:32)
Hibernate: select validator0_.ID as ID21_, validator0_.NAME as NAME21_, validator0_.STATUS as STATUS21_, validator0_.VALUE as VALUE21_, validator0_.DESCRIPTION as DESCRIPT5_21_, validator0_.VALIDATOR_TYPE_ID as VALIDATOR6_21_, validator0_.CREATE_TIME as CREATE7_21_, validator0_.CREATED_BY as CREATED8_21_, validator0_.MODIFY_TIME as MODIFY9_21_, validator0_.MODIFIED_BY as MODIFIED10_21_ from em_validators validator0_



I have added to POJO in validator type class and the validator class code is as follows:

ValidatorType.java
package com.insync.ems.validator;

import java.io.Serializable;
import java.util.Set;

public class ValidatorType implements Serializable
{
/**
* This attribute maps to the column ID in the em_validator_types table.
*/
private Long id;

/**
* This attribute maps to the column NAME in the em_validator_types table.
*/
private String name;

/**
* This attribute maps to the column STATUS in the em_validator_types table.
*/
private int status;

/**
* This attribute maps to the column DESCRIPTION in the em_validator_types table.
*/
private String description;

/**
* This attribute maps to the column VALIDATOR_TYPE in the em_validator_types table.
*/
private String validatorType;

/**
* This attribute maps to the column CLASSNAME in the em_validator_types table.
*/
private String classname;

/**
* This attribute maps to the column CREATE_TIME in the em_validator_types table.
*/
private long createTime;

/**
* This attribute maps to the column CREATED_BY in the em_validator_types table.
*/
private String createdBy;

/**
* This attribute maps to the column MODIFY_TIME in the em_validator_types table.
*/
private long modifyTime;

/**
* This attribute represents whether the primitive attribute modifyTime is null.
*/
private boolean modifyTimeNull = true;

/**
* This attribute maps to the column MODIFIED_BY in the em_validator_types table.
*/
private String modifiedBy;

private Set validators = null;

/**
* Method 'ValidatorType'
*
*/
public ValidatorType()
{
}

/**
* Method 'getId'
*
* @return long
*/
public Long getId()
{
return id;
}

/**
* Method 'setId'
*
* @param id
*/
public void setId(Long id)
{
this.id = id;
}

/**
* Method 'getName'
*
* @return String
*/
public String getName()
{
return name;
}

/**
* Method 'setName'
*
* @param name
*/
public void setName(String name)
{
this.name = name;
}

/**
* Method 'getStatus'
*
* @return int
*/
public int getStatus()
{
return status;
}

/**
* Method 'setStatus'
*
* @param status
*/
public void setStatus(int status)
{
this.status = status;
}

/**
* Method 'getDescription'
*
* @return String
*/
public String getDescription()
{
return description;
}

/**
* Method 'setDescription'
*
* @param description
*/
public void setDescription(String description)
{
this.description = description;
}

/**
* Method 'getValidatorType'
*
* @return String
*/
public String getValidatorType()
{
return validatorType;
}

/**
* Method 'setValidatorType'
*
* @param validatorType
*/
public void setValidatorType(String validatorType)
{
this.validatorType = validatorType;
}

/**
* Method 'getClassname'
*
* @return String
*/
public String getClassname()
{
return classname;
}

/**
* Method 'setClassname'
*
* @param classname
*/
public void setClassname(String classname)
{
this.classname = classname;
}

/**
* Method 'getCreateTime'
*
* @return long
*/
public long getCreateTime()
{
return createTime;
}

/**
* Method 'setCreateTime'
*
* @param createTime
*/
public void setCreateTime(long createTime)
{
this.createTime = createTime;
}

/**
* Method 'getCreatedBy'
*
* @return String
*/
public String getCreatedBy()
{
return createdBy;
}

/**
* Method 'setCreatedBy'
*
* @param createdBy
*/
public void setCreatedBy(String createdBy)
{
this.createdBy = createdBy;
}

/**
* Method 'getModifyTime'
*
* @return long
*/
public long getModifyTime()
{
return modifyTime;
}

/**
* Method 'setModifyTime'
*
* @param modifyTime
*/
public void setModifyTime(long modifyTime)
{
this.modifyTime = modifyTime;
setModifyTimeNull( false );
}

/**
* Sets the value of modifyTimeNull
*/
public void setModifyTimeNull(boolean modifyTimeNull)
{
this.modifyTimeNull = modifyTimeNull;
}

/**
* Gets the value of modifyTimeNull
*/
public boolean isModifyTimeNull()
{
return modifyTimeNull;
}

/**
* Method 'getModifiedBy'
*
* @return String
*/
public String getModifiedBy()
{
return modifiedBy;
}

/**
* Method 'setModifiedBy'
*
* @param modifiedBy
*/
public void setModifiedBy(String modifiedBy)
{
this.modifiedBy = modifiedBy;
}

/**
* Method 'equals'
*
* @param _other
* @return boolean
*/
public boolean equals(Object _other)
{
if (_other == null) {
return false;
}

if (_other == this) {
return true;
}

if (!(_other instanceof ValidatorType)) {
return false;
}

final ValidatorType _cast = (ValidatorType) _other;
if (id != _cast.id) {
return false;
}

if (name == null ? _cast.name != name : !name.equals( _cast.name )) {
return false;
}

if (status != _cast.status) {
return false;
}

if (description == null ? _cast.description != description : !description.equals( _cast.description )) {
return false;
}

if (validatorType == null ? _cast.validatorType != validatorType : !validatorType.equals( _cast.validatorType )) {
return false;
}

if (classname == null ? _cast.classname != classname : !classname.equals( _cast.classname )) {
return false;
}

if (createTime != _cast.createTime) {
return false;
}

if (createdBy == null ? _cast.createdBy != createdBy : !createdBy.equals( _cast.createdBy )) {
return false;
}

if (modifyTime != _cast.modifyTime) {
return false;
}

if (modifyTimeNull != _cast.modifyTimeNull) {
return false;
}

if (modifiedBy == null ? _cast.modifiedBy != modifiedBy : !modifiedBy.equals( _cast.modifiedBy )) {
return false;
}

return true;
}

/**
* Method 'hashCode'
*
* @return int
*/
public int hashCode()
{
int _hashCode = 0;
_hashCode = 29 * _hashCode + (int) (id.longValue() ^ (id.longValue() >>> 32));
if (name != null) {
_hashCode = 29 * _hashCode + name.hashCode();
}

_hashCode = 29 * _hashCode + status;
if (description != null) {
_hashCode = 29 * _hashCode + description.hashCode();
}

if (validatorType != null) {
_hashCode = 29 * _hashCode + validatorType.hashCode();
}

if (classname != null) {
_hashCode = 29 * _hashCode + classname.hashCode();
}

_hashCode = 29 * _hashCode + (int) (createTime ^ (createTime >>> 32));
if (createdBy != null) {
_hashCode = 29 * _hashCode + createdBy.hashCode();
}

_hashCode = 29 * _hashCode + (int) (modifyTime ^ (modifyTime >>> 32));
_hashCode = 29 * _hashCode + (modifyTimeNull ? 1 : 0);
if (modifiedBy != null) {
_hashCode = 29 * _hashCode + modifiedBy.hashCode();
}

return _hashCode;
}

/**
* Method 'createPk'
*
* @return ValidatorTypePk
*/
public ValidatorTypePk createPk()
{
return new ValidatorTypePk(id);
}

/**
* Method 'toString'
*
* @return String
*/
public String toString()
{
StringBuffer ret = new StringBuffer();
ret.append( "com.insync.ems.dto.ValidatorType: " );
ret.append( "id='" + id + "'" );
ret.append( ", name='" + name + "'" );
ret.append( ", status='" + status + "'" );
ret.append( ", description='" + description + "'" );
ret.append( ", validatorType='" + validatorType + "'" );
ret.append( ", classname='" + classname + "'" );
ret.append( ", createTime='" + createTime + "'" );
ret.append( ", createdBy='" + createdBy + "'" );
ret.append( ", modifyTime='" + modifyTime + "'" );
ret.append( ", modifiedBy='" + modifiedBy + "'" );
return ret.toString();
}

/**
* @param validators The validators to set.
*/
public void setValidators(Set validators) {
this.validators = validators;
}

/**
* @return Returns the validators.
*/
public Set getValidators() {
return validators;
}

}

Validator.java
package com.insync.ems.validator;

import java.io.Serializable;
import java.util.Set;

public class Validator implements Serializable
{
/**
*
*/
private static final long serialVersionUID = -383534651242266882L;

/**
* This attribute maps to the column ID in the em_validators table.
*/
private Long id;

/**
* This attribute maps to the column NAME in the em_validators table.
*/
private String name;

/**
* This attribute maps to the column STATUS in the em_validators table.
*/
private int status;

/**
* This attribute maps to the column VALUE in the em_validators table.
*/
private byte[] value;

/**
* This attribute maps to the column DESCRIPTION in the em_validators table.
*/
private String description;

/**
* This attribute maps to the column CREATE_TIME in the em_validators table.
*/
private long createTime;

/**
* This attribute maps to the column CREATED_BY in the em_validators table.
*/
private String createdBy;

/**
* This attribute maps to the column MODIFY_TIME in the em_validators table.
*/
private long modifyTime;

/**
* This attribute represents whether the primitive attribute modifyTime is null.
*/
private boolean modifyTimeNull = true;

/**
* This attribute maps to the column MODIFIED_BY in the em_validators table.
*/
private String modifiedBy;

private ValidatorType validatorType;

private Set event;

/**
* Method 'Validator'
*
*/
public Validator()
{
}

/**
* Method 'getId'
*
* @return long
*/
public Long getId()
{
return id;
}

/**
* Method 'setId'
*
* @param id
*/
public void setId(Long id)
{
this.id = id;
}

/**
* Method 'getName'
*
* @return String
*/
public String getName()
{
return name;
}

/**
* Method 'setName'
*
* @param name
*/
public void setName(String name)
{
this.name = name;
}

/**
* Method 'getStatus'
*
* @return int
*/
public int getStatus()
{
return status;
}

/**
* Method 'setStatus'
*
* @param status
*/
public void setStatus(int status)
{
this.status = status;
}

/**
* Method 'getValue'
*
* @return byte[]
*/
public byte[] getValue()
{
return value;
}

/**
* Method 'setValue'
*
* @param value
*/
public void setValue(byte[] value)
{
this.value = value;
}

/**
* Method 'getDescription'
*
* @return String
*/
public String getDescription()
{
return description;
}

/**
* Method 'setDescription'
*
* @param description
*/
public void setDescription(String description)
{
this.description = description;
}

/**
* Method 'getCreateTime'
*
* @return long
*/
public long getCreateTime()
{
return createTime;
}

/**
* Method 'setCreateTime'
*
* @param createTime
*/
public void setCreateTime(long createTime)
{
this.createTime = createTime;
}

/**
* Method 'getCreatedBy'
*
* @return String
*/
public String getCreatedBy()
{
return createdBy;
}

/**
* Method 'setCreatedBy'
*
* @param createdBy
*/
public void setCreatedBy(String createdBy)
{
this.createdBy = createdBy;
}

/**
* Method 'getModifyTime'
*
* @return long
*/
public long getModifyTime()
{
return modifyTime;
}

/**
* Method 'setModifyTime'
*
* @param modifyTime
*/
public void setModifyTime(long modifyTime)
{
this.modifyTime = modifyTime;
setModifyTimeNull( false );
}

/**
* Sets the value of modifyTimeNull
*/
public void setModifyTimeNull(boolean modifyTimeNull)
{
this.modifyTimeNull = modifyTimeNull;
}

/**
* Gets the value of modifyTimeNull
*/
public boolean isModifyTimeNull()
{
return modifyTimeNull;
}

/**
* Method 'getModifiedBy'
*
* @return String
*/
public String getModifiedBy()
{
return modifiedBy;
}

/**
* Method 'setModifiedBy'
*
* @param modifiedBy
*/
public void setModifiedBy(String modifiedBy)
{
this.modifiedBy = modifiedBy;
}

/**
* Method 'equals'
*
* @param _other
* @return boolean
*/
public boolean equals(Object _other)
{
if (_other == null) {
return false;
}

if (_other == this) {
return true;
}

if (!(_other instanceof Validator)) {
return false;
}

final Validator _cast = (Validator) _other;
if (id != _cast.id) {
return false;
}

if (name == null ? _cast.name != name : !name.equals( _cast.name )) {
return false;
}

if (status != _cast.status) {
return false;
}

if (value == null ? _cast.value != value : !value.equals( _cast.value )) {
return false;
}

if (description == null ? _cast.description != description : !description.equals( _cast.description )) {
return false;
}

if (createTime != _cast.createTime) {
return false;
}

if (createdBy == null ? _cast.createdBy != createdBy : !createdBy.equals( _cast.createdBy )) {
return false;
}

if (modifyTime != _cast.modifyTime) {
return false;
}

if (modifyTimeNull != _cast.modifyTimeNull) {
return false;
}

if (modifiedBy == null ? _cast.modifiedBy != modifiedBy : !modifiedBy.equals( _cast.modifiedBy )) {
return false;
}

return true;
}

/**
* Method 'hashCode'
*
* @return int
*/
public int hashCode()
{
int _hashCode = 0;
_hashCode = 29 * _hashCode + (int) (id.longValue() ^ (id.longValue() >>> 32));
if (name != null) {
_hashCode = 29 * _hashCode + name.hashCode();
}

_hashCode = 29 * _hashCode + status;
if (value != null) {
_hashCode = 29 * _hashCode + value.hashCode();
}

if (description != null) {
_hashCode = 29 * _hashCode + description.hashCode();
}

_hashCode = 29 * _hashCode + (int) (createTime ^ (createTime >>> 32));
if (createdBy != null) {
_hashCode = 29 * _hashCode + createdBy.hashCode();
}

_hashCode = 29 * _hashCode + (int) (modifyTime ^ (modifyTime >>> 32));
_hashCode = 29 * _hashCode + (modifyTimeNull ? 1 : 0);
if (modifiedBy != null) {
_hashCode = 29 * _hashCode + modifiedBy.hashCode();
}

return _hashCode;
}

/**
* Method 'createPk'
*
* @return ValidatorPk
*/
public ValidatorPk createPk()
{
return new ValidatorPk(id);
}

/**
* Method 'toString'
*
* @return String
*/
public String toString()
{
StringBuffer ret = new StringBuffer();
ret.append( "com.insync.ems.dto.Validator: " );
ret.append( "id='" + id + "'" );
ret.append( ", name='" + name + "'" );
ret.append( ", status='" + status + "'" );
ret.append( ", value='" + value + "'" );
ret.append( ", description='" + description + "'" );
ret.append( ", createTime='" + createTime + "'" );
ret.append( ", createdBy='" + createdBy + "'" );
ret.append( ", modifyTime='" + modifyTime + "'" );
ret.append( ", modifiedBy='" + modifiedBy + "'" );
return ret.toString();
}

/**
* @param validatorType The validatorType to set.
*/
public void setValidatorType(ValidatorType validatorType) {
this.validatorType = validatorType;
}

/**
* @return Returns the validatorType.
*/
public ValidatorType getValidatorType() {
return validatorType;
}

/**
* @param event The event to set.
*/
public void setEvent(Set event) {
this.event = event;
}

/**
* @return Returns the event.
*/
public Set getEvent() {
return event;
}

}

validatorType.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>
<class name="com.insync.ems.validator.ValidatorType" table="em_validator_types">
<id name="id" column="ID" type="long">
<generator class="org.hibernate.id.TableHiLoGenerator">
<param name="table">hibernate_unique_key</param>
<param name="column">next_hi</param>
</generator>
</id>
<property name="name" column="NAME" not-null="true" />
<property name="status" column="STATUS" not-null="true" />
<property name="description" column="DESCRIPTION" />
<property name="validatorType" column="VALIDATOR_TYPE" not-null="true" />
<property name="classname" column="CLASSNAME" not-null="true" />
<property name="createTime" column="CREATE_TIME" not-null="true" />
<property name="createdBy" column="CREATED_BY" not-null="true" />
<property name="modifyTime" column="MODIFY_TIME" />
<property name="modifiedBy" column="MODIFIED_BY" />
<set name="Validators" inverse="true" cascade="all">
<key column="ID"/>
<one-to-many class="com.insync.ems.validator.Validator"/>
</set>
</class>
<query name="com.insync.ems.validator.ValidatorManager.ValidatorType.all">
<![CDATA[from com.insync.ems.validator.ValidatorType as v]]>
</query>

<query name="com.insync.ems.validator.ValidatorManager.ValidatorType.by.name">
<![CDATA[from com.insync.ems.validator.ValidatorType as v where ucase(v.name)=ucase(?)]]>
</query>

<query name="com.insync.ems.validator.ValidatorManager.ValidatorType.by.status">
<![CDATA[from com.insync.ems.validator.ValidatorType as v where v.status=?]]>
</query>

<query name="com.insync.ems.validator.ValidatorManager.ValidatorType.by.validatorType">
<![CDATA[from com.insync.ems.validator.ValidatorType as v where ucase(v.validatorType)=ucase(?)]]>
</query>
</hibernate-mapping>


Validator.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>
<class name="com.insync.ems.validator.Validator" table="em_validators">
<id name="id" column="ID" type="long">
<generator class="org.hibernate.id.TableHiLoGenerator">
<param name="table">hibernate_unique_key</param>
<param name="column">next_hi</param>
</generator>
</id>
<!-- <property name="id" column="ID" not-null="true" />-->
<property name="name" column="NAME" not-null="true" />
<property name="status" column="STATUS" not-null="true" />
<property name="value" column="VALUE" not-null="true" />
<property name="description" column="DESCRIPTION" />
<many-to-one name="validatorType" column="VALIDATOR_TYPE_ID" class="com.insync.ems.validator.ValidatorType"/>
<property name="createTime" column="CREATE_TIME" not-null="true" />
<property name="createdBy" column="CREATED_BY" not-null="true" />
<property name="modifyTime" column="MODIFY_TIME" />
<property name="modifiedBy" column="MODIFIED_BY" />
<set name="event" inverse="true" cascade="all">
<key column="ID"/>
<one-to-many class="com.insync.ems.event.Event"/>
</set>
</class>
<query name="com.insync.ems.validator.ValidatorManager.Validator.all">
<![CDATA[from com.insync.ems.validator.Validator as v]]>
</query>
</hibernate-mapping>



I know there is something wrong in the query to fetch Validator. It is not able to fetch the ValidatorType object i believe cause i am not specifying the Join. But i am not sure how to solve it.

I would really appreciate if someone could help me out. Need to give to project by monday.

Any help would be appreciated.

REgards,
Milton

Hibernate version: 3.1

Mapping documents: 3.0

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using: MySQL 4.1

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

[quote][/quote][code][/code]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 27, 2006 12:32 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
At a guess, it's because you have a final member of Validator. CGLib has issues with finals. Can serialVersionUID be non-final? I can't remember.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 27, 2006 1:46 am 
Newbie

Joined: Sat Feb 25, 2006 10:17 am
Posts: 2
Thanx for the reply. But i guess i have solved the problem. I needed to add a join to the query in the validator.hbm.xml.

<query name="com.insync.ems.validator.ValidatorManager.Validator.all">
<![CDATA[from com.insync.ems.validator.Validator as v left join fetch v.validatorType]]>
</query>

and set the fetch="join" in the many-to-one element for Validator Type in the validator.hbm.xml


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.