Archive for category SPRING

MappingJackson2HttpMessageConverter

@SpringBootApplication
public class MainController extends SpringBootServletInitializer {

@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(MainController.class);
}

public static void main(String[] args) throws Exception {
SpringApplication.run(MainController.class, args);
}

@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
MappingJackson2HttpMessageConverter converter =
new MappingJackson2HttpMessageConverter(mapper);
return converter;
}
}

Advertisements

, , ,

Leave a comment

EntityManager Batch insert

@Service
public class BatchRepository<T extends MyEntity> {

@PersistenceContext
private EntityManager em;

public List<T> saveList(List<T> list) {

Session session = (Session) em.getDelegate();
Transaction tx = session.beginTransaction();

for (int i = 0; i < list.size(); i++) {
T t = list.get(i);
if (t.getId() == null) {
session.save(t);
} else {
session.update(t);
}
}

tx.commit();
return list;
}

Leave a comment

Difference between Oracle jdbc driver classes?

For Oracle 9i onwards you should use oracle.jdbc.OracleDriver rather than oracle.jdbc.driver.OracleDriver as Oracle have stated that oracle.jdbc.driver.OracleDriver is deprecated and support for this driver class will be discontinued in the next major release.

oracle.jdbc.OracleDriver

Leave a comment