我的项目中有一个特例,我需要在oracle db中执行本机插入。但是我有一个问题,当插入值(在我的例子中的列b中)为null时 - 发生此异常:
Caused by: java.sql.SQLSyntaxErrorException: ORA-00932: inconsistent datatypes: expected NUMBER got BINARY
我认为当值为null时,hibernate无法正确设置inserted数据类型。如何使用本机插入插入空值?
我的JPA存储库:
public interface MyRepository extends JpaRepository<MyTable, MyTablePk>, QueryDslPredicateExecutor<MyTable> {
@Modifying
@Transactional
@Query(value = "INSERT INTO DATA.MY_TABLE (a, b, c, d, e) "
+ "VALUES(?1, ?2, ?3, ?4, CURRENT_TIMESTAMP)", nativeQuery = true)
void insertData(String a,
BigDecimal b,
Integer c,
Integer d);
}
Db表:
create table DATA.my_table (
a varchar2(10 char) not null,
b number(10,8),
c number(2,0) not null,
d number(4,0) not null,
e timestamp,
constraint my_table_pk primary key (a, c, d)
);
实体:
@Entity
@Table(schema = "DATA")
public class MyTable implements Serializable {
private static final long serialVersionUID = -6802433470917268375L;
@Id
private MyTablePk id;
@Column(precision=10, scale=8)
private BigDecimal b;
@NotNull
@Column(nullable = false)
@Temporal(TemporalType.TIMESTAMP)
private Date e;
...
环境:Java 8,Spring 4.1.4,Hibernate 4.3.7.Final,Oracle 12c。
谢谢