Closed wesleyody closed 6 years ago
Thanks for the report. Unfortunately, you haven't provided enough information for us to be able to help you. It's not clear why you expect to be creating the subscription
table. Is it Flyway, Hibernate, or something else?
If you would like us to spend some time trying to help you, please provide a minimal sample application that works with 1.5 and fails with 2.0.
The table it's already created but when I run the test it's not finding it. I'm using Flyway.
BaseStructure:
@Entity
public class Subscription {
@Id
@GeneratedValue( strategy = GenerationType.IDENTITY )
private Integer id;
private String name;
// getters
}
public interface SubscriptionRepository extends JpaRepository< Subscription, Integer > {
}
@Service
public SubscriptionService {
@Transactional
public Subscription save ( Subscription subscription ) {
return subscriptionRepository.saveAndFlush( subscription );
}
}
Test:
public class BaseRepositoryImpl< T, ID extends Serializable >
extends SimpleJpaRepository< T, ID >
implements BaseRepository< T, ID > {
private EntityManager entityManager;
public BaseRepositoryImpl ( JpaEntityInformation< T, ? > entityInformation, EntityManager entityManager ) {
super( entityInformation, entityManager );
this.entityManager = entityManager;
}
@Override
public T refresh ( T entity ) {
entityManager.refresh( entity );
return entity;
}
@Override
public < C extends Collection< T > > C refresh ( C entities ) {
for ( T entity : entities ) {
refresh( entity );
}
return entities;
}
}
@Configuration
@ComponentScan( lazyInit = true )
public class ApplicationConfig {
@Configuration
@Profile( "default" )
@PropertySource( "classpath:application.properties" )
static class Default {
}
}
@RunWith( SpringJUnit4ClassRunner.class )
@ContextConfiguration( classes = { ApplicationConfig } )
@WebAppConfiguration
@Transactional
public class TestIT {
private MockMvc mockMvc;
@Resource
private WebApplicationContext webApplicationContext;
@Resource
private SubscriptionService subscriptionService;
@Before
public void setup () {
mockMvc = MockMvcBuilders
.webAppContextSetup( webApplicationContext )
.apply( SecurityMockMvcConfigurers.springSecurity() )
.build();
Subscription subscription = new Subscription();
subscription.setName( "foo" );
subscriptionService.save( subscription );
}
}
The same code works with 1.5
Thanks, but some code snippets in a comment aren't really what we need. Can you please turn those into a minimal sample application (something that we can git clone
or unzip) that reproduces the problem. We'll also need details of how to setup any dependencies your application has. Ideally, a minimal sample should not have any unless they are strictly necessary to reproduce the problem.
It was a problem created by https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#updated-default-create-drop-handling
It's all good thanks
When I run my integration tests it's giving me the error below on the moment that tries to insert something on the "database":
subscription is the name of my table that I'm trying to insert
But when I just run my application it is working fine. It seems that is creating an empty database. With
1.5.4.RELEASE
works fineMy configuration: