Skip to main content

Posts

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

Spring RestTemplate - How to skip SSL certificates validation?

In this tutorial, we will explore to consume restful web services hosted on https URL with SSL certificates. We will use Sprint RestTemplate 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. I encountered the following exception when accessing SSL hosted web services Caused by: javax.net.ssl.SSLHandshakeException:        sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target  at sun.security.ssl.Alerts.getSSLException(Alerts.java:192) at sun.security.ssl.SSLSocketImpl.fatal(SSLSocketImpl.java:1917) We will use  SSLContext to skip SSL validation. What is SSL Context? SSL Context is a collection of ciphers, trusted certificates, TLS extensions and options, and protocol versions. It acts as a factory

Top 20 JVM languages

Java is a popular object-oriented programming language. It was developed with an intention of WORA i.e. write once, run anywhere. Compiled Java code can run be run on any platform without recompilation. Java runs on Java Virtual Machine (JVM). JVM is a virtual machine and it is required by the computer to run any code compiled to Java bytecode.  Besides Java, the following languages can be run on JVM Scala Kotlin Clojure Apache Groovy Frege Ceylon Redline Smalltalk Xtend Haxe JRuby Kawa scheme Armed Bear Common Lisp Neo4j Nashorn Jacl Simula Jabaco JScheme Bigloo Renjin

Oracle How to reset Sequence without dropping it

In this article, we will learn how to reset Sequence to a particular value without dropping it. Let's suppose the current value of the sequence e.g seq_person_id is 10234 and we want to reset it to 100. Step 1 alter sequence  seq_person_id increment by -10134 minvalue 0 Note : MINUS sign with 10134. Step 2 select  seq_person_id.nextval from dual Step 3 alter sequence  seq_person_id  increment by 1 minvalue 0; The sequence is now reset to 100.