Java 弹簧靴&x2B;数据JPA:未获取连接实体的属性
到目前为止,我使用的是SpringWebMVC+DataJPA,我可以用H2Fine编写集成测试。Java 弹簧靴&x2B;数据JPA:未获取连接实体的属性,java,spring,hibernate,spring-boot,spring-data-jpa,Java,Spring,Hibernate,Spring Boot,Spring Data Jpa,到目前为止,我使用的是SpringWebMVC+DataJPA,我可以用H2Fine编写集成测试。 现在我正在使用SpringBoot,在集成测试中尝试使用H2时,我有一个奇怪的行为。我有以下两个实体(也使用lombok): 当我尝试将实体转换为DO时,我得到一个NullpointerException,因为只有Task的id被设置,所有其他属性都为null。当转换发生时,我处于同一事务中,因此应该加载属性。无论如何,在调用converter类之前,我尝试获取Task的“order”属性,但它为
现在我正在使用SpringBoot,在集成测试中尝试使用H2时,我有一个奇怪的行为。我有以下两个实体(也使用lombok): 当我尝试将实体转换为DO时,我得到一个NullpointerException,因为只有Task的id被设置,所有其他属性都为null。当转换发生时,我处于同一事务中,因此应该加载属性。无论如何,在调用converter类之前,我尝试获取Task的“order”属性,但它为null
@Service
public class RepositoryErrorSourceService implements ErrorSourceService {
....
@Override
@Transactional
public String search(Event event) {
...
EventLife eventLife = EventLife.builder()
.date(Calendar.getInstance())
.event(eventToDomainConverter.convert(eventEntity))
.task(command)
.eventStatus(EventStatusEnum.BEFORE_START)
.order(0).build();
EventLifeEntity eventLifeEntity = eventLifeEntityRepository.save( eventLifeToEntityConverter.convert(eventLife) );
LOGGER.debug("The following EvenEntity is saved: {}", eventLifeEntity);
// starting the first task of the workflow
command.execute( eventLifeToDomainConverter.convert( eventLifeEntity) );
...
}
}
渐变依赖项:
dependencies {
compile project(':common')
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-integration'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-devtools'
compile 'org.apache.httpcomponents:httpclient:4.5.2'
providedRuntime 'mysql:mysql-connector-java:5.1.38'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testRuntime 'com.h2database:h2:1.4.191'
testCompile 'com.jayway.restassured:rest-assured:2.9.0'
}
所以我在集成测试中使用了良好的H2,但在spring boot中似乎缺少了一些东西。也有可能我忘记了某个地方的环境。不管怎样,我都被卡住了。如果有人能帮助我,那就太好了 谢谢,
五, +++++++++++++++++更新1++++++++++++++
忘了提了,但我也尝试了使用“急切取回”类型。我甚至尝试在调用转换器之前引用特定属性,但没有任何更改。您不需要指定hsql db的版本。运行时('com.h2database:h2')应该足够了,因为spring自己管理版本。我的内存数据库也有类似的问题。尝试使用运行时('org.hsqldb:hsqldb'),看看问题是否仍然存在。谢谢Dennis,但恐怕没有任何改变。可能试一下急切取回类型吗?嗨,科林,我忘了把它放在上面,但我也试过急切取回类型。我甚至试着在转换之前参考特定的属性,但没有区别。但是我在交易中,所以实体经理应该能够应付。你知道吗?我认为它与弹簧靴有某种联系。也许我错过了某个配置?谢谢
dependencies {
compile project(':common')
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-data-jpa'
compile 'org.springframework.boot:spring-boot-starter-integration'
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
compile 'org.springframework.boot:spring-boot-starter-actuator'
compile 'org.springframework.boot:spring-boot-devtools'
compile 'org.apache.httpcomponents:httpclient:4.5.2'
providedRuntime 'mysql:mysql-connector-java:5.1.38'
testCompile 'org.springframework.boot:spring-boot-starter-test'
testRuntime 'com.h2database:h2:1.4.191'
testCompile 'com.jayway.restassured:rest-assured:2.9.0'
}