All Posts By

mathanlalsait@gmail.com

Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: “YEAR”: invalid identifier

February 19, 2025

Error caused while migrating from Spring boot 2.x to 3.x and Hibernate 6.x version

Caused by: java.sql.SQLSyntaxErrorException: ORA-00904: "YEAR": invalid identifier
	at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:629) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
	at oracle.jdbc.driver.T4CTTIoer11.processError(T4CTTIoer11.java:563) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
	at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:1150) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
	at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:770) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
	at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:298) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
	at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:497) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
	at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:151) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
	at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:936) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
	at oracle.jdbc.driver.OracleStatement.prepareDefineBufferAndExecute(OracleStatement.java:1171) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
	at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1100) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
	at oracle.jdbc.driver.OracleStatement.executeSQLSelect(OracleStatement.java:1425) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
	at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1308) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
	at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3745) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
	at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3854) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
	at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1097) ~[ojdbc8-21.9.0.0.jar:21.9.0.0.0]
	at com.zaxxer.hikari.pool.ProxyPreparedStatement.executeQuery(ProxyPreparedStatement.java:52) ~[HikariCP-5.1.0.jar:na]
	at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeQuery(HikariProxyPreparedStatement.java) ~[HikariCP-5.1.0.jar:na]
	at org.hibernate.sql.results.jdbc.internal.DeferredResultSetAccess.executeQuery(DeferredResultSetAccess.java:246) ~[hibernate-core-6.5.3.Final.jar:6.5.3.Final]
	... 172 common frames omitted

Solution:

Hibernate 6 HibernateCriteriaBuilder adds operation needed to express features of HQL which are not available in standard JPQL. So it is recommended to migrate to HibernateCriteriaBuilder method like year, month, minute, seconds etc to support more HQL features.

Replace

        CriteriaBuilder cb = entityManager.getCriteriaBuilder();
        Expression<Integer> yearExp = cb.function("year", Integer.class, root.get(modelData));

With

        HibernateCriteriaBuilder cb = entityManager.unwrap(Session.class).getCriteriaBuilder();
        Expression<Integer> yearExp = cb.year(root.get(modelData));

year

Extracts the TemporalUnit.YEAR of a date, time, or datetime expression.

EntityManager – unwrap

Java Persistence 2.0 introduces unwrap method to return an object of the specified type to allow access to the provider-specific API

Java Program how to find second largest number in array

April 12, 2023

Program:

public class SecondLarge 
{
	public static void main(String[] args) 
	{
		int[] a = { 25, 122, 33, 45, 56 };
		int largest = a[0];
		int secondLargest = a[0];
		System.out.println("The Given Array is:");

		for (int i = 0; i < a.length; i++) 
		{
			System.out.println(a[i] + "\t");
		}

		for (int i = 0; i < a.length; i++) 
		{
			if (a[i] > largest) 
			{
				secondLargest = largest;
				largest = a[i];
			} 
			else if (a[i] > secondLargest) 
			{
				secondLargest = a[i];
			}
		}
		System.out.println("The Second Largest Number is:" + secondLargest);
	}
}

Compile:

javac SecondLarge.java
 java SecondLarge

Output:

The Given Array is:
25	
122	
33	
45	
56	
The Second Largest Number is:56

Java Code To Check Print Array Elements (Using For Loop)

April 7, 2023

Program:

public class Array 
{
	public static void main(String[] args) 
	{
		int a[] = new int[] { 1, 2, 3, 4, 5, 6, 7 };
		System.out.println("The Array Elements:");
		for (int i = 0; i < a.length; i++) 
		{
			System.out.println(a[i]);
		}

	}
}

Compile:

javac  Array.java
 java  Array

Output:

The Array Elements:
1
2
3
4
5
6
7

Java Code To Check Fibonnaci Series

April 6, 2023

Explanation:

         Fibonacci series means the next number is the sum of the previous two number.

         The First two number is always 0 and 1.
        
         Step 1: In this program,we use class name as Fibonacci.

         Step 2: In that main method,we declare the variable n1=0;n2=1,n3,i,count=10.

         Step 3: And then use for loop.
    
         Step 4: In that loop,the initalization starts from 2 because 0 and 1 are already 
                 printed.

         Step 5: To find n3 value,add n1 and n2.Now the n3 value will be printed.

         Step 6: Now we assign n2 value to n1 and n3 value to n2 in that statement 

                                      n1=n2;
                                      n2=n3;

         Step 7: And then put the value in the previous step n3=n1+n2.

         Step 8: This process will continue until the loop exixts.

Program:

public class Fibonnaci 
{
	public static void main(String args[]) 
	{
		int n1 = 0, n2 = 1, n3, i, num = 10;
		System.out.println("The fibonacci series are:");
		System.out.print(n1 + " " + n2);
		for (i = 2; i < num; ++i) 
		{
			n3 = n1 + n2;
			System.out.print(" " + n3);
			n1 = n2;
			n2 = n3;
		}
	}
}

Compile:

javac Fibonnaci.java
 java Fibonnaci

Output:

The fibonacci series are:
0 1 1 2 3 5 8 13 21 34

Java Code To Check Print the Reverse Of a Given Number

April 1, 2023
 EXPLANATION:-

   Here we see how to reverse a program using while loop.

STEP1: First write the class name and declare the main method.

STEP2: Initialize the variable int,num,remainder,reverse for the program.

STEP3: Use while loop and find the remainder value by 10 using the modulo of the given program.

STEP4: Then multiply the reverse number by 10 and add the modulo value what we get in the remainder.

STEP5: Next divide the number by 10.

STEP6: Keep on repeat the process until the zero value will appear.

STEP7: Finally we get the reverse value (EG:654321-123456).

Program:

public class Reverse 
{
	public static void main(String[] args) 
	{
		int num = 654321, reverse = 0;
		while (num != 0) 
		{
			int remainder = num % 10;
			reverse = reverse * 10 + remainder;
			num = num / 10;
		}
		System.out.println(" The reverse of the given number is : " + reverse);
	}
}

Compile:

javac Reverse.java
 java Reverse

Output:

 The reverse of the given number is : 123456

Java Code To Check Swap with Variable

March 31, 2023

EXPLANATION:

    step1: Write the class name and declare the main method.

    step2: Initalize the variable int a,b,temp.

    step3: Give the value for the variable a=10,b=5.

    step4: Assign the third variable as temp.

    step5: Declare temp=a; a=b; b=temp;
                    
    step6: Assign a to a temp variable temp=a;

    step7: Assign b to a variable a=b;

    step8: Assign temp to variable b=temp;

    step9: Now, the value will be swapped. 

Program:

public class Swapvar 
{
	public static void main(String args[]) 
	{
		int a = 10;
		int b = 5;
		b = a + b;
		a = b - a;
		b = b - a;
		System.out.println(a);
		System.out.println(b);
	}

}

Compile:

javac Swapvar.java
 java Swapvar

Output:

5
10

Java Code To Check Print Square Pattern Program

March 23, 2023

Program:

public class squarePattern 
{
       public static void main(String[] args) 
       {
             int size=9;
             for(int i=0;i<size;i=i+2) 
	     {
                      for(int j=0;j<size;j++) 
	              {
			  System.out.print("*");
	              }
		          System.out.println();
             }
       }
}

Compile:

javac squarePattern.java
 java squarePattern

Output:

*********
*********
*********
*********
*********

Java Code To Print Check Number Pattern Program

March 22, 2023

Program:

public class Pattern2
{
	public static void main(String args[])
	{
		int a=1;
		for(int i=1;i<=9;i=i+2)
		{
			for(int j=1;j<=i;j++)
			{
				System.out.print(a);

			}
		  System.out.println();
		  a++;
		}
	}
}

Compile:

javac Pattern2.java
 java Pattern2

Output:

1
222
33333
4444444
555555555

Java Code To Check Print Right Triangle Star Pattern

March 16, 2023

Program:

public class Pattern1 
{
	public static void main(String args[]) 
	{
		for (int i = 1; i <= 5; i++) 
		{
			for (int j = 1; j <= i; j++) 
			{
				System.out.print("*");

			}
			System.out.println();
		}
	}
}

Compile:

javac Pattern1.java
 java Pattern1

Output:

*
**
***
****
*****