Hello everyone, I have seen several of these topics, but I have not yet found a good enough explanation of what it is and why is it thrown.
I'm doing a basic JPQL to get a list, the query is as follows
Code:
entityManager.createQuery("SELECT invoice FROM Invoice invoice", Invoice.class).getResultList();
On that query, I get the following exception thrown:
Code:
Caused by: org.hibernate.AssertionFailure: null identifier
at org.hibernate.engine.spi.EntityKey.<init>(EntityKey.java:69) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.internal.AbstractSessionImpl.generateEntityKey(AbstractSessionImpl.java:240) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.extractKeysFromResultSet(Loader.java:722) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:635) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.doQuery(Loader.java:856) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.Loader.loadEntity(Loader.java:2058) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:82) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.loader.entity.EntityLoader.loadByUniqueKey(EntityLoader.java:161) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.persister.entity.AbstractEntityPersister.loadByUniqueKey(AbstractEntityPersister.java:2202) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:661) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
at org.hibernate.type.EntityType.resolve(EntityType.java:441) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
...
The entity I'm trying to get from the database is a really big one, here it is
Code:
//package and imports
@Entity
@Table(name = "INVOICE", schema = "SCHEMA")
@IdClass(InvoicePK.class)
public class Invoice implements Serializable{
private static final long serialVersionUID = 1173693645748731657L;
@Id
@SequenceGenerator(name = "SEQ_INVOICEID", sequenceName = "SEQ_INVOICEID", initialValue = 1, allocationSize = 1)
@GeneratedValue(generator = "SEQ_INVOICEID", strategy = GenerationType.SEQUENCE)
@Column(name = "invoiceId", nullable = false, precision = 22, scale = 0)
private Long invoiceId;
@Id
@Column(name = "databaseId", nullable = false, precision = 22, scale = 0)
private Long databaseId;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "center")
private Center center;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "referenceInvoiceId", referencedColumnName = "invoiceId"),
@JoinColumn(name = "referenceInvoiceDatabaseId", referencedColumnName = "databaseId") })
private Invoice referenceInvoice;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "companyUnitId", referencedColumnName = "companyUnitId"),
@JoinColumn(name = "companyDatabaseId", referencedColumnName = "companyDatabaseId"),
@JoinColumn(name = "personId", referencedColumnName = "personId") })
private Company company;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "operation", nullable = false)
private Operation operation;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "storeId", referencedColumnName = "storeId"),
@JoinColumn(name = "storeDatabaseId", referencedColumnName = "storeDatabaseId") })
private Store store;
@Temporal(TemporalType.DATE)
@Column(name = "entryDate", nullable = false, length = 7)
@ViewSearch(name = "Data Entrada")
private Date entryDate;
@Column(name = "documentNumber", nullable = false, precision = 9, scale = 9)
@ViewSearch(name = "Número")
private Long documentNumber;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "fileId", referencedColumnName = "fileId"),
@JoinColumn(name = "fileDatabaseId", referencedColumnName = "fileDatabaseId") })
private InvoiceFile file;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "issuerId", referencedColumnName = "issuerId"),
@JoinColumn(name = "issuerDatabaseId", referencedColumnName = "issuerDatabaseId") })
private Person issuer;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumns({
@JoinColumn(name = "carrierId", referencedColumnName = "carrierId"),
@JoinColumn(name = "carrierDatabaseId", referencedColumnName = "carrierDatabaseId") })
private Person carrier;
@Column(name = "stateCode", precision = 2, scale = 0)
private Integer stateCode;
@Column(name = "accessKey", precision = 8, scale = 0)
private Integer accessKey;
@Column(name = "operationDescription", length = 60)
private String operationDescription;
@Enumerated
@Column(name = "paymentForm", precision = 1, scale = 0)
private PaymentForm paymentForm;
@Column(name = "taxDocumentModel", length = 2)
private String taxDocumentModel;
@Column(name = "taxDocumentGroup", precision = 3, scale = 0)
@ViewSearch(name = "Série")
private Integer taxDocumentGroup;
@Temporal(TemporalType.DATE)
@Column(name = "documentEmssionDate", nullable = false, length = 7)
private Date documentEmssionDate;
@Temporal(TemporalType.DATE)
@Column(name = "merchandiseShippingDate", nullable = false, length = 7)
private Date merchandiseShippingDate;
@Temporal(TemporalType.DATE)
@Column(name = "merchandiseShippingHour", nullable = false, length = 7)
private Date merchandiseShippingHour;
@Enumerated
@Column(name = "operationType", precision = 1, scale = 0)
private OperationType operationType;
@Enumerated
@Column(name = "printingType", precision = 22, scale = 0)
private PrintingType printingType;
@Enumerated
@Column(name = "emissionType", precision = 1, scale = 0)
private EmissionType emissionType;
@Enumerated
@Column(name = "emissionGoal", precision = 1, scale = 0)
private EmissionGoal emissionGoal;
@Enumerated
@Column(name = "emissionProcess", precision = 1, scale = 0)
private EmissionProcess emissionProcess;
@Enumerated
@Column(name = "tributarySystemCode", precision = 22, scale = 0)
private TributarySystemCode tributarySystemCode;
@Column(name = "invoiceStatus", precision = 22, scale = 0)
private InvoiceStatus invoiceStatus;
@OneToOne(mappedBy = "accountPayableSource", fetch = FetchType.LAZY)
private AccountPayableSource accountPayableSource;
@OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE, CascadeType.REMOVE}, fetch = FetchType.LAZY, mappedBy = "invoice")
private List<InvoiceItems> items;
@OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE, CascadeType.REMOVE}, fetch = FetchType.LAZY, mappedBy = "invoice")
private List<InvoiceVolumes> volumes;
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "InvoicePurchaseOrder", schema = "SCHEMA", joinColumns = {
@JoinColumn(name = "invoiceId", referencedColumnName = "invoiceId", nullable = false, updatable = false),
@JoinColumn(name = "invoiceDataBaseId", referencedColumnName = "invoiceDataBaseId", nullable = false, updatable = false) }, inverseJoinColumns = {
@JoinColumn(name = "purchaseOrderId", referencedColumnName = "purchaseOrderId", nullable = false, updatable = false, insertable = false),
@JoinColumn(name = "purchaseOrderDatabaseId", referencedColumnName = "purchaseOrderDatabaseId", nullable = false, updatable = false, insertable = false)})
private List<PurchaseOrder> listPedidosCompra;
@OneToMany(cascade = {CascadeType.PERSIST,CascadeType.MERGE, CascadeType.REMOVE}, fetch = FetchType.LAZY, mappedBy = "invoice")
private List<InvoiceTrailer> trailers;
public Invoice(){
super();
}
}
Some attributes and the methods equals() and hashCode() were omitted, but all the attributes that have relationships are there.
I would like to know if there is any werid mapping on my entity, or if it really is a hibernate bug.
because the following line is also thrown in the stacktrace:
Code:
HHH000099: an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session): org.hibernate.AssertionFailure: null identifier
PS: I set all mappings to FetchType.LAZY just to see if I could get the error to stop being thrown, but no luck.
Any ideas?
Thanks!
Other PS: this is my first post here, so I'm sorry if I failed to follow any of the rules. If so, please let me know so I can edit my post.