我有 Spring Data 和 Oracle 12 数据库的有趣问题
我有
java.sql.SQLSyntaxErrorException:
ORA-00942: table or view does not exist
但是当我使用 JdbcTemplate 时它有效! Spring 数据和 JdbcTemplate 使用相同的数据源。 Liquibase 迁移也没有问题
我尝试将模式用于模型,但没有运气。
@Getter
@Setter
@Entity
@Table(name = "tb_accounts", schema = "rx")
public class CustomerAccount {
@Id
@Column(name = "id")
private String id;
private String accountNo;
}
@Repository
public interface CustomerAccountRepository extends JpaRepository<CustomerAccount, String> {
}
但正如我所说,它适用于 JdbcTemplate
@Repository
public class CustomerAccountDao {
@Autowired
private DataSource dataSource;
private JdbcTemplate jdbcTemplate;
@PostConstruct
private void postConstruct() {
jdbcTemplate = new JdbcTemplate(dataSource);
}
public List<CustomerAccount> findAll() {
return jdbcTemplate.query("select * from tb_accounts", (rs, i) -> {
CustomerAccount account = new CustomerAccount();
account.setId(rs.getString("id"));
return account;
});
}
迁移文件
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.0.xsd">
<changeSet id="1" author="user1">
<createTable tableName="tb_accounts">
<column name="id" type="VARCHAR(256)">
<constraints primaryKey="true"/>
</column>
<column name="accountNo" type="VARCHAR(256)"/>
</createTable>
</changeSet>
</databaseChangeLog>
有任何想法吗?我应该检查什么?我花了几个小时找到原因,但没有任何帮助:(
最佳答案
它需要使用 TB_ACCOUNTS 而不是 tb_accounts ...
关于 Spring 数据和 ORA-00942 : table or view does not exist,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52348230/