gpt4 book ai didi

java - 甲骨文数据库 : ORA-01461: can bind a LONG value only for insert into a LONG column

转载 作者:行者123 更新时间:2023-11-29 04:22:00 25 4
gpt4 key购买 nike

我在 Oracle 数据库中使用 Long 作为我的 ID。我看到:'ORA-01461: can bind a LONG value only for insert into a LONG column',当我尝试通过 Spring Data 的“保存”功能进行保存时。

我不明白这是什么问题。我读过我应该使用 CLOB 而不是 Long,但我不明白 CLOB 是什么以及如何使用它。或者可能是其他问题。我的代码片段:

型号:

@Entity
public class Picture {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PICT_SEQ")
@SequenceGenerator(sequenceName = "picture_seq", allocationSize = 5, name = "PICT_SEQ")
private Long id;

private String name;

private String author;

@Column(name="CREATED_DATE")
@Convert(converter = LocalDateAttributeConverter.class)
private LocalDate createdDate;

private String content;

// getXXX, setXXX...
}

存储库:

public interface PictureRepository extends CrudRepository<Picture,Long>{

public List<Picture> findAll();

public void delete(Picture pic);

@SuppressWarnings("unchecked")
public Picture save(Picture pic);
}

服务层:

@Service
public class PictureService {

@Autowired
private PictureRepository pictureRepo;

public Picture savePicture(Picture p) {
return pictureRepo.save(p);
}

//...
}

Controller 片段:

@RestController
public class PictureController {

@Autowired
private PictureService pictureService;

@PostMapping(value="/send")
public ResponseEntity<?> sendPictureToDatabase(@RequestBody Picture picture) throws IOException {

pictureService.savePicture(picture); //here is the problem
AjaxResponseBody result = new AjaxResponseBody();
result.setMsg("success");
result.setResult(pictureService.getAllPictures());
return ResponseEntity.ok(result);
}
}

最佳答案

I used Long as my id in Oracle database.

你不必。
Oracle LONG Datatype 实际上不是为了表示数字类型而设计的:

Columns defined as LONG can store variable-length character data containing up to 2 gigabytes of information. LONG data is text data that is to be appropriately converted when moving among different systems.

相反,这个 id :

@Id
private Long id;

应映射到 oracle 中的 NUMBER 类型。

您可以指定 NUMBER(19) 来表示 Java Long 范围值,其中最大值包含 19 位(9223372036854775807).

关于java - 甲骨文数据库 : ORA-01461: can bind a LONG value only for insert into a LONG column,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48531873/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com