我有一个带有休眠和jpa的弹簧启动应用程序。当尝试创建实体的新实例(通过任何一个或直接)时,一切似乎都很好(没有错误,并且返回的实例正在增加),但是这些实例被保存到数据库中,也不会在查询到orm时返回(niether by norFooJpaRepositoryentityManageridJpaRepository.findAll()entityManager.find(FooImpl.class, id))
我尝试调用方法而不是 -> 抛出错误(无事务)saveAndFlushsaveJpaRepository
我尝试手动刷新 ->相同的错误。entityManager
我检查了 的齐平模式 - >它是“自动”entityManager
我尝试直接使用 ->找不到任何实例entityManager.find(CourseImpl.class, id)
我尝试用->注释服务方法没有区别@Transactional
我的实体:
@Entity
@Table(name = "foo")
public class FooImpl implements Foo{
@Id
@GeneratedValue
private Long id;
@Column
private String someOtherValue;
...
@Override
public Long getId() {
return id;
}
@Override
public void setId(Long id) {
this.id = id;
}
}
我:Application.java
@SpringBootApplication
@EnableJpaRepositories
@EnableTransactionManagement
@EnableJpaAuditing
public class Application extends SpringBootServletInitializer implements ApplicationContextAware {
private static ApplicationContext applicationContext;
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
@Bean
@Primary
@ConfigurationProperties(prefix = "spring.datasource")
public javax.sql.DataSource primaryDataSource() {
DriverManagerDataSource dataSource = new DriverManagerDataSource();
dataSource.setDriverClassName("com.mysql.cj.jdbc.Driver");
dataSource.setUsername("username");
dataSource.setPassword("n0tRea1Pasw0rd");
dataSource.setUrl("jdbc\\:mysql\\://localhost\\:3306/bar");
dataSource.setSchema("bar");
return dataSource;
}
郎朗坤
相关分类