ORA-01722:使用Hibernate时号码无效

时间:2019-01-17 20:57:25

标签: java spring hibernate entity

我有一个实体Job,如下所示。

Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

// check if there is somebody authenticated
if (!(authentication instanceof AnonymousAuthenticationToken)) {
    String currentUserName = authentication.getName();
    // do something the the username, maybe get more information from a database
}

我还有另一个实体PrintFile。

@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>();
}

这是我的桌子。

@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;
}

尝试使用Sprint引导休息API提取作业数据时,出现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) 错误。所有的数据类型映射似乎都是正确的,还有什么可能出错了?

编辑:

摆脱连接后,Job实体将毫无问题地获取。即Job实体中printFileInfos的整个声明。这使我认为问题出在联接或PrintFile实体中。

1 个答案:

答案 0 :(得分:1)

我建议您尝试使用以下给定的代码。添加referencedColumnName属性后,它对我有用。

   @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>();