Hibernate fail to register REF_CURSOR parameter - jpa

I am new to Hibernate. Using the 5.2.10 FINAL version connecting to Oracle 11g using the Oracle10gDialect with JPA 2.1 and ojdbc8.jar
I try to access a simple stored procedure taking a String input parameter and output a Oracle SYS_REFCURSOR.
StoredProcedureQuery call = session.createStoredProcedureCall("sp_get_profile");
call.registerStoredProcedureParameter(1, String.class, ParameterMode.IN);
call.registerStoredProcedureParameter(2, Class.class, ParameterMode.REF_CURSOR);
call.execute();
An exception occur when I access the function
ERROR SqlExceptionHelper Invalid column type: 2012
DatabaseException::error=[Error registering REF_CURSOR parameter [2]]
I try to write a simple program connecting to DB with the Oracle Driver only. I will have the same error if I register Types.REF_CUSOR as the output parameter to CallableStatement.
cs.registerOutParameter(2, Types.REF_CURSOR);
And the problem can be solved by changing to OracleTypes
cs.registerOutParameter(2, OracleTypes.CURSOR);
Anyone know what is wrong? I need to fall back to use the traditional SQL programming if I cannot get the stored procedure access success. . . please help.

Finally got it work, I should check the Oracle JDBC document first before implementation.
ojdbc8 should be good for Oracle 12c + JDK8 + JPA2.1 with Oracle12cDialect.
For Oracle 11g, need to use ojdbc6.jar

I solved that issue by debugging OJDBC and Hibernate, the building from sources a patched Hibernate CORE library (5.4.15-Final).
I have patched the method ExtractedDatabaseMetaDataImpl.supportsRefCursors which returns always false.

Related

SocketException thrown when using linq for Npgsql EntityFramework6 model

After much effort getting my MVC5 vb.net app configured with Npgsql and EntityFramework6.Npgsql I can connect to the postgres database fine using the Entity Data Model Wizard in Visual Studio 2017, creating a new connection with Data Provider of PostgreSQL Database, entering my database server details and testing the connection (succeeds). I can also double-click the EDMX file and add tables, etc as expected. This is my first project that talks to a postgreSQL database (normally use MS SQL Server). Everything seems to be happy and fine until I encounter code that is a linq statement that attempts to query the database. My Linq statement is:
Dim l_ListOfPwrCycleCrashEvents As List(Of pwr_cycle_crash_events) = (From item In m_AnalyticsEntities.pwr_cycle_crash_events Where item.serialnumber = "0123445678" Select item).ToList
I have the statement in a try/catch block, but visual studio still reports the following:
Exception thrown:'System.Net.Sockets.SocketException' in System.dll Additional
information: A non-blocking socket operation could not be completed
immediately occurred
I cannot seem to figure out why this statement fails. I am able to use similar statements against a different EntityFramework (MS SQL Server) that is also configured in the application.
The complete method that contains the linq statement:
Public ReadOnly Property iCountOfPwrCycleCrashEvents(
ByVal a_sSerialNumber As String
) As Integer Implements IAnalytics.iCountOfPwrCycleCrashEvents
Get
Try
Dim l_ListOfPwrCycleCrashEvents As List(Of pwr_cycle_crash_events) = (From item In m_AnalyticsEntities.pwr_cycle_crash_events
Where item.serialnumber = a_sSerialNumber
Select item).ToList
If (l_ListOfPwrCycleCrashEvents IsNot Nothing) Then Return l_ListOfPwrCycleCrashEvents.Count
Catch l_Exception2 As System.Net.Sockets.SocketException
Dim askjfhakjh As Integer = 7
Catch l_Exception As Exception
Dim kjhadkjh As Integer = 1
End Try
Return 0
End Get
End Property
I am using Npgsql v4.1.1 and EntityFramework6.Npgsql v6.3.0 in an application that targets .NET Framework 4.5.1.
I can't seem to figure out why the linq statement throws this exception or how to solve the problem. What suggestions do you have?
I figured out the issue. I was using 4.5.1 framework because I thought I had a dependency that would not allow me to move to 4.5.2. I went to Package Manager Console and ran the following command:
Update-Package -ProjectName myProjectName -reinstall
By doing so, I found that I had a package that was needed but could not be loaded because it required the 4.5.2 framework (or higher). I changed the framework of the app to 4.5.2 and issued the above Package Manager command and it executed without errors. I ran the app and the linq statement no longer throws an exception.

DB2 exception: Cannot create PoolableConnectionFactory SQLCODE=-142,

I keep having the following error in MobileFirst Platform 6.3:
Runtime: org.apache.commons.dbcp.SQLNestedException: Cannot create
PoolableConnectionFactory (DB2 SQL Error: SQLCODE=-142,
SQLSTATE=42612, SQLERRMC=null, DRIVER=4.19.26)
This is my adapter code:
var test2 = WL.Server.createSQLStatement("SELECT * FROM WSDIWC.WBPTRR1");
function getCEID(cnum) {
return WL.Server.invokeSQLStatement({
preparedStatement : test2,
parameters : []
});
}
And adapter XML:
<connectivity>
<connectionPolicy xsi:type="sql:SQLConnectionPolicy">
<!-- Example for using a JNDI data source, replace with actual data source
name -->
<!-- <dataSourceJNDIName>${training-jndi-name}</dataSourceJNDIName> -->
<!-- Example for using MySQL connector, do not forget to put the MySQL
connector library in the project's lib folder -->
<dataSourceDefinition>
<driverClass>com.ibm.db2.jcc.DB2Driver</driverClass>
<url>jdbc:db2://***</url>
<user>**</user>
<password>**</password>
</dataSourceDefinition>
</connectionPolicy>
</connectivity>
I have remove the url, user and password.
Hope you help me out on clarification about the current problem.
I already know that the sql is not accepted since it's just a simple query.
I have also research about z/OS DB2 that it has issue with same error code sqlcode=-142. http://answers.splunk.com/answers/117024/splunk-db-connect-db2.html
While you say that this is a "simple query", the exception error code mentions the following:
-142
THE SQL STATEMENT IS NOT SUPPORTED
Explanation
An SQL statement was detected that is not supported by the database.
The statement might be valid for other IBM® relational database
products or it might be valid in another context. For example,
statements such as VALUES and SIGNAL or RESIGNAL SQLSTATE can be used
only in certain contexts, such as in a trigger body or in an SQL
Procedure.
System action
The statement cannot be processed.
Programmer response
Change the syntax of the SQL statement or remove the statement from
the program.
You should review the DB2 SQL guidelines for how to achieve what you want to achieve, and also explain that in the question if you'd like further assistance. For example, are you sure "WSDIWC.WBPTRR1" is actually available?
I encountered this same problem with JDBC connections to mainframe DB2 in MobileFirst 6.3. Connections to DB2 LUW worked fine. It appears that default pool validationQuery is valid for DB2 LUW but not DB2 z/OS.
You can work around the bug by doing the data source configuration in the Liberty profile server.xml. From the Eclipse Servers view, expand MobileFirst Development Server and edit the Server Configuration. Add the driver and data source there; for example:
<library id="db2jcc">
<fileset dir="whereever" includes="db2jcc4.jar db2jcc_license_cisuz.jar"/>
</library>
<dataSource id="db2" jndiName="jdbc/db2">
<jdbcDriver libraryRef="db2jcc"/>
<properties.db2.jcc databaseName="mydb" portNumber="5021"
serverName="myserver" user="myuser" password="mypw" />
</dataSource>
Then reference it in your adapter XML under connectionPolicy:
<dataSourceJNDIName>jdbc/db2</dataSourceJNDIName>
A benefit of configuring data sources in server.xml (vs the adapter XML) is you have access to all data source, JDBC, and JCC properties. So if the connection pool gives you other problems, you can customize it or switch to another data source type, such as type="javax.sql.DataSource".

How can I connect vertica with JDBC?

I want to connect vertica with JDBC. But I got errors.
Here is my code :
....
Class.forName("com.vertica.jdbc.Driver");
....
connection= DriverManager.getConnection
(
"jdbc:vertica://192.168.2.116:5433/schema", "dbadmin", "pass123"
);
But I got this error(if I open the netbeans database section I got same error message. But I connect to vertica with client(Dbeaver)) :
ex = (java.sql.SQLException) java.sql.SQLException: [Vertica]No enum const class com.vertica.dsi.dataengine.utilities.MetadataSourceColumnTag.COLUMN_SİZE
How can I fix this?
So if you need jdbc client for vertica in netbeans or intellij use this vertica jdbc driver. It's the one that worked for me. (taken from dbvisuzlizer).
i think it is because of your locale. in this case turkish i guess.
COLUMN_SİZE has upper case i -> İ
it is verticas fault to use toUpper digressivly.
Vertica's connect string uses databasename, not schema name after the host:port. See the doc for details:
https://my.vertica.com/docs/CE/6.0.1/HTML/index.htm#1395.htm
Connection conn = DriverManager.getConnection(
"jdbc:vertica://VerticaHost:portNumber/databaseName",
"username", "password");
By default, users have a search path of "$user, public, v_catalog, v_monitor and v_internal", therefore, you can create and use a matching username to connect directly to the desired SCHEMA.
Its about 32 bit - 64 bit issue I think, because it is working on 32 bit windows I cant understand
make sure the connector (vertica-jdbc-xxxx.jar) is in the JDK\jre\lib\ext folder

Varchar to int typecasting in JPA 1.9

I want to convert varchar to int in jpql. The field is varchar, but all the data will be in integer format only. My JPA library version is 1.9
I already used CAST and CONVERT methods, but it did not working.
My query is:
select SUM(Cast(model.wagonsRequired as INT)) from IptRailcargolines model where model.iptRailwayindent.id=7
or
select SUM(CONVERT(INT, model.wagonsRequired)) from IptRailcargolines model where model.iptRailwayindent.id=7
and my java console error is:
Caused by: Exception [TOPLINK-8025] (Oracle TopLink Essentials - 2.0 (Build b40-rc (03/21/2007))): oracle.toplink.essentials.exceptions.EJBQLException
Exception Description: Syntax error parsing the query [select SUM(FUNCTION(CONVERT(INT, model.wagonsRequired))) from IptRailcargolines model where model.iptRailwayindent.id=:headId], line 1, column 20: unexpected token [(].
Internal Exception: line 1:20: unexpected token: (
Please help me to resolve the issue.
Thankyou for your reply...
I am using MyEclipse IDE. So, may be internally it will use the Eclipselink. Can you please tell me where can i found my EclipseLink version? and how can i use FUNC / FUNCTION method in my JPA query. (I am using SQLSERVER 2008.)
I think i found the eclipseLink version in my myeclipse.
Windows > Preference > JPA
The version is 1.0
Please tell me the solution.
CAST and CONVERT are not part of JPA (1.0 or 2.0, and there is no 1.9).
You seem to be using EclipseLink, but there is no 1.9 version either. These functions are supported in EclipseLink 2.4, previously (2.3) you could us the FUNC operator to call a database function, or use a native SQL query.

Bad value for type timestamp on production server

I'm working with: seam 2.2.2 + hibernate + richfaces + jboss 5.1 + postgreSQL
I have an module which needs to load some data from the database. Easy. The problem is, on development it works fine, 100%, but when I deploy on my production server and try to get the data, an error rise:
could not read column value from result set: fechahor9_504_; Bad value for type timestamp : [C#122e5cf
SQL Error: 0, SQLState: 22007
Bad value for type timestamp : [C#122e5cf
javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not execute query
[more errors]
Caused by: org.postgresql.util.PSQLException: Bad value for type timestamp : [C#122e5cf
at org.postgresql.jdbc2.TimestampUtils.loadCalendar(TimestampUtils.java:232)
[more errors]
Caused by: java.lang.NumberFormatException: Trailing junk on timestamp: ''
at org.postgresql.jdbc2.TimestampUtils.loadCalendar(TimestampUtils.java:226)
I can't understand why it works on my machine (development) and why not on production. Any clues? Anyone gone through the same problem? Is exactly the same compilation
Stefano Travelli was right. I was checking the jBoss on production and there was an old jdbc driver on [jboss_dir]/common/lib from an old jwebstart application (not developed by me). Deleted that jdbc and it works fine. I should check if the old application is still needed and if so, check if it still works without the jdbc being there or with an upgraded version.
Not sure what the driver story is ..
but the problem for me show up when JDBC tries to parse bigint from the DB to
myOjbect.setDate(Date date){...}
the other "JDBC friendly" is ignorred for some reason .
myOjbect.setDate(long date){...}
So .. removing the Date setter and leaving a long one resolves the problem.
This is a Big workaround .. but may help someone out there :)