Hi All,
I'm new to hibernate so struggling a little. I have two POJOs (
BreakDTO and
BreakNoteDTO) mapped to two separate tables.
BreakDTO has a one-to-many relationship with
BreakNoteDTO also referenced by a foreign key in the database table. (Also,
BreakDTO declares a
BreakNoteDTO object)
The problem I'm having is when I call a get method to get all
BreakDTO objects, a nullpointer exception is thrown when it goes to retrieve the
BreakNoteDTO object.
I've attached the POJOs and the mapping files and also the generated sql. Thanks very much for your help :-)
Code:
/**
*
*/
package com.ubs.eae.facade.data;
import java.io.Serializable;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.List;
/**
* @author dipeolay
*
*/
public class BreakDTO implements Serializable {
private int ttid;
private Long id;
private int leId;
private int cptyLeId;
private String contractNumber;
private char contractType;
private String status;
private String secCode;
private String secName;
private String breakType;
private Double ourQty;
private Double ourAmount;
private Double ourRate;
private String ourRateCode;
private String ourRoundingIndicator;
private String ourMarkParameter;
private boolean isTrackedUs;
private Calendar ourDeliveryDate;
private Double ourDividendTaxRate;
private Double cptyQty;
private Double cptyAmount;
private Double cptyRate;
private String cptyRateCode;
private String cptyRoundingIndicator;
private String cptyMarkParameter;
private boolean isTrackedCpty;
private Calendar cptyDeliveryDate;
private Double cptyDividendTaxRate;
private String comments;
private BreakNoteDTO [] notes;
private Calendar updated;
/**
*
*/
public BreakDTO() {
}
/**
* @return the id
*/
public Long getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(Long id) {
this.id = id;
}
public int getTtid(){
return ttid;
}
public void setTtid(int ttid){
this.ttid = ttid;
}
/**
* @return the breakType
*/
public String getBreakType() {
return breakType;
}
/**
* @param breakType the breakType to set
*/
public void setBreakType(String breakTypes) {
this.breakType = breakTypes;
}
/**
* @return the comments
*/
public String getComments() {
return comments;
}
/**
* @param comments the comments to set
*/
public void setComments(String comments) {
this.comments = comments;
}
/**
* @return the contractNumber
*/
public String getContractNumber() {
return contractNumber;
}
/**
* @param contractNumber the contractNumber to set
*/
public void setContractNumber(String contractNumber) {
this.contractNumber = contractNumber;
}
/**
* @return the contractType
*/
public char getContractType() {
return contractType;
}
/**
* @param contractType the contractType to set
*/
public void setContractType(char contractType) {
this.contractType = contractType;
}
/**
* @return the cptyAmount
*/
public Double getCptyAmount() {
return cptyAmount;
}
/**
* @param cptyAmount the cptyAmount to set
*/
public void setCptyAmount(Double cptyAmount) {
this.cptyAmount = cptyAmount;
}
/**
* @return the cptyDeliveryDate
*/
public Calendar getCptyDeliveryDate() {
return cptyDeliveryDate;
}
/**
* @param cptyDeliveryDate the cptyDeliveryDate to set
*/
public void setCptyDeliveryDate(Calendar cptyDeliveryDate) {
this.cptyDeliveryDate = cptyDeliveryDate;
}
/**
* @return the cptyDividendTaxRate
*/
public Double getCptyDividendTaxRate() {
return cptyDividendTaxRate;
}
/**
* @param cptyDividendTaxRate the cptyDividendTaxRate to set
*/
public void setCptyDividendTaxRate(Double cptyDividendTaxRate) {
this.cptyDividendTaxRate = cptyDividendTaxRate;
}
/**
* @return the cptyMarkParameter
*/
public String getCptyMarkParameter() {
return cptyMarkParameter;
}
/**
* @param cptyMarkParameter the cptyMarkParameter to set
*/
public void setCptyMarkParameter(String cptyMarkParameter) {
this.cptyMarkParameter = cptyMarkParameter;
}
/**
* @return the cptyQty
*/
public Double getCptyQty() {
return cptyQty;
}
/**
* @param cptyQty the cptyQty to set
*/
public void setCptyQty(Double cptyQty) {
this.cptyQty = cptyQty;
}
/**
* @return the cptyRate
*/
public Double getCptyRate() {
return cptyRate;
}
/**
* @param cptyRate the cptyRate to set
*/
public void setCptyRate(Double cptyRate) {
this.cptyRate = cptyRate;
}
/**
* @return the cptyRoundingIndicator
*/
public String getCptyRoundingIndicator() {
return cptyRoundingIndicator;
}
/**
* @param cptyRoundingIndicator the cptyRoundingIndicator to set
*/
public void setCptyRoundingIndicator(String cptyRoundingIndicator) {
this.cptyRoundingIndicator = cptyRoundingIndicator;
}
/**
* @return the isTrackedCpty
*/
public boolean getIsTrackedCpty() {
return isTrackedCpty;
}
/**
* @param isTrackedCpty the isTrackedCpty to set
*/
public void setIsTrackedCpty(boolean isTrackedCpty) {
this.isTrackedCpty = isTrackedCpty;
}
/**
* @return the isTrackedUs
*/
public boolean getIsTrackedUs() {
return isTrackedUs;
}
/**
* @param isTrackedUs the isTrackedUs to set
*/
public void setIsTrackedUs(boolean isTrackedUs) {
this.isTrackedUs = isTrackedUs;
}
/**
* @return the notes
*/
public BreakNoteDTO [] getNotes() {
//notes = breakNotes.toArray(new BreakNoteDTO[breakNotes.size()]);
return notes;
}
/**
* @param notes the notes to set
*/
public void setNotes(BreakNoteDTO[] notes) {
this.notes = notes;
}
/**
* @return the ourAmount
*/
public Double getOurAmount() {
return ourAmount;
}
/**
* @param ourAmount the ourAmount to set
*/
public void setOurAmount(Double ourAmount) {
this.ourAmount = ourAmount;
}
/**
* @return the ourDeliveryDate
*/
public Calendar getOurDeliveryDate() {
return ourDeliveryDate;
}
/**
* @param ourDeliveryDate the ourDeliveryDate to set
*/
public void setOurDeliveryDate(Calendar ourDeliveryDate) {
this.ourDeliveryDate = ourDeliveryDate;
}
/**
* @return the ourDividendTaxRate
*/
public Double getOurDividendTaxRate() {
return ourDividendTaxRate;
}
/**
* @param ourDividendTaxRate the ourDividendTaxRate to set
*/
public void setOurDividendTaxRate(Double ourDividendTaxRate) {
this.ourDividendTaxRate = ourDividendTaxRate;
}
/**
* @return the ourMarkParameter
*/
public String getOurMarkParameter() {
return ourMarkParameter;
}
/**
* @param ourMarkParameter the ourMarkParameter to set
*/
public void setOurMarkParameter(String ourMarkParameter) {
this.ourMarkParameter = ourMarkParameter;
}
/**
* @return the ourQty
*/
public Double getOurQty() {
return ourQty;
}
/**
* @param ourQty the ourQty to set
*/
public void setOurQty(Double ourQty) {
this.ourQty = ourQty;
}
/**
* @return the ourRate
*/
public Double getOurRate() {
return ourRate;
}
/**
* @param ourRate the ourRate to set
*/
public void setOurRate(Double ourRate) {
this.ourRate = ourRate;
}
/**
* @return the ourRateCode
*/
public String getOurRateCode() {
return ourRateCode;
}
/**
* @param ourRateCode the ourRateCode to set
*/
public void setOurRateCode(String ourRateCode) {
this.ourRateCode = ourRateCode;
}
/**
* @return the ourRoundingIndicator
*/
public String getOurRoundingIndicator() {
return ourRoundingIndicator;
}
/**
* @param ourRoundingIndicator the ourRoundingIndicator to set
*/
public void setOurRoundingIndicator(String ourRoundingIndicator) {
this.ourRoundingIndicator = ourRoundingIndicator;
}
/**
* @return the secCode
*/
public String getSecCode() {
return secCode;
}
/**
* @param secCode the secCode to set
*/
public void setSecCode(String secCode) {
this.secCode = secCode;
}
/**
* @return the secName
*/
public String getSecName() {
return secName;
}
/**
* @param secName the secName to set
*/
public void setSecName(String secName) {
this.secName = secName;
}
/**
* @return the status
*/
public String getStatus() {
return status;
}
/**
* @param status the status to set
*/
public void setStatus(String status) {
this.status = status;
}
public String getCptyRateCode() {
return cptyRateCode;
}
public void setCptyRateCode(String cptyRateCode) {
this.cptyRateCode = cptyRateCode;
}
public int getCptyLeId() {
return cptyLeId;
}
public void setCptyLeId(int cptyLeId) {
this.cptyLeId = cptyLeId;
}
public int getLeId() {
return leId;
}
public void setLeId(int leId) {
this.leId = leId;
}
/**
* @param updated the updated to set
*/
public void setUpdated(Calendar updated) {
this.updated = updated;
}
/**
* @return the updated
*/
public Calendar getUpdated() {
return updated;
}
public int hashCode() {
if (contractNumber == null) return 0;
return contractNumber.hashCode();
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final BreakDTO other = (BreakDTO) obj;
if (contractNumber == null) {
if (other.contractNumber != null)
return false;
} else if (!contractNumber.equals(other.contractNumber))
return false;
return true;
}
}
Code:
/**
*
*/
package com.ubs.eae.facade.data;
import java.io.Serializable;
import java.util.Calendar;
/**
* @author dipeolay
*
*/
public class BreakNoteDTO implements Serializable {
private Long id;
private Long breakId;
private String breakNote;
private Calendar addedAt;
private String addedBy;
/**
*/
public BreakNoteDTO() {
}
public Calendar getAddedAt() {
return addedAt;
}
public void setAddedAt(Calendar addedAt) {
this.addedAt = addedAt;
}
public String getAddedBy() {
return addedBy;
}
public void setAddedBy(String addedBy) {
this.addedBy = addedBy;
}
public Long getBreakId() {
return breakId;
}
public void setBreakId(Long breakId) {
this.breakId = breakId;
}
public String getBreakNote() {
return breakNote;
}
public void setBreakNote(String breakNote) {
this.breakNote = breakNote;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public int hashCode() {
if (breakId == null) return 0;
return breakId.hashCode();
}
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final BreakNoteDTO other = (BreakNoteDTO) obj;
if (breakId == null) {
if (other.breakId != null)
return false;
} else if (!breakId.equals(other.breakId))
return false;
return true;
}
}
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.ubs.eae.facade.data.BreakDTO" table="CONTRACT_COMP_BREAKS">
<id column = "EXTERNAL_REF_ID"
name = "id"
type = "java.lang.Long" >
<generator class="sequence">
<param name="sequence">CONTRACT_COMP_BREAKS_SEQ</param>
</generator>
</id>
<property
column ="INTERNAL_REF_ID"
name = "contractNumber"
type = "java.lang.String"
not-null = "true"
unique = "true"/>
<property
column = "BORROW_LOAN_IND"
name = "contractType"
type = "char"
not-null = "true"/>
<property
column="LEGAL_ENTITY_ID"
name="leId"
not-null="true"
type="int"
/>
<property
column="COUNTERPARTY_LE_ID"
name="cptyLeId"
not-null="true"
type="int"
/>
<property
column="TIMETABLE_ID"
name="ttid"
not-null="true"
type="int"
/>
<property
column="BREAK_TYPE"
name="breakType"
not-null="true"
type="java.lang.String"
/>
<property
column="BREAK_STATUS"
name="status"
not-null="true"
type="java.lang.String"
/>
<property
column="SEC_ID"
name="secCode"
not-null="false"
type="java.lang.String"
/>
<property
column="SEC_NAME"
name="secName"
not-null="false"
type="java.lang.String"
/>
<property
column="QTY_LE"
name="ourQty"
not-null="false"
type="java.lang.Double"
/>
<property
column="QTY_CPTY"
name="cptyQty"
not-null="false"
type="java.lang.Double"
/>
<property
column="RATE_LE"
name="ourRate"
not-null="false"
type="java.lang.Double"
/>
<property
column="RATE_CPTY"
name="cptyRate"
not-null="false"
type="java.lang.Double"
/>
<property
column="RATE_CODE_LE"
name="ourRateCode"
not-null="false"
type="java.lang.String"
/>
<property
column="RATE_CODE_CPTY"
name="cptyRateCode"
not-null="false"
type="java.lang.String"
/>
<property
column="LE_ROUNDING_IND"
name="ourRoundingIndicator"
not-null="false"
type="java.lang.String"
/>
<property
column="CPTY_ROUNDING_IND"
name="cptyRoundingIndicator"
not-null="false"
type="java.lang.String"
/>
<property
column="LE_MARK_PARAMS"
name="ourMarkParameter"
not-null="false"
type="java.lang.String"
/>
<property
column="CPTY_MARK_PARAMS"
name="cptyMarkParameter"
not-null="false"
type="java.lang.String"
/>
<property
column="TRACKED_BY_LE"
name="isTrackedUs"
not-null="false"
type="boolean"
/>
<property
column="TRACKED_BY_CPTY"
name="isTrackedCpty"
not-null="false"
type="boolean"
/>
<property
column="LE_DELIVERY_DATE"
name="ourDeliveryDate"
not-null="false"
type="java.util.Calendar"
/>
<property
column="CPTY_DELIVERY_DATE"
name="cptyDeliveryDate"
not-null="false"
type="java.util.Calendar"
/>
<property
column="LE_DIV_TAX_RATE"
name="ourDividendTaxRate"
not-null="false"
type="java.lang.Double"
/>
<property
column="CPTY_DIV_TAX_RATE"
name="cptyDividendTaxRate"
not-null="false"
type="java.lang.Double"
/>
<property
column="LE_AMOUNT"
name="ourAmount"
not-null="false"
type="java.lang.Double"
/>
<property
column="CPTY_AMOUNT"
name="cptyAmount"
not-null="false"
type="java.lang.Double"
/>
<property
column="COMMENTS"
name="comments"
not-null="false"
type="java.lang.String"
/>
<property
column="UPDATED"
name="updated"
not-null="false"
type="java.util.Calendar"
/>
<array name="notes" cascade="all" >
<key column ="BREAK_ID"/>
<index column = "NOTE_ID"/>
<one-to-many class="com.ubs.eae.facade.data.BreakNoteDTO"/>
</array>
</class>
</hibernate-mapping>
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.ubs.eae.facade.data.BreakNoteDTO" table="CONTRACT_BREAK_NOTES">
<id name = "id" column = "NOTE_ID" type = "java.lang.Long">
<generator class="sequence">
<param name="sequence">CONTRACT_BREAK_NOTES_SEQ</param>
</generator>
</id>
<property name="breakId" column = "BREAK_ID" type = "java.lang.Long" not-null = "true" />
<property name = "breakNote" column = "NOTE" type = "java.lang.String" not-null="true" length ="100"/>
<property name = "addedAt" column = "UPDATED" type = "java.util.Calendar" not-null="true"/>
<property name = "addedBy" column = "UPDATED_BY" type = "java.lang.String" not-null="true" length ="10"/>
<!-- many-to-one
name="breakId"
class="com.ubs.eae.facade.data.BreakDTO"
not-null="true" >
<column name="BREAK_ID" />
</many-to-one>-->
</class>
</hibernate-mapping>
Code:
Hibernate: select breakdto0_.EXTERNAL_REF_ID as EXTERNAL1_, breakdto0_.INTERNAL_REF_ID as INTERNAL2_, breakdto0_.BORROW_LOAN_IND as BORROW_L3_, breakdto0_.LEGAL_ENTITY_ID as LEGAL_EN4_, breakdto0_.COUNTERPARTY_LE_ID as COUNTERP5_, breakdto0_.TIMETABLE_ID as TIMETABL6_, breakdto0_.BREAK_TYPE as BREAK_TYPE, breakdto0_.BREAK_STATUS as BREAK_ST8_, breakdto0_.SEC_ID as SEC_ID, breakdto0_.SEC_NAME as SEC_NAME, breakdto0_.QTY_LE as QTY_LE, breakdto0_.QTY_CPTY as QTY_CPTY, breakdto0_.RATE_LE as RATE_LE, breakdto0_.RATE_CPTY as RATE_CPTY, breakdto0_.RATE_CODE_LE as RATE_CO15_, breakdto0_.RATE_CODE_CPTY as RATE_CO16_, breakdto0_.LE_ROUNDING_IND as LE_ROUN17_, breakdto0_.CPTY_ROUNDING_IND as CPTY_RO18_, breakdto0_.LE_MARK_PARAMS as LE_MARK19_, breakdto0_.CPTY_MARK_PARAMS as CPTY_MA20_, breakdto0_.TRACKED_BY_LE as TRACKED21_, breakdto0_.TRACKED_BY_CPTY as TRACKED22_, breakdto0_.LE_DELIVERY_DATE as LE_DELI23_, breakdto0_.CPTY_DELIVERY_DATE as CPTY_DE24_, breakdto0_.LE_DIV_TAX_RATE as LE_DIV_25_, breakdto0_.CPTY_DIV_TAX_RATE as CPTY_DI26_, breakdto0_.LE_AMOUNT as LE_AMOUNT, breakdto0_.CPTY_AMOUNT as CPTY_AM28_, breakdto0_.COMMENTS as COMMENTS, breakdto0_.UPDATED as UPDATED from CONTRACT_COMP_BREAKS breakdto0_ where (breakdto0_.LEGAL_ENTITY_ID=0642 )and(breakdto0_.COUNTERPARTY_LE_ID=5284 )
Hibernate: select notes0_.NOTE_ID as NOTE_ID__, notes0_.BREAK_ID as BREAK_ID__, notes0_.NOTE_ID as NOTE_ID0_, notes0_.BREAK_ID as BREAK_ID0_, notes0_.NOTE as NOTE0_, notes0_.UPDATED as UPDATED0_, notes0_.UPDATED_BY as UPDATED_BY0_ from CONTRACT_BREAK_NOTES notes0_ where notes0_.BREAK_ID=?
Hibernate: select notes0_.NOTE_ID as NOTE_ID__, notes0_.BREAK_ID as BREAK_ID__, notes0_.NOTE_ID as NOTE_ID0_, notes0_.BREAK_ID as BREAK_ID0_, notes0_.NOTE as NOTE0_, notes0_.UPDATED as UPDATED0_, notes0_.UPDATED_BY as UPDATED_BY0_ from CONTRACT_BREAK_NOTES notes0_ where notes0_.BREAK_ID=?
Hibernate: select notes0_.NOTE_ID as NOTE_ID__, notes0_.BREAK_ID as BREAK_ID__, notes0_.NOTE_ID as NOTE_ID0_, notes0_.BREAK_ID as BREAK_ID0_, notes0_.NOTE as NOTE0_, notes0_.UPDATED as UPDATED0_, notes0_.UPDATED_BY as UPDATED_BY0_ from CONTRACT_BREAK_NOTES notes0_ where notes0_.BREAK_ID=?
Hibernate: select notes0_.NOTE_ID as NOTE_ID__, notes0_.BREAK_ID as BREAK_ID__, notes0_.NOTE_ID as NOTE_ID0_, notes0_.BREAK_ID as BREAK_ID0_, notes0_.NOTE as NOTE0_, notes0_.UPDATED as UPDATED0_, notes0_.UPDATED_BY as UPDATED_BY0_ from CONTRACT_BREAK_NOTES notes0_ where notes0_.BREAK_ID=?
Hibernate: select notes0_.NOTE_ID as NOTE_ID__, notes0_.BREAK_ID as BREAK_ID__, notes0_.NOTE_ID as NOTE_ID0_, notes0_.BREAK_ID as BREAK_ID0_, notes0_.NOTE as NOTE0_, notes0_.UPDATED as UPDATED0_, notes0_.UPDATED_BY as UPDATED_BY0_ from CONTRACT_BREAK_NOTES notes0_ where notes0_.BREAK_ID=?
Hibernate: select notes0_.NOTE_ID as NOTE_ID__, notes0_.BREAK_ID as BREAK_ID__, notes0_.NOTE_ID as NOTE_ID0_, notes0_.BREAK_ID as BREAK_ID0_, notes0_.NOTE as NOTE0_, notes0_.UPDATED as UPDATED0_, notes0_.UPDATED_BY as UPDATED_BY0_ from CONTRACT_BREAK_NOTES notes0_ where notes0_.BREAK_ID=?
Hibernate: select notes0_.NOTE_ID as NOTE_ID__, notes0_.BREAK_ID as BREAK_ID__, notes0_.NOTE_ID as NOTE_ID0_, notes0_.BREAK_ID as BREAK_ID0_, notes0_.NOTE as NOTE0_, notes0_.UPDATED as UPDATED0_, notes0_.UPDATED_BY as UPDATED_BY0_ from CONTRACT_BREAK_NOTES notes0_ where notes0_.BREAK_ID=?
Hibernate: select notes0_.NOTE_ID as NOTE_ID__, notes0_.BREAK_ID as BREAK_ID__, notes0_.NOTE_ID as NOTE_ID0_, notes0_.BREAK_ID as BREAK_ID0_, notes0_.NOTE as NOTE0_, notes0_.UPDATED as UPDATED0_, notes0_.UPDATED_BY as UPDATED_BY0_ from CONTRACT_BREAK_NOTES notes0_ where notes0_.BREAK_ID=?
Hibernate: select notes0_.NOTE_ID as NOTE_ID__, notes0_.BREAK_ID as BREAK_ID__, notes0_.NOTE_ID as NOTE_ID0_, notes0_.BREAK_ID as BREAK_ID0_, notes0_.NOTE as NOTE0_, notes0_.UPDATED as UPDATED0_, notes0_.UPDATED_BY as UPDATED_BY0_ from CONTRACT_BREAK_NOTES notes0_ where notes0_.BREAK_ID=?
Hibernate: select notes0_.NOTE_ID as NOTE_ID__, notes0_.BREAK_ID as BREAK_ID__, notes0_.NOTE_ID as NOTE_ID0_, notes0_.BREAK_ID as BREAK_ID0_, notes0_.NOTE as NOTE0_, notes0_.UPDATED as UPDATED0_, notes0_.UPDATED_BY as UPDATED_BY0_ from CONTRACT_BREAK_NOTES notes0_ where notes0_.BREAK_ID=?
Hibernate: select notes0_.NOTE_ID as NOTE_ID__, notes0_.BREAK_ID as BREAK_ID__, notes0_.NOTE_ID as NOTE_ID0_, notes0_.BREAK_ID as BREAK_ID0_, notes0_.NOTE as NOTE0_, notes0_.UPDATED as UPDATED0_, notes0_.UPDATED_BY as UPDATED_BY0_ from CONTRACT_BREAK_NOTES notes0_ where notes0_.BREAK_ID=?