Java EE Enterprise Application: perform some action on deploy/startup [duplicate]

Configure SerlvetContextListener and override contextInitilized() in your web application description , web.xml <web-app …> <listener> <listener-class>com.someCompany.AppNameServletContextListener</listener-class> </listener> </web-app package com.someCompany; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; public class AppNameServletContextListener implements ServletContextListener{ @Override public void contextDestroyed(ServletContextEvent arg0) { System.out.println(“ServletContextListener destroyed”); } @Override public void contextInitialized(ServletContextEvent arg0) { System.out.println(“ServletContextListener started”); // do the things here } }

getting the response body of HttpResponse

First, see if your server is not returning blank response: response.getEntity().getContentLength(); //it should not be 0 Second, try the following to convert response into string: StringBuilder sb = new StringBuilder(); try { BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()), 65728); String line = null; while ((line = reader.readLine()) != null) { sb.append(line); } } catch (IOException … Read more

Configure JPA to let PostgreSQL generate the primary key value

Given the table definition: CREATE TABLE webuser( idwebuser SERIAL PRIMARY KEY, … ) Use the mapping: @Entity @Table(name=”webuser”) class Webuser { @Id @SequenceGenerator(name=”webuser_idwebuser_seq”, sequenceName=”webuser_idwebuser_seq”, allocationSize=1) @GeneratedValue(strategy = GenerationType.SEQUENCE, generator=”webuser_idwebuser_seq”) @Column(name = “idwebuser”, updatable=false) private Integer id; // …. } The naming tablename_columname_seq is the PostgreSQL default sequence naming for SERIAL and I recommend that you … Read more

what is difference between a Model and an Entity

The definition of these terms is quite ambiguous. You will find different definitions at different places. Entity: An entity represents a single instance of your domain object saved into the database as a record. It has some attributes that we represent as columns in our tables. Model: A model typically represents a real world object … Read more