I am trying to connect my springboot app to my netezza database but no luck. I am trying to use the tutorial at: https://www.callicoder.com/spring-boot-rest-api-tutorial-with-mysql-jpa-hibernate/
I replaced the spring.datasource.url with my netezza database url but no luck. How can I connect to netezza please?
Next to properly configuring spring.datasource.url, you also have to add the Netezza JDBC driver to your classpath. According to this article on the IBM Knowledge Center, you should be able to download the client tools for the right environment:
nz-*client-version.tar.z
Netezza client installation packages for the supported client
operating systems. The IBM Netezza client packages are available for a
common group of operating system environments such as:
nz-linuxclient-version.tar.gz for Linux on Intel/AMD, includes ODBC/JDBC and Netezza command line utilities
...
Additionally to this, you also have to properly configure the dialect. As far as I'm aware, Hibernate (the default JPA provider within Spring boot) has no support for the Netazza dialect. You can find a full list of supported dialects on their Javadoc.
However, since Netazza is based on PostgreSQL 7.x, you might be able to get it to work using one of the PostgreSQL dialects, though there are two remarks:
Hibernate no longer comes with a dialect supporting PostgreSQL 7.x
Netazza didn't maintain backwards compatibility, so it may not work
So to answer your question, it's not officially supported by Hibernate, so it probably won't work. The alternatives are:
Writing your own Hibernate dialect for Netezza. This requires some work, but will allow you to use your dialect for re-use in other projects.
Using the more low-level JdbcTemplate. This means you'll have to work with SQL itself and you may have to do things by yourself.
For the lazy ones like myself,
1) You'll need to install the jar on your machine first, this SO answer explains that.
2) Add the dependencies
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>7.4.1-jdbc3</version>
</dependency>
<dependency>
<groupId>net.sf.squirrel-sql.plugins</groupId>
<artifactId>netezza</artifactId>
<version>3.5.0</version>
</dependency>
<dependency>
<groupId>org.netezza</groupId>
<artifactId>netezza</artifactId>
<version>1.0</version>
</dependency>
3) Netezza custom dialect. Please note, these are the data types that were required for my use case. For any additional data types, you'll have to add them explicitly.
import org.hibernate.dialect.PostgreSQLDialect;
import org.hibernate.type.StandardBasicTypes;
#SuppressWarnings("deprecation")
public class NetezzaDialect extends PostgreSQLDialect {
public NetezzaDialect() {
registerHibernateType(Types.CHAR, StandardBasicTypes.STRING.getName());
registerHibernateType(Types.VARCHAR, StandardBasicTypes.STRING.getName());
registerHibernateType(Types.NVARCHAR, StandardBasicTypes.STRING.getName());
registerHibernateType(Types.BIGINT, StandardBasicTypes.LONG.getName());
registerHibernateType(Types.SMALLINT, StandardBasicTypes.SHORT.getName());
registerHibernateType(Types.DATE, StandardBasicTypes.DATE.getName());
}
}
4) The properties for spring boot
# Netezza properties
spring.datasource.url=jdbc:netezza://{host}:{port}/{db/ catalog}
spring.datasource.username=
spring.datasource.password=
spring.jpa.properties.hibernate.dialect=your.org.config.NetezzaDialect
spring.datasource.driver-class-name=org.netezza.Driver
Related
I'm trying to connect Hibernate Reactive and Spring WebFlux(Project Reactor most).
The problem is that Uni<>(Hibernate Reactive type) replaces Mono<> (Reactive type from Project Reactor), and from now, behaviour is not such obviously, as Project Reactor provides without other reactive types.
Is there are some tools for compatibility between Uni<> and Reactor's Mono<>/Flux<>?
Already Investigated GitHub repos, tried to connect reactive types via custom spring starters.
Yes, there is support to convert between the two type systems.
Add the following dependency...
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>mutiny-reactor</artifactId>
<version>1.7.0</version>
</dependency>
...and use the following code:
Mono<T> monoFromUni = uni.convert().with(UniReactorConverters.toMono());
You can find detailed documentation here: https://smallrye.io/smallrye-mutiny/1.7.0/guides/converters/
Im working in a quarkus project, I have to connect to an elasticsearch clusert and in production exists a mysql database with data.
Im thinking about using Hibernate Search but I have some questions.
1-Which version of hibernate search use quarkus? In the pom is not specified. Is 6?
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-search-orm-elasticsearch</artifactId>
</dependency>
2-It compatible with elasticsearch 7.11.1?
3-In my project I will connect to the mysql database just once to initialize all the index, then the connection is going to be closed, is this possible? or hibernate search needs to be connected to mysql database always?
4-To initialize the indexs with hibernate search is mandatory to use hibernate annotations (for example #Entity and #Column) in the entitys?
5-As I said, the connection with mysql database is going to be close after first indexing, is there a way to add new records to index if I get a list of objects from other system? (for example something like batch)
Thanks
It's Hibernate Search 6 - in Quarkus 1.13, 6.0.2.Final
Yes, it should be. Our main testing is now against the latest Open Source version of Elasticsearch but we are still testing 7.11.
Hibernate Search handles reads/writes and also hydrate your search data from the database so you should have the MySQL database around. If you are only doing read-only stuff AND only using projections, maybe not having the database around is possible but I don't think it's a supported use case
Yes.
You will have to implement it yourself, there's nothing built-in.
Is Spring Data JDBC v1.1.5 recommended for Oracle Database and Enterprise Applications? Lot of samples around the net based on Open Source RDBMS (H2 or PostgreSQL). We are using Spring Data JDBC in a Spring Boot Microservice Application, facing following problems.
Force to write custom converters for oracle.sql.TIMESTAMP, oracle.sql.TIMESTAMPTZ and oracle.sql.DATE and oracle.sql.ROWID etc..
Can't type cast oracle.sql.ROWID to java.lang.Number
Identity must not be null after save.
Spring Data JDBC is absolutely recommended for Enterprise Applications.
Not so much for use with Oracle.
Since the necessary resources (database & JDBC driver) weren't available in a form that could be easily used in integration tests on public platforms, Oracle isn't included in regular builds.
Therefore it is likely that one encounters issues when working with Oracle.
Some are already known, for others issues in Jira or even PRs are highly appreciated.
In the WSO2 documentation you state that the embedded H2 database is suitable for development. However, for most enterprise testing and production environments we recommend an industry-standard RDBMS such as Oracle, PostgreSQL, MySQL, MS SQL, etc. (https://docs.wso2.com/display/Carbon420/Working+with+Databases)
Can you kindly give us some use cases where H2 Databases are suitable for production environments?
How can we better assess if the H2 Database is suitable or not for our production environment?
We do not recommend H2 Database to be used in production. However H2 is recommended to be used as the "Local" Registry. See "Registry and governance" in Production Deployment Guidelines.
See also Sharing Databases
I answered a similar question before: https://stackoverflow.com/a/23090822/1955702
In my case, it was perfectly suitable for testing project on build time. In-memory database have been used to store some lookup table values. Very simple usage as follows:
pom.xml
...
<dependencies>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<version>1.4.193</version>
<scope>testing</scope>
</dependency>
...
</dependencies>
...
Test class
...
#BeforeClass
public static void setupOnce() throws SQLException {
conn = DriverManager
.getConnection("jdbc:h2:mem:test;MODE=Oracle;INIT=runscript from 'classpath:scripts/test.sql'");
dao = new Dao(conn);
...
}
I'd like to set the v$session.program Oracle property in order to have information available in the session table. I'm using JPA with a jndi XA datasource created with an oracle-xa-ds.xml deployed in the deploy folder of Jboss, and therefore I haven't access to the constructor of the Connection.
I have access to the Connection object, in JPA 2 using unwrap, in JPA 1 by casting JPA to Hibernate classes, but there are no properties setter (only Client Info properties that are the way to proceed starting JDBC 4.0).
So my question is, using JPA (with Hibernate) using Jboss 4.2 :
Is it possible to configure the v$session.program in the persistence.xml ?
Is it possible to configure the v$session.program in the oracle-ds.xml ?
Is their any other approach to the solution ?
Thank you for any valuable comments and answers !
I had the same Problem today, after much fiddeling and reading documentation finally I had the Eureka moment:
Add following parameter:
<xa-datasource-property name="connectionProperties">v$session.program=YourUniqueName</xa-datasource-property>
Thats all.
I'm pretty sure this must be documented somewhere but here is what we can find in the JBoss wiki:
How To Specify "PROGRAM" Oracle Connection Property
JBoss Version: JBoss 4.0.3 SP1, Oracle DB Version: 10g
To be able to distinguish the JDBC
connections on the Oracle server side,
which are created by different JBoss
instances, Oracle's PROGRAM connection
property might be set within the
Oracle specific JDBC datasource config
file by using the following tags:
<connection-property name="v$session.program">ADistinguishedNameForPROGRAMProperty</connection-property>
i.e.
...
<connection-url>AConnectionURL</connection-url>
<connection-property name="v$session.program">ADistinguishedNameForPROGRAMProperty</connection-property>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
...
That way the DBAs can have proper
granularity in:
AWRs
v$session view
Other tools which are checking/evaluating PROGRAM connection
property