1.18.2018

How to reset Postgres Primary Key Sequence?

In Postgres auto incrementing primary keys are defined using SERIAL PRIMARY KEY. These primary keys are tied to a sequence when defined and hence we need to ALTER the sequence . . .

ALTER SEQUENCE ca_kw_kw_id_seq RESTART WITH 1;
UPDATE ca_kw SET kw_id=nextval('ca_kw_kw_id_seq');

How to Exit from Postgres Command Line?

\q is your command to quit.

I tried to guess the first time by running quit, exit, Ctrl+c with out any luck. Hope this saves some time for others.

How to connect to a Postgres instance from Command Line / Terminal?

The following steps will explain on how to connect to your Postgres instance from command line or terminal if you are using Mac.

1. Make sure you have Postgres installed
2. From command line run the following command

psql -h localhost -p5432 -U superuser postgres

options:
-h host
-p port (default 5432)
-U username (default your machine login)
database (default postgres)

3. Enter the password when prompted for. This is either the one you created during Postgres installation or your machine login password
4. Now Type "helpfor help or \h for help with SQL commands or \? for help with psql commands

1.09.2018

Node js Timezone using Moment

There seems to be no better way of manipulating timezones in javascript. So far I found Moment.js library to be decent. I used it in my node.js projects.

Easy install: Assuming you have node/npm installed, to install moment js library run npm install moment from command line.

Straightforward code:

var moment = require('moment-timezone');
moment.tz.setDefault('America/Chicago'); // default is UTC if you don't set anything
var formattedDate = moment('2018-01-09').format('YYYY-MM-DD'); //formats and converts to the default timezone set above
console.log(formattedDate);

Simple and and easy to use. Have fun manipulating date-time in your javascript code.

11.03.2013

Spring + Hibernate + @Transaction

Error : "No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here"

Assuming everything is in place as per the docs/tutorials out there one could almost miss this little thing.

only looks for @Transactional on beans in the same application context it is defined in.
This means that, if you put in a WebApplicationContext for a DispatcherServlet, it only checks for @Transactional beans in your controllers, and not your services.