HHH-12225 - NullPointerException When Using type(<Class>) in HQL

This commit is contained in:
randymay 2017-11-03 16:22:22 -04:00 committed by Vlad Mihalcea
parent f5c1b006d6
commit 5a9a1c5a87
8 changed files with 892 additions and 0 deletions

View File

@ -300,6 +300,10 @@ public class PojoEntityTuplizer extends AbstractEntityTuplizer {
@Override
public String determineConcreteSubclassEntityName(Object entityInstance, SessionFactoryImplementor factory) {
if ( entityInstance == null ) {
return getEntityName();
}
final Class concreteEntityClass = entityInstance.getClass();
if ( concreteEntityClass == getMappedClass() ) {
return getEntityName();

View File

@ -0,0 +1,380 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.query.hhh12225;
import java.util.Date;
public class Contract {
public static final long serialVersionUID = 1L;
private transient boolean overrideEnabled = false;
private Long id;
private Date creationDate;
private Date modifiedDate;
private Integer version;
private boolean rendered;
private boolean fixedPrice;
private boolean renewable;
private boolean emailDistributionRequested;
private Integer financedTerm;
private Integer financedAmortizationPeriod;
private Integer coverageTerm;
private Long trackingId;
private Long timeToCreate = 0L;
private Long templateId;
private Double productPrice = 0.0;
private Double totalCost = 0.0;
private Double paymentAmount = 0.0;
private Double price = 0.0;
private Double financedAmount = 0.0;
private Double coverageBenefit = 0.0;
private Double coveragePaymentRelief = 0.0;
private Double coverageFinanced = 0.0;
private Double previousDeficiency = 0.0;
private Double coverageDeficiency = 0.0;
private Double interestRate = 0.0;
private String externalId;
private String paymentMethod;
private String paymentFrequency;
private String accountNumber;
private String origin;
private String premiumFinanced;
private String locale;
private Date effectiveDate;
private Date terminationDate;
private Date renewalDate;
private Date expiryDate;
private Contract _endorsed;
public Contract() {
}
public boolean isNew() {
return this.id == null;
}
public Long getId() {
return this.id;
}
public void setId(Long id) {
this.id = id;
}
public Date getEffectiveDate() {
return this.effectiveDate;
}
public void setEffectiveDate(Date effectiveDate) {
this.effectiveDate = effectiveDate;
}
public Date getTerminationDate() {
return this.terminationDate;
}
public void setTerminationDate(Date terminationDate) {
this.terminationDate = terminationDate;
}
public String getExternalId() {
return this.externalId;
}
public void setExternalId(String externalId) {
this.externalId = externalId;
}
public Long getTemplateId() {
return this.templateId;
}
public void setTemplateId(Long templateId) {
this.templateId = templateId;
}
public Double getPrice() {
return this.price;
}
public void setPrice(Double price) {
this.price = price;
}
public Integer getVersion() {
return this.version;
}
public void setVersion(Integer version) {
this.version = version;
}
public String toString() {
return String.valueOf( id );
}
public Integer getFinancedTerm() {
return financedTerm;
}
public void setFinancedTerm(Integer integer) {
financedTerm = integer;
}
public Long getTrackingId() {
return trackingId;
}
public void setTrackingId(Long id) {
trackingId = id;
}
public Date getCreationDate() {
return creationDate;
}
public Date getModifiedDate() {
return modifiedDate;
}
public void setCreationDate(Date date) {
creationDate = date;
}
public void setModifiedDate(Date date) {
modifiedDate = date;
}
public Integer getCoverageTerm() {
return coverageTerm;
}
public void setCoverageTerm(Integer integer) {
coverageTerm = integer;
}
public String getAccountNumber() {
return accountNumber;
}
public Double getFinancedAmount() {
return financedAmount;
}
public void setAccountNumber(String string) {
accountNumber = string;
}
public void setFinancedAmount(Double double1) {
financedAmount = double1;
}
public Double getCoverageDeficiency() {
return coverageDeficiency;
}
public Double getPreviousDeficiency() {
return previousDeficiency;
}
public void setCoverageDeficiency(Double double1) {
coverageDeficiency = double1;
}
public void setPreviousDeficiency(Double double1) {
previousDeficiency = double1;
}
public Double getTotalCost() {
return totalCost;
}
public void setTotalCost(Double double1) {
totalCost = double1;
}
public Double getInterestRate() {
return interestRate;
}
public void setInterestRate(Double double1) {
interestRate = double1;
}
public boolean isRendered() {
return rendered;
}
public void setRendered(boolean b) {
rendered = b;
}
public Double getCoverageBenefit() {
return coverageBenefit;
}
public Double getCoverageFinanced() {
return coverageFinanced;
}
public void setCoverageBenefit(Double double1) {
coverageBenefit = double1;
}
public void setCoverageFinanced(Double double1) {
coverageFinanced = double1;
}
public boolean isFixedPrice() {
return fixedPrice;
}
public void setFixedPrice(boolean fixedPrice) {
this.fixedPrice = fixedPrice;
}
public Double getProductPrice() {
return productPrice;
}
public void setProductPrice(Double productPrice) {
this.productPrice = productPrice;
}
public Long getTimeToCreate() {
return timeToCreate;
}
public void setTimeToCreate(Long timeToCreate) {
this.timeToCreate = timeToCreate;
}
public String getPaymentMethod() {
return paymentMethod;
}
public void setPaymentMethod(String paymentMethod) {
this.paymentMethod = paymentMethod;
}
public String getPaymentFrequency() {
return paymentFrequency;
}
public void setPaymentFrequency(String paymentFrequency) {
this.paymentFrequency = paymentFrequency;
}
public Double getPaymentAmount() {
return paymentAmount;
}
public void setPaymentAmount(Double paymentAmount) {
this.paymentAmount = paymentAmount;
}
public Double getCoveragePaymentRelief() {
return coveragePaymentRelief;
}
public void setCoveragePaymentRelief(Double coveragePaymentRelief) {
this.coveragePaymentRelief = coveragePaymentRelief;
}
public Date getExpiryDate() {
return expiryDate;
}
public void setExpiryDate(Date coverageTerminationDate) {
this.expiryDate = coverageTerminationDate;
}
public String getPremiumFinanced() {
return premiumFinanced;
}
public void setPremiumFinanced(String premiumFinanced) {
this.premiumFinanced = premiumFinanced;
}
public Integer getFinancedAmortizationPeriod() {
return financedAmortizationPeriod;
}
public void setFinancedAmortizationPeriod(Integer financedAmortizationPeriod) {
this.financedAmortizationPeriod = financedAmortizationPeriod;
}
public Date getRenewalDate() {
return renewalDate;
}
public void setRenewalDate(Date refinancingDate) {
this.renewalDate = refinancingDate;
}
public boolean isRenewable() {
return renewable;
}
public void setRenewable(boolean renewable) {
this.renewable = renewable;
}
public boolean isEmailDistributionRequested() {
return emailDistributionRequested;
}
public void setEmailDistributionRequested(boolean emailDistributionRequested) {
this.emailDistributionRequested = emailDistributionRequested;
}
public String getOrigin() {
return origin;
}
public void setOrigin(String origin) {
this.origin = origin;
}
public Contract getEndorsed() {
return _endorsed;
}
public void setEndorsed(Contract endorsed) {
_endorsed = endorsed;
}
public boolean isEndorsement() {
return _endorsed != null;
}
public String getLocale() {
return locale;
}
public void setLocale(String locale) {
this.locale = locale;
}
public boolean isOverrideEnabled() {
return overrideEnabled;
}
public void setOverrideEnabled(boolean overrideEnabled) {
this.overrideEnabled = overrideEnabled;
}
}

View File

@ -0,0 +1,77 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.query.hhh12225;
import java.util.List;
import org.hibernate.testing.TestForIssue;
import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
import org.junit.Test;
import static org.hibernate.testing.transaction.TransactionUtil.doInHibernate;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@TestForIssue(jiraKey = "HHH-12225")
public class HQLTypeTest extends BaseCoreFunctionalTestCase {
@Override
protected Class[] getAnnotatedClasses() {
return new Class[] {
};
}
@Override
protected String[] getMappings() {
return new String[] {
"Contract.hbm.xml",
"Vehicle.hbm.xml"
};
}
@Override
protected String getBaseForMappings() {
return "org/hibernate/query/hhh12225/";
}
@Test
public void test() throws Exception {
doInHibernate( this::sessionFactory, session -> {
for ( long i = 0; i < 10; i++ ) {
VehicleContract vehicleContract = new VehicleContract();
Vehicle vehicle1 = new Vehicle();
vehicle1.setContract( vehicleContract );
VehicleTrackContract vehicleTrackContract = new VehicleTrackContract();
Vehicle vehicle2 = new Vehicle();
vehicle2.setContract( vehicleTrackContract );
session.save( vehicle1 );
session.save( vehicle2 );
session.save( vehicleContract );
session.save( vehicleTrackContract );
}
List workingResults = session.createQuery(
"select rootAlias.id from Contract as rootAlias where rootAlias.id = :id" )
.setParameter( "id", 1L )
.getResultList();
assertFalse( workingResults.isEmpty() );
Long workingId = (Long) workingResults.get( 0 );
assertEquals( Long.valueOf( 1 ), workingId );
List failingResults = session.createQuery(
"select rootAlias.id, type(rootAlias) from Contract as rootAlias where rootAlias.id = :id" )
.setParameter( "id", 1L )
.getResultList();
assertFalse( failingResults.isEmpty() );
Long failingId = (Long) ( (Object[]) failingResults.get( 0 ) )[0];
assertEquals( Long.valueOf( 1 ), failingId );
} );
}
}

View File

@ -0,0 +1,285 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.query.hhh12225;
import java.util.Date;
public class Vehicle {
public static final long serialVersionUID = 1L;
public static final String STATUS_NEW = "new";
public static final String STATUS_USED = "used";
private Long _id;
private Integer _version;
private Date _creationDate;
private Date _modifiedDate;
private String _vin;
private boolean _dirty;
private Double _msrp;
private Double _residualValue;
private Double _invoicePrice;
private Integer _decodeAttempts;
private String _model;
private String _modelDetail;
private Integer _year;
private Integer _odometer;
private String _license;
private String _status;
private String _vehicleType;
private String _classification;
private String _country;
private String _engineType;
private String _assemblyPlant;
private Integer _sequenceNumber;
private String _bodyType;
private String _fuelType;
private String _driveLineType;
private VehicleContract _contract;
/**
* default constructor
*/
public Vehicle() {
_decodeAttempts = 0;
}
public Long getId() {
return _id;
}
public void setId(Long id) {
_id = id;
}
public Integer getVersion() {
return _version;
}
public void setVersion(Integer version) {
_version = version;
}
public Date getCreationDate() {
return _creationDate;
}
public void setCreationDate(Date creationDate) {
_creationDate = creationDate;
}
public Date getModifiedDate() {
return _modifiedDate;
}
public void setModifiedDate(Date modifiedDate) {
_modifiedDate = modifiedDate;
}
public String getVin() {
return _vin;
}
public void setVin(String vin) {
_vin = vin;
}
public boolean isDirty() {
return _dirty;
}
public void setDirty(boolean dirty) {
_dirty = dirty;
}
public Double getMsrp() {
return _msrp;
}
public void setMsrp(Double msrp) {
_msrp = msrp;
}
public Integer getDecodeAttempts() {
return _decodeAttempts;
}
public void setDecodeAttempts(Integer decodeAttempts) {
_decodeAttempts = decodeAttempts;
}
public String getModel() {
return _model;
}
public void setModel(String model) {
_model = model;
}
public String getModelDetail() {
return _modelDetail;
}
public void setModelDetail(String modelDetail) {
_modelDetail = modelDetail;
}
public Integer getYear() {
return _year;
}
public void setYear(Integer year) {
_year = year;
}
public Integer getOdometer() {
return _odometer;
}
public void setOdometer(Integer odometer) {
_odometer = odometer;
}
public String getLicense() {
return _license;
}
public void setLicense(String license) {
_license = license;
}
public String getStatus() {
return _status;
}
public void setStatus(String status) {
_status = status;
}
public String getVehicleType() {
return _vehicleType;
}
public void setVehicleType(String vehicleType) {
_vehicleType = vehicleType;
}
public String getCountry() {
return _country;
}
public void setCountry(String country) {
_country = country;
}
public String getEngineType() {
return _engineType;
}
public void setEngineType(String engineType) {
_engineType = engineType;
}
public String getAssemblyPlant() {
return _assemblyPlant;
}
public void setAssemblyPlant(String assemblyPlant) {
_assemblyPlant = assemblyPlant;
}
public Integer getSequenceNumber() {
return _sequenceNumber;
}
public void setSequenceNumber(Integer sequenceNumber) {
_sequenceNumber = sequenceNumber;
}
public String getBodyType() {
return _bodyType;
}
public void setBodyType(String bodyType) {
_bodyType = bodyType;
}
public String getFuelType() {
return _fuelType;
}
public void setFuelType(String fuelType) {
_fuelType = fuelType;
}
public String getDriveLineType() {
return _driveLineType;
}
public void setDriveLineType(String driveLineType) {
_driveLineType = driveLineType;
}
public VehicleContract getContract() {
return _contract;
}
public void setContract(VehicleContract contract) {
_contract = contract;
}
public String getClassification() {
return _classification;
}
public void setClassification(String classification) {
_classification = classification;
}
public Double getResidualValue() {
return _residualValue;
}
public void setResidualValue(Double residualValue) {
_residualValue = residualValue;
}
public Double getInvoicePrice() {
return _invoicePrice;
}
public void setInvoicePrice(Double invoicePrice) {
_invoicePrice = invoicePrice;
}
public String toString() {
return String.valueOf( _vin );
}
public boolean equals(Object obj) {
if ( obj == null ) {
return false;
}
if ( obj == this ) {
return true;
}
if ( obj instanceof Vehicle ) {
//TODO - needs to include contract equals comparision
return _vin.equals( ( (Vehicle) obj ).getVin() );
}
return false;
}
public int hashCode() {
return _vin.hashCode();
}
}

View File

@ -0,0 +1,39 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.query.hhh12225;
import java.util.ArrayList;
import java.util.List;
public class VehicleContract extends Contract {
public static final long serialVersionUID = 1L;
private List<Vehicle> vehicles;
public VehicleContract() {
vehicles = new ArrayList<Vehicle>();
}
public void addVehicle(Vehicle vehicle) {
vehicle.setContract( this );
getVehicles().add( vehicle );
}
public String toString() {
return String.valueOf( getId() );
}
public List<Vehicle> getVehicles() {
return vehicles;
}
public void setVehicles(List<Vehicle> vehicles) {
this.vehicles = vehicles;
}
}

View File

@ -0,0 +1,30 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.query.hhh12225;
public class VehicleTrackContract extends VehicleContract {
public static final long serialVersionUID = 1L;
private String _etchingId = null;
private boolean _original = false;
public String getEtchingId() {
return _etchingId;
}
public void setEtchingId(String etchingId) {
_etchingId = etchingId;
}
public boolean isOriginal() {
return _original;
}
public void setOriginal(boolean original) {
_original = original;
}
}

View File

@ -0,0 +1,46 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.query.hhh12225">
<class name="Contract" table="contract" >
<meta attribute="class-description">
Walkaway Debt Cancellation Contract
</meta>
<id name="id" type="long" unsaved-value="null">
<!-- meta attribute="scope-set">protected</meta -->
<generator class="native"/>
</id>
<version name="version" unsaved-value="null" type="java.lang.Integer">
<!-- meta attribute="scope-set">protected</meta -->
</version>
<property name="creationDate" type="timestamp" column="creation_date" insert="false" update="false" generated="always" />
<property name="modifiedDate" type="timestamp" column="modified_date" insert="false" update="false" generated="always" />
<property name="effectiveDate" type="timestamp">
<column name="effective_date" index="idx_contract_effective_date" />
</property>
<property name="terminationDate" type="timestamp" column="termination_date" />
<property name="renewalDate" type="timestamp" column="renewal_date" />
<property name="expiryDate" type="timestamp" column="expiry_date" />
<!--<many-to-one name="endorsed" claorg.hibernate.query.hhh122252225.Contract" column="endorsed_contract_id" fetch="select" lazy="false" />-->
<joined-subclass name="VehicleContract" table="contract_vehicle" >
<key column="contract_id" />
<bag name="vehicles" cascade="all" inverse="true" fetch="select" lazy="false">
<meta attribute="validate:min-size">1</meta>
<meta attribute="validate:max-size">1</meta>
<key column="contract_id" />
<one-to-many class="org.hibernate.query.hhh12225.Vehicle" />
</bag>
<joined-subclass name="VehicleTrackContract" table="contract_vehicle_track">
<key column="contract_id" />
<property name="etchingId" type="string" column="etching_id" length="64" />
<property name="original" type="boolean" column="original" />
</joined-subclass>
</joined-subclass>
</class>
</hibernate-mapping>

View File

@ -0,0 +1,31 @@
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="org.hibernate.query.hhh12225">
<class name="Vehicle">
<meta attribute="class-description">
Walkaway Vehicle Object
</meta>
<id name="id" type="long" unsaved-value="null">
<generator class="native"/>
</id>
<version name="version" unsaved-value="null" type="java.lang.Integer">
<meta attribute="scope-set">protected</meta>
</version>
<property name="creationDate" type="timestamp" column="creation_date" insert="false" update="false" generated="always" />
<property name="modifiedDate" type="timestamp" column="modified_date" insert="false" update="false" generated="always" />
<property name="dirty" type="boolean" />
<property name="decodeAttempts" type="java.lang.Integer" column="decode_attempts"/>
<property name="year" type="java.lang.Integer" column="year" />
<property name="msrp" type="java.lang.Double" column="msrp_value" />
<property name="residualValue" type="java.lang.Double" column="residual_value" />
<property name="invoicePrice" type="java.lang.Double" column="invoice_price" />
<property name="odometer" type="java.lang.Integer" />
<property name="sequenceNumber" type="java.lang.Integer" column="seq_number" />
</class>
</hibernate-mapping>