我正在使用springboot,即使在具有WRITE权限的情况下保存记录时也会出现异常。 例外是:
“对数据库'table_name'的INSERT权限被拒绝 'db_name',模式'dbo'“
HHH000010:批量发布时,它仍然包含JDBC语句。
当我用JPA存储库替换它并得到此错误时,这与JdbcTemplate一起使用效果很好。
这是我的代码段的样子:
@SpringBootApplication
@ComponentScan(basePackages = {"com.person.model"})
@EnableJpaRepositories(basePackages={"com.person.repository"})
public class TestApplication {
public static void main(String[] args) {
SpringApplication.run(TestApplication.class, args);
}
}
我在此应用中建立了多个数据库连接,该数据库被设置为辅助连接 下面是配置类的外观
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(
entityManagerFactoryRef = "entityManagerFactory",
basePackages = {"com.person.repository"})
public class PrelandDBConfig {
@Bean(name = "secDataSource")
@ConfigurationProperties(prefix = "preland.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@PersistenceContext(unitName = "prelanding")
@Bean(name = "entityManagerFactory")
public LocalContainerEntityManagerFactoryBean entityManagerFactory(
EntityManagerFactoryBuilder builder,
@Qualifier("secDataSource") DataSource dataSource) {
return builder
.dataSource(dataSource)
.packages("com.person.model")
.persistenceUnit("prelanding")
.build();
}
@Bean(name = "transactionManager")
public PlatformTransactionManager transactionManager(
@Qualifier("entityManagerFactory") EntityManagerFactory entityManagerFactory) {
return new JpaTransactionManager(entityManagerFactory);
}
}
下面是模型,服务类是:
@Entity
@Table(name = "java_app_log", catalog = "personDb", schema = "dbo")
public class AppLog {
@Id
@Column(name = "CORR_ID")
private String corrId;
@Column(name = "LOG_MSG")
private String logMsg;
@Column(name = "CREATE_DATE")
private Date createDate;
}
@Service
public class DBService {
@Autowired
AppLogRepo _appLogRepo;
AppLog appLog = new AppLog();
appLog.setLogMsg(logMsg);
appLog.setCreateDate(new Date());
_appLogRepo.save(appLog);
}
这是我拥有的JPA存储库:
public interface AppLogRepo extends JpaRepository<AppLog, Integer> {
}
application.properties文件为
preland.datasource.url=jdbc:sqlserver://persondbqa.testcmp.com;databaseName=personDb
preland.datasource.username=test-user
preland.datasource.password=test-password
preland.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
preland.datasource.platform=sqlserver
preland.datasource.initialize=false
preland.datasource.show-sql=true
preland.datasource.validation-query=select 1
preland.datasource.testOnBorrow=true
请指导我我在这里真正失踪了什么。预先感谢。