Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/main/java/com/j256/ormlite/stmt/mapped/MappedCreate.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public int insert(DatabaseType databaseType, DatabaseConnection databaseConnecti
} else if (idField.isGeneratedId()) {
if (assignId) {
// get the id back from the database
keyHolder = new KeyHolder();
keyHolder = new KeyHolder(idField.getColumnName());
}
} else {
// the id should have been set by the caller already
Expand Down Expand Up @@ -257,8 +257,18 @@ private void assignIdValue(T data, Number val, String label, ObjectCache objectC
}

private static class KeyHolder implements GeneratedKeyHolder {
String columnName;
Number key;

public KeyHolder(String columnName) {
this.columnName = columnName;
}

@Override
public String getColumnName() {
return this.columnName;
}

public Number getKey() {
return key;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
*/
public interface GeneratedKeyHolder {

/**
* Return the name of the generated column we are interested in.
*/
public String getColumnName();

/**
* Add the key number on the key holder. May be called multiple times.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public int insert(String statement, Object[] args, FieldType[] argFieldTypes, Ge
if (keyHolder == null) {
stmt = connection.prepareStatement(statement);
} else {
stmt = connection.prepareStatement(statement, Statement.RETURN_GENERATED_KEYS);
stmt = connection.prepareStatement(statement, new String[] { keyHolder.getColumnName() });
}
statementSetArgs(stmt, args, argFieldTypes);
int rowN = stmt.executeUpdate();
Expand Down