I have an entity Job as below.
@Entity
@Getter
@Setter
@NoArgsConstructor
@Immutable
@ToString
@JsonIgnoreProperties({"hibernateLazyInitializer", "handler"})
@Table(name = "JOB")
public class Job extends BaseEntity implements IEntity, IDto {
@Id
@Column(name = "JOB_ID", unique = true, nullable = false)
private Long id;
@Column(name = "PRINT_JOB_ID", length = 30)
private String printJobId;
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "PRINT_JOB_ID", nullable = false, insertable = false, updatable = false)
private Set<PrintFile> printFileInfos = new HashSet<PrintFile>();
}
I also have another entity PrintFile.
@Entity
@Getter
@Setter
@NoArgsConstructor
@Immutable
@Table(name = "PRINT_FILE")
public class PrintFile implements Serializable {
@Id
@Column(name = "FILE_ID", unique = true, nullable = false, length = 50)
private String fileId;
@Column(name = "PRINT_JOB_ID", nullable = false, length = 30)
private String printJobId;
}
Here are my tables.
Job
JOB_ID NOT NULL NUMBER
PRINT_JOB_ID VARCHAR2(30)
Print_File
PRINT_JOB_ID NOT NULL VARCHAR2(30)
FILE_ID NOT NULL VARCHAR2(50)
When trying fetch Job data using Sprint boot rest API, I'm getting java.sql.SQLSyntaxErrorException: ORA-01722: invalid number
error. All the dataype mapping seems to be correct, what else could have gone wrong ?
EDIT:
The Job entity fetches without any issues when I get rid of the join. i.e, the entire declaration of printFileInfos in Job entity. This makes me think the issue is either with the join or in PrintFile entity.
I would recommend you to try below given code. After adding referencedColumnName attribute, it worked for me.
@OneToMany(fetch = FetchType.LAZY)
@JoinColumn(name = "PRINT_JOB_ID", referencedColumnName = "PRINT_JOB_ID", nullable = false, insertable = false, updatable = false)
private Set<PrintFile> printFileInfos = new HashSet<PrintFile>();