I need help with JPA/Hibernate. I have added two new columns to a table:
CREATE TABLE DMU_TRACKED_SERIAL (
TSO_SPLIT_NUMBER varchar(6) PRIMARY KEY NOT NULL,
CREATED_BY varchar(100) DEFAULT 'APDMUIF',
CREATED_TS timestamp DEFAULT CURRENT TIMESTAMP NOT NULL, -- new column added
MODIFIED char(1) DEFAULT 'F' NOT NULL -- new column added
)
The entity class is TrackedSerial (attached). I’m using what I believe to be the correct annotations for the new getters, based on getters for the same type in other entity classes in the project:
@Column(name = "CREATED_TS", nullable = false, length = 26,
updatable = false, columnDefinition="TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
@Temporal(TemporalType.TIMESTAMP)
public Date getCreatedTs() {
return createdTs;
}
@Column(name = "MODIFIED", nullable = false, columnDefinition = "char(1)")
@Convert(converter = BooleanCharacter.class)
public Boolean getModified() {
return modified;
}
Insertions seem to work fine, but although this query returns with no error:
@NamedNativeQuery(name = "getUnimportedTrackedSerials",
query = "SELECT * FROM CADBOM.DMU_TRACKED_SERIAL WHERE modified = 'F'")
A few lines after the call that uses this query on line 73, an exception is thrown at line 79 (indicated by arrow)
java.lang.ClassCastException: [Ljava.lang.Object; incompatible with com.daimler.dmu.jpa.entities.dmu.TrackedSerial at com.daimler.dmu.batch.jobs.PerSerialItemFetcher.execute(PerSerialItemFetcher.java:79)
Now this is very odd, because the variable t is the same class as the members of trackedSerials. There should be no need to cast, let alone throw an exception. I suspect Hibernate is doing some jiggery-pokery with reflection, creating objects that look like TrackedSerial but aren't exactly. Does anyone know what's going on here?
