I am new to Spring Data JDBC, and I am struggling to create a simple Dto and get it persisted on the DB.
I am using Spring-Boot 2.1.1.RELEASE and and Oracle 12 Database.
UserDto
@Table(value="USERS_T")
public class UserDto extends PersistableDto {
@Id
@Column(value="USR_USERNAME")
private String userName;
@Column(value="USR_FIRSTNAME")
private String firstName;
@Column(value="USR_LASTNAME")
private String lastName;
.....
}
UserDao
@Repository
public interface UserDao extends CrudRepository<UserDto, String> {
@Query("SELECT * FROM USERS_T u WHERE u.USR_USERNAME = :userName")
UserDto findByUserName(@Param("userName") String userName);
}
and I am simply trying to persist it on the DB like this
public String createUser() {
UserDto userDto = new UserDto().setUserName("mapss@sapot.wrong.email.pt").setPassword("superpass").setUserType("Guest").setActive(true);
logger.info(String.format("Creating user: " + userDto));
userDto.setNew(true);
UserDto persistedUser = userDao.save(userDto);
logger.info(String.format("Persisted user: " + persistedUser));
return "Ending of create user operation";
}
I am getting this exception.
org.springframework.dao.DataRetrievalFailureException: The generated key is not of a supported numeric type. Unable to cast [oracle.sql.ROWID] to [java.lang.Number]
at org.springframework.jdbc.support.GeneratedKeyHolder.getKey(GeneratedKeyHolder.java:79) ~[spring-jdbc-5.1.3.RELEASE.jar:5.1.3.RELEASE]
at org.springframework.data.jdbc.core.DefaultDataAccessStrategy.getIdFromHolder(DefaultDataAccessStrategy.java:323) ~[spring-data-jdbc-1.0.3.RELEASE.jar:1.0.3.RELEASE]
I believe that this somehow is related with the fact that the @Id is a String.
Can someone help me understand what am I doing wrong? Why this behavior. On the spec I do not see and restriction to the type of the Id. Is this and Oracle integration issue? How can i fix this?
thank you all for your help.