I have a mapping with has a composite key and a five key-many-to-one elements. I am getting a ClassCastException:java.lang.Integer when I attempt to simply do a session.save(obj) after populating the colums by way of the getters.
I don't understand what the Integer reference is here. I have tried all sorts of things, such as only populating the key values and making sure the types in the mappings are explictly sett for all properties, keys, etc . . .
If anyone sees a solution, please feel free to offer some advice. Below are the mappings, persistence classes and class where I am persisting the object.
Thanks much!
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 default-cascade="none" default-access="property"
default-lazy="true" auto-import="true">
<class name="ami.server.dto.datamart.billing.SongAggregateFactsDTO"
table="billing_data_mart_db.SongAggregateFacts" mutable="true"
abstract="false" polymorphism="implicit" dynamic-update="false"
dynamic-insert="false" select-before-update="false" optimistic-lock="version">
<composite-id>
<key-many-to-one name="companyId" class="ami.server.dto.datamart.billing.CompanyDimensionDTO" column="company_id"/>
<key-many-to-one name="contractId" class="ami.server.dto.datamart.billing.ContractDimensionDTO" column="contract_id"/>
<key-many-to-one name="jukeboxId" class="ami.server.dto.datamart.billing.JukeboxDimensionDTO" column="jukebox_id"/>
<key-many-to-one name="songId" class="ami.server.dto.datamart.billing.SongDimensionDTO" column="song_id"/>
<key-many-to-one name="timeId" class="ami.server.dto.datamart.billing.TimeDimensionDTO" column="time_id"/>
</composite-id>
<property name="purchasedCredits" column="purchased_credits" type="integer"/>
<property name="clearedCreditsTotal" column="cleared_credits_total" type="integer"/>
<property name="paidStdSelections" column="paid_std_selections" type="integer"/>
<property name="paidModSelections" column="paid_mod_selections" type="integer"/>
<property name="paidMsfSelections" column="paid_msf_selections" type="integer"/>
<property name="totalPaidSelections" column="total_paid_selections" type="integer"/>
<property name="ifpStdSelections" column="ifp_std_selections" type="integer"/>
<property name="ifpModSelections" column="ifp_mod_selections" type="integer"/>
<property name="ifpMsfSelections" column="ifp_msf_selections" type="integer"/>
<property name="totalIfpSelections" column="total_ifp_selections" type="integer"/>
<property name="totalPatronSelections" column="total_patron_selections" type="integer"/>
<property name="popularityPaidPlays" column="popularity_paid_plays" type="integer"/>
<property name="demoPlays" column="demo_plays" type="integer"/>
<property name="royaltyPaidPlays" column="royalty_paid_plays" type="integer"/>
<property name="ifpPlays" column="ifpPlays" type="integer"/>
<property name="playsErrors" column="plays_errors" type="integer"/>
<property name="playsOther" column="plays_other" type="integer"/>
<property name="playsRejected" column="plays_rejected" type="integer"/>
<property name="nifpSelections" column="nifp_selections" type="integer"/>
<property name="nifpPlays" column="nifp_plays" type="integer"/>
<property name="autoplaySelections" column="autoplay_selections" type="integer"/>
<property name="autoplayPlays" column="autoplayPlays" type="integer"/>
<property name="badMediaErrors" column="bad_media_errors" type="integer"/>
<property name="fadedAutoplays" column="faded_autoplays" type="integer"/>
<property name="clearedAutoplays" column="cleared_autoplays" type="integer"/>
<property name="rejectedAutoplays" column="rejected_autoplays" type="integer"/>
<property name="modCost" column="mod_cost" type="double"/>
<property name="modCharges" column="mod_charges" type="double"/>
<many-to-one name="companyId" column="company_id"
class="ami.server.dto.datamart.billing.CompanyDimensionDTO" update="false" insert="false" not-null="true"/>
<many-to-one name="contractId" column="contract_id"
class="ami.server.dto.datamart.billing.ContractDimensionDTO" update="false" insert="false" not-null="true"/>
<many-to-one name="jukeboxId" column="jukebox_id"
class="ami.server.dto.datamart.billing.JukeboxDimensionDTO" update="false" insert="false" not-null="true"/>
<many-to-one name="songId" column="song_id"
class="ami.server.dto.datamart.billing.SongDimensionDTO" update="false" insert="false" not-null="true"/>
<many-to-one name="timeId" column="time_id"
class="ami.server.dto.datamart.billing.TimeDimensionDTO" update="false" insert="false" not-null="true"/>
</class>
</hibernate-mapping>
public class SongAggregateFactsDTO implements Serializable
{
/* Composite Key Identifier – protected accessor is used seeing that we
* have to generate the key manually
*/
private Integer companyId;
private Integer contractId;
private Integer jukeboxId;
private Integer songId;
private Long timeId;
private Integer purchasedCredits;
private Integer clearedCreditsTotal;
private Integer paidStdSelections;
private Integer paidModSelections;
private Integer paidMsfSelections;
private Integer totalPaidSelections;
private Integer ifpStdSelections;
private Integer ifpModSelections;
private Integer ifpMsfSelections;
private Integer totalIfpSelections;
private Integer totalPatronSelections;
private Integer popularityPaidPlays;
private Integer royaltyPaidPlays;
private Integer demoPlays;
private Integer ifpPlays;
private Integer playsErrors;
private Integer playsOther;
private Integer playsRejected;
private Integer nifpSelections;
private Integer nifpPlays;
private Integer autoplaySelections;
private Integer autoplayPlays;
private Integer badMediaErrors;
private Integer fadedAutoplays;
private Integer clearedAutoplays;
private Integer rejectedAutoplays;
private Double modCost;
private Double modCharges;
public void setCompanyId(Integer companyId) {
this.companyId = companyId;
}
public Integer getCompanyId() {
return companyId;
}
public void setContractId(Integer contractId) {
this.contractId = contractId;
}
public Integer getContractId() {
return contractId;
}
public void setJukeboxId(Integer jukeboxId) {
this.jukeboxId = jukeboxId;
}
public Integer getJukeboxId() {
return jukeboxId;
}
public void setSongId(Integer songId) {
this.songId = songId;
}
public Integer getSongId() {
return songId;
}
public void setTimeId(Long timeId) {
this.timeId = timeId;
}
public Long getTimeId() {
return timeId;
}
public void setPurchasedCredits(Integer purchasedCredits) {
this.purchasedCredits = purchasedCredits;
}
public Integer getPurchasedCredits() {
return purchasedCredits;
}
public void setClearedCreditsTotal(Integer clearedCreditsTotal) {
this.clearedCreditsTotal = clearedCreditsTotal;
}
public Integer getClearedCreditsTotal() {
return clearedCreditsTotal;
}
public void setPaidStdSelections (Integer paidStdSelections) {
this.paidStdSelections = paidStdSelections;
}
public Integer getPaidStdSelections() {
return paidStdSelections;
}
public void setPaidModSelections (Integer paidModSelections) {
this.paidModSelections = paidModSelections;
}
public Integer getPaidModSelections() {
return paidModSelections;
}
public void setPaidMsfSelections (Integer paidMsfSelections) {
this.paidMsfSelections = paidMsfSelections;
}
public Integer getPaidMsfSelections() {
return paidMsfSelections;
}
public void setTotalPaidSelections (Integer totalPaidSelections) {
this.totalPaidSelections = totalPaidSelections;
}
public Integer getTotalPaidSelections () {
return totalPaidSelections;
}
public void setIfpStdSelections (Integer ifpStdSelections) {
this.ifpStdSelections = ifpStdSelections;
}
public Integer getIfpStdSelections () {
return ifpStdSelections;
}
public void setIfpModSelections (Integer ifpModSelections) {
this.ifpStdSelections = ifpModSelections;
}
public Integer getIfpModSelections () {
return ifpModSelections;
}
public void setIfpMsfSelections (Integer ifpMsfSelections) {
this.ifpMsfSelections = ifpMsfSelections;
}
public Integer getIfpMsfSelections () {
return ifpMsfSelections;
}
public void setTotalIfpSelections (Integer totalIfpSelections) {
this.totalIfpSelections = totalIfpSelections;
}
public Integer getTotalIfpSelections () {
return totalIfpSelections;
}
public void setTotalPatronSelections (Integer totalPatronSelections) {
this.totalPatronSelections = totalPatronSelections;
}
public Integer getTotalPatronSelections () {
return totalPatronSelections;
}
public void setPopularityPaidPlays (Integer popularityPaidPlays) {
this.popularityPaidPlays = popularityPaidPlays;
}
public Integer getPopularityPaidPlays () {
return popularityPaidPlays;
}
public void setRoyaltyPaidPlays (Integer royaltyPaidPlays) {
this.royaltyPaidPlays = royaltyPaidPlays;
}
public Integer getRoyaltyPaidPlays () {
return royaltyPaidPlays;
}
public void setDemoPlays(Integer demoPlays) {
this.demoPlays = demoPlays;
}
public Integer getDemoPlays() {
return demoPlays;
}
public void setIfpPlays (Integer ifpPlays) {
this.ifpPlays = ifpPlays;
}
public Integer getIfpPlays () {
return ifpPlays;
}
public void setPlaysErrors (Integer playsErrors) {
this.playsErrors = playsErrors;
}
public Integer getPlaysErrors () {
return playsErrors;
}
public void setPlaysOther (Integer playsOther) {
this.playsOther = playsOther;
}
public Integer getPlaysOther () {
return playsOther;
}
public void setPlaysRejected (Integer playsRejected) {
this.playsRejected = playsRejected;
}
public Integer getPlaysRejected () {
return playsRejected;
}
public void setNifpSelections (Integer nifpSelections) {
this.nifpSelections = nifpSelections;
}
public Integer getNifpSelections () {
return nifpSelections;
}
public void setNifpPlays (Integer nifpPlays) {
this.nifpPlays = nifpPlays;
}
public Integer getNifpPlays() {
return nifpPlays;
}
public void setAutoplaySelections(Integer autoplaySelections) {
this.autoplaySelections = autoplaySelections;
}
public Integer getAutoplaySelections() {
return autoplaySelections;
}
public void setAutoplayPlays(Integer autoplayPlays) {
this.autoplayPlays = autoplayPlays;
}
public Integer getAutoplayPlays() {
return autoplayPlays;
}
public void setBadMediaErrors(Integer badMediaErrors) {
this.badMediaErrors = badMediaErrors;
}
public Integer getBadMediaErrors() {
return badMediaErrors;
}
public void setFadedAutoplays(Integer fadedAutoplays) {
this.fadedAutoplays = fadedAutoplays;
}
public Integer getFadedAutoplays () {
return fadedAutoplays;
}
public void setClearedAutoplays(Integer clearedAutoplays) {
this.clearedAutoplays = clearedAutoplays;
}
public Integer getClearedAutoplays () {
return clearedAutoplays;
}
public void setRejectedAutoplays (Integer rejectedAutoplays) {
this.rejectedAutoplays = rejectedAutoplays;
}
public Integer getRejectedAutoplays() {
return rejectedAutoplays;
}
public void setModCost(Double modCost) {
this.modCost = modCost;
}
public Double getModCost() {
return modCost;
}
public void setModCharges(Double modCharges) {
this.modCharges = modCharges;
}
public Double getModCharges () {
return modCharges;
}
// Override equals and hashCode methods using Business Key Equalty
public boolean equals(Object other) {
if(this.equals(other)) return true;
if(!(other instanceof SongAggregateFactsDTO)) return false;
final SongAggregateFactsDTO songAggregateFact = (SongAggregateFactsDTO)other;
if( !songAggregateFact.getCompanyId().equals(getCompanyId() ) )
return false;
if( !songAggregateFact.getContractId().equals(getContractId() ) )
return false;
if( !songAggregateFact.getJukeboxId().equals(getJukeboxId() ) )
return false;
if( !songAggregateFact.getSongId().equals(getSongId() ) )
return false;
if( !songAggregateFact.getTimeId().equals(getTimeId() ) )
return false;
return true;
}
public int hashCode() {
int result;
result = getCompanyId().intValue() + getContractId().intValue() +
getJukeboxId().intValue() + getSongId().intValue() +
getTimeId().intValue();
return result;
}
}
<?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 default-cascade="none" default-access="property"
default-lazy="true" auto-import="true">
<class name="ami.server.dto.datamart.billing.TimeDimensionDTO"
table="billing_data_mart_db.TimeDimension" mutable="true"
abstract="false" polymorphism="implicit" dynamic-update="false"
dynamic-insert="false" select-before-update="false" optimistic-lock="version">
<id name="id" column="time_id" type="long"/>
<property name="eventDay" column="event_day" type="date"/>
<property name="eventMonth" column="event_month" type="date"/>
<property name="eventQtr" column="event_qtr" type="date"/>
<property name="eventYear" column="event_year" type="date"/>
<property name="serverDay" column="server_day" type="date"/>
<property name="serverMonth" column="server_month" type="date"/>
<property name="serverYear" column="server_year" type="date"/>
<property name="aggrDay" column="aggr_day" type="date"/>
<property name="aggrMonth" column="aggr_month" type="date"/>
<property name="aggrYear" column="aggr_year" type="date"/>
</class>
</hibernate-mapping>
public class TimeDimensionDTO implements Serializable
{
// Key Identifier – Natural Key
private Long id;
private Date eventDay;
private Date eventMonth;
private Date eventQtr;
private Date eventYear;
private Date serverDay;
private Date serverMonth;
private Date serverYear;
private Date aggrDay;
private Date aggrMonth;
private Date aggrYear;
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
public void setEventDay(Date eventDay) {
this.eventDay = eventDay;
}
public Date getEventDay() {
return eventDay;
}
public void setEventMonth(Date eventMonth) {
this.eventMonth = eventMonth;
}
public Date getEventMonth() {
return eventMonth;
}
public void setEventQtr(Date eventQtr) {
this.eventQtr = eventQtr;
}
public Date getEventQtr() {
return eventQtr;
}
public void setEventYear(Date eventYear) {
this.eventYear = eventYear;
}
public Date getEventYear() {
return eventYear;
}
public void setServerDay(Date serverDay) {
this.serverDay = serverDay;
}
public Date getServerDay() {
return serverDay;
}
public void setServerMonth(Date serverMonth) {
this.serverMonth = serverMonth;
}
public Date getServerMonth() {
return serverMonth;
}
public void setServerYear(Date serverYear) {
this.serverYear = serverYear;
}
public Date getServerYear() {
return serverYear;
}
public void setAggrDay(Date aggrDay) {
this.aggrDay = aggrDay;
}
public Date getAggrDay() {
return aggrDay;
}
public void setAggrMonth(Date aggrMonth) {
this.aggrMonth = aggrMonth;
}
public Date getAggrMonth() {
return aggrMonth;
}
public void setAggrYear(Date aggrYear) {
this.aggrYear = aggrYear;
}
public Date getAggrYear() {
return aggrYear;
}
}
<?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 default-cascade="none" default-access="property"
default-lazy="true" auto-import="true">
<class name="ami.server.dto.datamart.billing.SongDimensionDTO"
table="billing_data_mart_db.SongDimension" mutable="true"
abstract="false" polymorphism="implicit" dynamic-update="false"
dynamic-insert="false" select-before-update="false" optimistic-lock="version">
<id name="id" column="song_id"/>
<property name="songTitle" column="song_title"/>
<property name="songArtistName" column="song_artist_name"/>
<property name="songReleaseDate" column="song_release_date"/>
<property name="songIsrc" column="song_isrc"/>
</class>
</hibernate-mapping>
public class SongDimensionDTO implements Serializable
{
// Key Identifier – Natural Key
private Integer id;
private String songTitle;
private String songArtistName;
private Date songReleaseDate;
private String songIsrc;
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setSongTitle(String songTitle) {
this.songTitle = songTitle;
}
public String getSongTitle() {
return songTitle;
}
public void setSongArtistName(String songArtistName) {
this.songArtistName = songArtistName;
}
public String getSongArtistName() {
return songArtistName;
}
public void setSongReleaseDate(Date songReleaseDate) {
this.songReleaseDate = songReleaseDate;
}
public Date getSongReleaseDate() {
return songReleaseDate;
}
public void setSongIsrc(String songIsrc) {
this.songIsrc = songIsrc;
}
public String getSongIsrc() {
return songIsrc;
}
}
<?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 default-cascade="none" default-access="property"
default-lazy="true" auto-import="true">
<class name="ami.server.dto.datamart.billing.JukeboxDimensionDTO"
table="billing_data_mart_db.JukeboxDimension" mutable="true"
abstract="false" polymorphism="implicit" dynamic-update="false"
dynamic-insert="false" select-before-update="false" optimistic-lock="version">
<id name="id" column="jukebox_id"/>
<property name="jukeboxName" column="jukebox_name"/>
<property name="jukeboxSoftwareVersion" column="jukebox_software_version"/>
<property name="jukeboxCatalogVersion" column="jukebox_catalog_version"/>
<property name="jukeboxServTermStartDate"
column="jukebox_serv_term_start_date" type="date"/>
<property name="jukeboxModel" column="jukebox_model"/>
<property name="jukeboxStatus" column="jukebox_status"/>
</class>
</hibernate-mapping>
public class JukeboxDimensionDTO implements Serializable
{
// Key Identifier – Natural Key
private Integer id;
private String jukeboxName;
private String jukeboxSoftwareVersion;
private String jukeboxCatalogVersion;
private String jukeboxModel;
private String jukeboxStatus;
private Date jukeboxServTermStartDate;
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setJukeboxName(String jukeboxName) {
this.jukeboxName = jukeboxName;
}
public String getJukeboxName() {
return jukeboxName;
}
public void setJukeboxSoftwareVersion(String jukeboxSoftwareVersion) {
this.jukeboxSoftwareVersion = jukeboxSoftwareVersion;
}
public String getJukeboxSoftwareVersion() {
return jukeboxSoftwareVersion;
}
public void setJukeboxCatalogVersion(String jukeboxCatalogVersion) {
this.jukeboxCatalogVersion = jukeboxCatalogVersion;
}
public String getJukeboxCatalogVersion() {
return jukeboxCatalogVersion;
}
public void setJukeboxModel(String jukeboxModel) {
this.jukeboxModel = jukeboxModel;
}
public String getJukeboxModel() {
return jukeboxModel;
}
public void setJukeboxStatus(String jukeboxStatus) {
this.jukeboxStatus = jukeboxStatus;
}
public String getJukeboxStatus() {
return jukeboxStatus;
}
public void setJukeboxServTermStartDate(Date jukeboxServTermStartDate) {
this.jukeboxServTermStartDate = jukeboxServTermStartDate;
}
public Date getJukeboxServTermStartDate() {
return jukeboxServTermStartDate;
}
}
<?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 default-cascade="none" default-access="property"
default-lazy="true" auto-import="true">
<class name="ami.server.dto.datamart.billing.ContractDimensionDTO"
table="billing_data_mart_db.ContractDimension" mutable="true"
abstract="false" polymorphism="implicit" dynamic-update="false"
dynamic-insert="false" select-before-update="false" optimistic-lock="version">
<id name="id" column="contract_id"/>
<property name="contractName" column="contract_name"/>
<property name="contractStatus" column="contract_status"/>
<property name="contractOpenDate" column="contract_open_date"
type="date"/>
<property name="contractAutoRenewalFlag" column="contract_auto_renewal_flag"/>
<property name="contractOrigExpDate" column="contract_orig_exp_date"
type="date"/>
<property name="contractRevisedExpDate" column="contract_revised_exp_date"
type="date"/>
</class>
</hibernate-mapping>
public class ContractDimensionDTO implements Serializable
{
// Key Identifier – Natural Key
public Integer id;
private String contractName;
private String contractStatus;
private Date contractOpenDate;
private Boolean contractAutoRenewalFlag;
private Date contractOrigExpDate;
private Date contractRevisedExpDate;
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setContractName(String contractName) {
this.contractName = contractName;
}
public String getContractName() {
return contractName;
}
public void setContractStatus(String contractStatus) {
this.contractStatus = contractStatus;
}
public String getContractStatus() {
return contractStatus;
}
public void setContractOpenDate(Date contractOpenDate) {
this.contractOpenDate = contractOpenDate;
}
public Date getContractOpenDate() {
return contractOpenDate;
}
public void setContractAutoRenewalFlag(Boolean contractAutoRenewalFlag) {
this.contractAutoRenewalFlag = contractAutoRenewalFlag;
}
public Boolean getContractAutoRenewalFlag() {
return contractAutoRenewalFlag;
}
public void setContractOrigExpDate(Date contractOrigExpDate) {
this.contractOrigExpDate = contractOrigExpDate;
}
public Date getContractOrigExpDate () {
return contractOrigExpDate;
}
public void setContractRevisedExpDate(Date contractRevisedExpDate) {
this.contractRevisedExpDate = contractRevisedExpDate;
}
public Date getContractRevisedExpDate () {
return contractRevisedExpDate;
}
}
<?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 default-cascade="none" default-access="property"
default-lazy="true" auto-import="true">
<class name="ami.server.dto.datamart.billing.CompanyDimensionDTO"
table="billing_data_mart_db.CompanyDimension" mutable="true"
abstract="false" polymorphism="implicit" dynamic-update="false"
dynamic-insert="false" select-before-update="false" optimistic-lock="version">
<id name="id" column="company_id"/>
<property name="companyName" column="company_name"/>
<property name="companyType" column="company_type"/>
<property name="companyCity" column="company_city"/>
<property name="companyState" column="company_state"/>
<property name="companyZip" column="company_zip"/>
<property name="companyCountry" column="company_country"/>
</class>
</hibernate-mapping>
public class CompanyDimensionDTO implements Serializable
{
// Key Identifier – Natural Key
private Integer id;
private String companyName;
private String companyType;
private String companyCity;
private String companyState;
private String companyZip;
private String companyCountry;
public void setId(Integer id) {
this.id = id;
}
public Integer getId() {
return id;
}
public void setCompanyName (String companyName) {
this.companyName = companyName;
}
public String getCompanyName () {
return companyName;
}
public void setCompanyType (String companyType) {
this.companyType = companyType;
}
public String getCompanyType () {
return companyType;
}
public void setCompanyCity (String companyCity) {
this.companyCity = companyCity;
}
public String getCompanyCity () {
return companyCity;
}
public void setCompanyState (String companyState) {
this.companyState = companyState;
}
public String getCompanyState () {
return companyState;
}
public void setCompanyZip (String companyZip) {
this.companyZip = companyZip;
}
public String getCompanyZip () {
return companyZip;
}
public void setCompanyCountry (String companyCountry) {
this.companyCountry = companyCountry;
}
public String getCompanyCountry () {
return companyCountry;
}
}
// Persistence Class/Code
SongAggregateFactDTO songAggr = new SongAggregateFactDTO
songAggr.setJukeboxId(new Integer(1));
songAggr.setCompanyId(new Integer(1));
songAggr.setContractId(new Integer(1));
songAggr.setSongId(new Integer(1));
songAggr.setTimeId(new Long(1));
session.save(songAggr);