我正在使用Spring,我的课程使用@Transactional
注释。
我正在使用SimpleJdbcInsert
,但我收到以下警告:
TableMetaDataProvider: - 无法找到表元数据 'data.data_insert' - 必须提供列名
我有三张桌子,所有三张桌子都有这样的关系:
table1
的 主键是table 2
中的外键和{{1}中的主键是table 2
中的外键。
显示表1插入代码:
table 3
错误记录:
java.sql.Timestamp timestamp = getCurrentJavaSqlTimestamp();
Map<String, Object> params = new HashMap<String, Object>();
params.put("notes", task.getNotes());
params.put("recording_time", timestamp);
params.put("end_user_id", 805);
SimpleJdbcInsert insertData = new SimpleJdbcInsert(dataSource).
withTableName("data.data_insert").
usingColumns("notes", "recording_time",
"end_user_id").usingGeneratedKeyColumns("data_id");
long dataId = insertData.executeAndReturnKey(params).longValue();
答案 0 :(得分:2)
正确的一个:
java.sql.Timestamp timestamp = getCurrentJavaSqlTimestamp();
Map<String, Object> params = new HashMap<String, Object>();
params.put("notes", task.getNotes());
params.put("recording_time", timestamp);
params.put("end_user_id", 805);
SimpleJdbcInsert insertData = new
SimpleJdbcInsert(dataSource).withSchemaName("data").
withTableName("data_insert")
usingColumns("notes", "recording_time",
"end_user_id").usingGeneratedKeyColumns("data_id");
long dataId = insertData.executeAndReturnKey(params).longValue();
所以只需要使用withSchemaName
的架构名称。