Monday, September 12, 2016

Sending custom cookies with Postman

To send a custom cookie with Postman (API testing tool), set a "Cookie" header with value similar to "name=value". For example, to send JSESSIONID='Babis' include this header:

Header Key | Header Value
Cookie | JSESSIONID='Babis'

 As described here, you should first install Postman's interceptor extension.

Wednesday, September 7, 2016

Adding a new non-null column in a JPA entity with default value (on schema upgrade)

Say you have the following table:

Id | First | Last | Phone
1 Thoring Oakenshield 123456
2 Bilbo Baggins 654321

...and you want to add an extra Email column which should be non-null and default to email@email.com (without losing any data).

In you JPA entity, write:

@Column(nullable = false, columnDefinition = "Varchar(255) default 'email@email.com'")
private String email;
// getter + setter

Make sure you have these external properties set in application.properties:
  • spring.jpa.generate-ddl
  • spring.jpa.hibernate.ddl-auto

Read here for more details.

Also, keep in mind that this is not safe. Not to be used in production. Related stackoverflow discussion.

Tested this with
spring-boot-starter-data-jpa:1.3.1 and Oracle Database 11g Express Edition Release 11.2.0.2.0.