Skip to main content

Posts

Java Bubble Sort Example

Introduction Bubble sort is the simplest sorting algorithm. It has the following steps a) Iterates through the list b) Compares the adjacent elements c) Swap the adjacent elements if they are in not in proper sorting order d) The list is traversed repeatedly unless the list is sorted Worst Complexity : O(n*n) Best Complexity    : O(n) Alternate name      : Sinking Sort Implementation using Simple Loops public class BubbleSortExample { private static int array[] = {0,5,2,6,3,1}; static int temp = 0; public static void main(String[] args) { bubbleSortAscending(); System.out.println("Ascending Sorted List"); for(int value : array) { System.out.print(value + " "); } bubbleSortDescending(); System.out.println("Descending Sorted List"); for(int value : array) { System.out.print(value + " "); } } private static void bubbleSortAscending() { for(int outer=0; outer<array.length; outer++) {

WARN orm.deprecation - HHH90000014: Found use of deprecated [org.hibernate.id.SequenceGenerator] sequence-based id generator

Introduction  I upgraded Hibernate from version 4 to 5.4.4. Following warning was thrown by Hibernate WARN  orm.deprecation - HHH90000014: Found use of deprecated [org.hibernate.id.SequenceGenerator] sequence-based id generator; use org.hibernate.id.enhanced.SequenceStyleGenerator instead.  See Hibernate Domain Model Mapping Guide for details. http-nio-8080-exec-10 WARN  orm.deprecation - HHH90000014: Found use of deprecated [org.hibernate.id.SequenceHiLoGenerator] sequence-based id generator; use org.hibernate.id.enhanced.SequenceStyleGenerator instead.  See Hibernate Domain Model Mapping Guide for details. Old Code     @Id     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_PERSON")     @SequenceGenerator(name = "SEQ_PERSON", sequenceName = "SEQ_PERSON_ID",allocationSize=1)     private Long id; SequenceGenerator is deprecated by Hibernate and we have to use either SequenceStyleGenerator or GenericGenerator instea

Default Port numbers used by different software/protocols

The following table lists the default port numbers used by different software/protocols Software/Protocol Default Port Number http 80 https 443 Apache Server 80 IIS Server 80 Apache Tomcat 8080 MySQL server 3306 SQL Server 1433  MongoDB   27017 PostgreSQL 5432 Java No default port DynamoDB 8000 Cassandra 7000 neo4j http port 7474 neo4j https port 7473 Oracle SQL*Net Listener 1521 Oracle Data Guard 1521 Oracle Connection Manager 1630 Oracle Management Agent 3938 Oracle Enterprise Manager Database Console 1158 Oracle SQL*Plus RMI Port 5580 Oracle SQL*Plus JMS Port 5600

Hibernate - Could not instantiate id generator [entity-name=domainObject]

Exception Could not instantiate id generator [entity-name=Your DomainObject] Solution  <generator> or @GeneratedValue specifies the Java class that is used to generate a unique identifier to the mapped persistent class. Using increment  hbm.xml example <id name="id" type="java.lang.Long" column="id">        <generator class="increment" /> </id> Annotation example @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="ID") private Long id; Using database sequence hbm.xml example <id name="id" type="java.lang.Long" column="id">   <generator class="sequence">     <param name="sequence">SEQ_PERSON_ID</param>  </generator> </id> Annotation example @Id @GeneratedValue(strategy=GenerationType.SEQUENCE,generator="PERSON_SEQ") @SequenceGenerator(name="PERSON_SEQ&qu

Hibernate 5.4.4 - select hibernate_sequence.nextval from dual

Exception http-nio-8080-exec-1 DEBUG hibernate.SQL - select hibernate_sequence.nextval from dual http-nio-8080-exec-1 WARN  spi.SqlExceptionHelper - SQL Error: 2289, SQLState: 42000 http-nio-8080-exec-1 ERROR spi.SqlExceptionHelper - ORA-02289: sequence does not exist org.hibernate.exception.SQLGrammarException: could not extract ResultSet at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:63) at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42) Solution Default value for hibernate.id.new_generator_mappings setting changed to true for 5.0, in previous versions it was set to false by default Add the following property to hibernate.cfg.xml <property name="hibernate.id.new_generator_mappings"> false </property> OR Add the following property to the configuration properties.put("hibernate.id.new_generator_mappings", " false &

Hibernate 5.4.4 - Instantiate an instance of SessionFactory

Introduction We will learn how to create an instance of SessionFactory using Hibernate 5.4.4 Code private static final SessionFactory sessionFactory; public static final String cfgFileLocation = "/hibernate.cfg.xml";  try {          StandardServiceRegistry standardRegistry = new StandardServiceRegistryBuilder()                                            .configure( cfgFileLocation ).build();           Metadata metadata = new MetadataSources( standardRegistry )             .getMetadataBuilder()             .applyImplicitNamingStrategy( ImplicitNamingStrategyJpaCompliantImpl.INSTANCE )             .build();     sessionFactory = metadata.getSessionFactoryBuilder()           .build();     } catch (Throwable ex) {                  System.out.println( "exception" );         throw new ExceptionInInitializerError(ex);     } Following exceptions are resolved through the above code java.lang.IllegalArgumentException: org.hibernate.hql.intern

hibernate-release-5.4.4.Final - Required Jars

Introduction Hibernate (Object Relational Mapping framework) is an implementation of Java Persistence API (JPA) specification.   Required Jars for Hibernate 5.4.4 Following Jars resided inside the required folder are the mandatory jars required for Hibernate 5.4.4 antlr-2.7.7.jar byte-buddy-1.9.11.jar classmate-1.3.4.jar dom4j-2.1.1.jar FastInfoset-1.2.15.jar hibernate-commons-annotations-5.1.0.Final.jar hibernate-core-5.4.4.Final.jar istack-commons-runtime-3.0.7.jar jandex-2.0.5.Final.jar javassist-3.24.0-GA.jar javax.activation-api-1.2.0.jar javax.persistence-api-2.2.jar jaxb-api-2.3.1.jar jaxb-runtime-2.3.1.jar jboss-logging-3.3.2.Final.jar jboss-transaction-api_1.2_spec-1.1.1.Final.jar stax-ex-1.8.jar txw2-2.3.1.jar Hibernate 5.4.4 release is compatible with  Java 8 or 11  JPA 2.2 References https://hibernate.org/orm/releases/5.4/

Jersey Framework Client - How to add HTTP Basic Authentication Header to HTTP Request?

Introduction In this tutorial, we will learn how to add HTTP basic authorization token to the HTTP request header. We will use Jersey Framework to consume RESTful web services. Read the following post if you want to learn how to secure web services using HTTP Basic Authentication Jersey Java Framework - How to add HTTP Basic Authentication to RESTful web services? Maven Dependencies <dependency>     <groupId>org.glassfish.jersey.core</groupId>     <artifactId>jersey-client</artifactId>     <version>2.29</version>  </dependency>  <dependency>     <groupId>org.glassfish.jersey.inject</groupId>     <artifactId>jersey-hk2</artifactId>     <version>2.29</version> </dependency> Basic Authentication is the most simple way to secure HTTP requests. It has the following format Authorization: Basic base64-encoding of username:password Jersey Client Jersy is the refe

Eclipse - Server Tomcat v8.5 Server at localhost failed to start.

When I try to launch the tomcat from Eclipse, I encountered the following error Server Tomcat v8.5 Server at localhost failed to start. Solution Step 1  Delete the .snap file located at the following location     eclipse workspace Path\ .metadata\.plugins\org.eclipse.core.resources Step 2 Delete the  tmp0  folder from the following path      eclipse workspace Path \.metadata\.plugins\org.eclipse.wst.server.core Step 3  Delete the server from servers list Step 4  Remove already added Tomcat Server      i)  Click on Define a new Server     ii)  Select Server Runtime Environments     iii) Select the Tomcat Server and remove it as follows Remove Selected Server Step 5 Make sure that correct version of Server is configured in Project Properties Step 6 Restart the Eclipse IDE.

Jersey Client - How to skip SSL certificates validation?

Introduction In this tutorial, we will explore to skip SSL certificates validation using the Jersy Client. We will use jersey Framework to consume the restful web services. It is very easy to consume the web services hosted on HTTP protocol. Challange is consuming the web services hosted on HTTPS with SSL certificates enabled. Maven Dependencies <dependency>     <groupId>org.glassfish.jersey.core</groupId>     <artifactId>jersey-client</artifactId>     <version>2.29</version> </dependency> Jersey Client Jersy is the reference implementation of JAX-RS. JAX-RS makes it very easy for Java developers to develop and consume RESTFul web services. Client Code import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.Invocation; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.Response; public class SkipSSLCertificateClient { public static Stri