hibernate.hbm2ddl.auto value="update" issue with Hibernate 3.4 to 5.1 migration - postgresql

I have an application presently running (without issue) on JBoss 6 that I am attempting to upgrade to run on WildFly 10.1. Much of this upgrade is going well. However, the upgrade from Hibernate 3.4 (on JBoss 6) to Hibernate 5.1 (on WildFly 10.1) is causing a few issues.
Specifically, in my persistence.xml, I include the following property.
<property name="hibernate.hbm2ddl.auto" value="update"/>
Please NOTE: I am NOT making any schema or other DB changes as part of the upgrade. Furthermore, I am pointing at the same database instance that has been successfully running under the JBoss 6/Hibernate 3.4 instance. Therefore, I am confident that inclusion of this property should have no actual work/update to do upon first run with the WildFly 10.1/Hibernate 5.1 version.
However, inclusion of this property appears to 1) erroneously determine that it needs to make updates and 2) fail to do so successfully. It results in the following stack trace:
Failed to start service jboss.persistenceunit."app.ear#PU": org.jboss.msc.service.StartException in service jboss.persistenceunit."PU": javax.persistence.PersistenceException: [PersistenceUnit: PU] Unable to build Hibernate SessionFactory
...
Caused by: javax.persistence.PersistenceException: [PersistenceUnit: PU] Unable to build Hibernate SessionFactory
...
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Unable to execute schema management to JDBC target [create index company_id_index on APPROVER (COMPANY_ID)]
...
Caused by: org.postgresql.util.PSQLException: ERROR: relation "company_id_index" already exists
Again, the table and index in question already exist (as confirmed by the final error).
Is Hibernate now no longer case sensitive (COMPANY_ID_INDEX being different than company_id_index)?
If so, how can I configure it so that it is case insensitive as it used to be (Postgres defaults all of this to lower....)
TIA!

Doh! Face palm! I recently discovered that similar errors were also occurring related to hbm2ddl index creation with Hibernate 3.4/JBoss 6 as I am now experiencing with Hibernate 5.1/Wildfly 10.1; however, they were NOT preventing successful start up of the persistence module. Essentially, they were being only subtly suppressed. I'm not sure if this is an expected change related to the Hibernate versions or not, as they do prevent it's start up in Hibernate 5.1/Wildfly 10.1?
The underlying issue here turned out to be that index names must be unique across the entire schema in Postgres. So multiple entities each having a FK to a COMPANY_ID column must each have a unique name for the index. Indices are relations in Postgres (driving the unique across schema requirement).
Thank you for the suggestions and apologies for the confusion.

Related

After upgrading to postgresql 13.8 getting error the server does not support SSL

We have upgraded the postgresql version from 9.6 to 13.8 in our lab. Post upgrade and initialization our application is keep restarting due to the below error in the log 
Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'migration': Unsatisfied dependency expressed through field 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'credentialedDataSource': Invocation of init method failed; nested exception is org.springframework.jdbc.CannotGetJdbcConnectionException: Could not get JDBC Connection; nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (The server does not support SSL.)
What does the above error mean? How to fix it? Do we need to do anything with the server.crt and server.key files? Meaning, reimport or regenerate. 
Pls let me know if you need any other detail from me.
Just playing with the postgresql parameters in pg_hba.conf file
You need to carry the server.crt and server.key over from the old server to the new one (if you didn't already). You also need to change "ssl" parameter in the new postgresql.conf file, since you apparently haven't done so.
You should carefully consider the differences between the old postgresql.conf and the new one to decide how the differences should be resolved. 9.6 to 13 is a pretty big jump, and some parameters are new, some are obsolete, and some have changed their defaults or their meanings (or spellings).

Why JBOSS ORACLE datasource doesn't fail fast when query times out?

Why JBOSS ORACLE datasource doesn't fail fast when query times out?
Environment: jboss-eap-7.0
I was waiting a fast fail with the exception:
java.sql.SQLTimeoutException: ORA-01013 user requested cancel of current operation
But I get the following after the end of transaction.
Caused by: java.lang.Throwable: setRollbackOnly called from:
at com.arjuna.ats.internal.jta.transaction.arjunacore.TransactionImple.setRollbackOnly(TransactionImple.java:339)
How do I force it to fail fast?
This is related to the JDBC driver version and firewall stuff.
This is not related to JBOSS, XA, JTA, DATASOURCE or something else.
See: https://www.ibm.com/mysupport/s/question/0D50z000062kF2p/why-is-the-webspheredefaultquerytimeout-property-for-timing-out-sql-queries-not-working

EclipseLink adding a Converter causes ValidationException intermittently

I am building a new application using EclipseLink for the first time.
Everything was going okay until I added an entity that uses JSR310 Instant for a timestamp column.
So I created a converter class and mapped it to the the associated field like so:
#Convert(converter = JSR310InstantTypeConverter.class)
private Instant pwdChangeCodeExpiresOn = null;
However since I added that converter the application has started throwing the following exception:
SEVERE: Servlet.service() for servlet [APIJerseyServlet] in context with path [/Sclera] threw exception [org.glassfish.jersey.server.ContainerException: java.lang.ExceptionInInitializerError] with root cause
Local Exception Stack:
Exception [EclipseLink-7351] (Eclipse Persistence Services - 2.5.1.v20130918-f2b9fc5): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The converter class [com.sclera.utils.JSR310InstantTypeConverter] specified on the mapping attribute [pwdChangeCodeExpiresOn] from the class [com.sclera.entity.Admin] was not found. Please ensure the converter class name is correct and exists with the persistence unit definition.
at org.eclipse.persistence.exceptions.ValidationException.converterClassNotFound(ValidationException.java:2317)
at org.eclipse.persistence.internal.jpa.metadata.converters.ConvertMetadata.process(ConvertMetadata.java:248)
This will start happening after a code change (when Eclipse restarts the server). I have to stop and start (and/or restart) the server manually a few times until it finally starts working again. Then it will work fine until a code change or two later when it will start throwing the exception again.
This is an enormous pain. Anyone know the cause and how to fix it?
Okay solution found. Adding the converter class to the persistence.xml file - as suggested by the error message - seems to have resolved the problem.
<persistence-unit name="example" transaction-type="RESOURCE_LOCAL">
....
<class>com.example.utils.JSR310InstantTypeConverter</class>
...
</persistence-unit>
I should have tried that earlier. The fact that is working some of the time without this made me think it wouldn't make a difference.

Spring data using Neo4j and MongoDB

I am just about to go crazy,I just spent many hours to try work with spring-data for Neo4J,working with spring-data for MongoDB was a walk in the park compared to that.
My goals: 1) Working with spring-data to manage two data-stores Mongo,Neo4j.
(correct me if I am wrong but there is no spring-data cross data store support for these two, which mean I will use different domain entities for each store)
2) Working with Neo4J embedded graph.
3) Will have the ability to monitor the graph with some client like the web admin.
So I started with Good Relationship spring-data example
, where using :
POM
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>2.0.0.RELEASE</version>
</dependency>
XML
<neo4j:config storeDirectory="data/graph.db"/>
So my first question is how can I monitor the graph In that configuration, in which client?
So I read more and I got to Neo4j Web Admin for embedded graph configuration
I followed every step tried it and boom!
Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.haze.server.repository.mongo.ProfileRepository com.haze.server.services.ProfileServices.profileRepository; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'profileRepository': FactoryBean threw exception on object creation; nested exception is java.lang.NoSuchMethodError: org.springframework.data.repository.core.RepositoryMetadata.getDomainClass()Ljava/lang/Class;
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:506)
at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:284)
... 39 more
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'profileRepository': FactoryBean threw exception on object creation; nested exception is java.lang.NoSuchMethodError: org.springframework.data.repository.core.RepositoryMetadata.getDomainClass()Ljava/lang/Class;
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:149)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.getObjectFromFactoryBean(FactoryBeanRegistrySupport.java:102)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForBeanInstance(AbstractBeanFactory.java:1442)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:305)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:876)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:818)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:735)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:478)
... 41 more
Caused by: java.lang.NoSuchMethodError: org.springframework.data.repository.core.RepositoryMetadata.getDomainClass()Ljava/lang/Class;
at org.springframework.data.mongodb.repository.support.MongoRepositoryFactory.getTargetRepository(MongoRepositoryFactory.java:84)
at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:137)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:125)
at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:41)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
... 49 more
Make long story short the only version configuration I find to get spring context to load is
<spring.data.mongo.version>1.0.4.RELEASE</spring.data.mongo.version>
<neo4j.version>1.6</neo4j.version>
<spring-data-neo4j.version>2.0.1.RELEASE</spring-data-neo4j.version>
If I am adding the below dependency like specify in the article it crashed.
<spring-data-commons-core.version>1.3.0.RELEASE</spring-data-commons-core.version>
Ok so I got it working after many hours with the neo4j embedded graph and the server wrapper in order to monitor the graph from the web admin with mongo as my primary datastore.
Kind of happy but sad cause using old version for the neo4j server wrapper (1.6 cause that is the only thing which worked) I was motivated to start working with the graph via spring-data.
So I got the most basic node entity:
#NodeEntity
public class ProfileNode {
#GraphId
private Long id;
#Indexed(unique = true)
private String pid = null;
}
Tried some basic operations:
// save node - OK
ProfileNode node = new ProfileNode();
node.setPid("44ed79b3ea8a99117aa601b16e916ddr");
ProfileNode profile = graphRepo.save(node);
// return NULL
node = graphRepo.findByPropertyValue("pid",
"44ed79b3ea8a99117aa601b16e916ddr");
// throwing exception - java.lang.UnsupportedOperationException:read only index
graphRepo.delete(profile);
Basically almost every basic operation I tried didn't worked for me.
I don't know if the problems occur because of my mishmash configurations or that I am doing something wrong In my code, can someone please help me configure my application or let me know why the most basic operation via spring data doesn't work for me?
Thanks.
Please update to 2.1.RC4 as Lasse said.
Regarding using the embedded server with SDN, it is described in the docs.
What does your repository look like?
You really should upgrade to SDN 2.1.RC4, it will be out as GA in a metter of weeks.
Secondly, here is some code to get you started: https://github.com/SpringSource/spring-data-neo4j/blob/master/spring-data-neo4j/src/test/java/org/springframework/data/neo4j/repository/DerivedFinderTests.java - you can add a test for findByPropertyValue if you are not keen on derived finders, but at least this works out of the box using just that single file, i.e. you can eliminate Spring config as a source of errors.
For cross-store: I see little point in cross-store with MongoDB, to me cross-store is all about transactions across multiple data sources. With MongoDB + Neo, I'd just build different repositories and on the application level do just enough to use them concurrently.
You have to have spring-data-mongodb-1.1.0.RC1 and spring-data-neo4j-2.1.0.RC4. Both of those have the same spring-data-commons-core dependency.
spring-data with neo4j + mongo version conflicts

Why does EclipseLink think my database schema doesn't exist?

I'm working on a web project using EJB 3.0, and whenever EclipseLink tries to interact with the database, it says that the schema I'm using doesn't exist (which it does).
I get a massive, unhelpful stack trace from GlassFish 2.1, which begins with:
EclipseLink, version: Eclipse Persistence Services - 1.1.0.r3639-SNAPSHOT
file:/C:/Documents%20and%20Settings/nick/.personalDomain/personalDomain/applications/j2ee-apps/ScienceEar/lib/ScienceJpa-1.0-SNAPSHOT.jar-SciencePU login successful
Local Exception Stack:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 1.1.0.r3639-SNAPSHOT): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLSyntaxErrorException: Schema 'BEAMLINE' does not exist
Error Code: -1
Call: SELECT exp_id, fac_family, public_viewable, group_name, created_ts, status, exp_num, date_received, exp_type, title, updated_ts, text_only_title, experiment_url, proposed_eec, start_of_prep FROM beamline.eec_exp_toc
Query: ReadAllQuery(name="Experiment.findAll" referenceClass=Experiment sql="SELECT exp_id, fac_family, public_viewable, group_name, created_ts, status, exp_num, date_received, exp_type, title, updated_ts, text_only_title, experiment_url, proposed_eec, start_of_prep FROM beamline.eec_exp_toc")
I could post more of the stack trace, but it's really boring. Any ideas for why EclipseLink can't see the schema?
More info: "beamline" is the only schema I use. The SQL in the stack trace is the stuff that was generated by a NamedQuery, the first interaction with this database (and the first JPA interaction at all) in my program.
Got it - I'm connecting directly to the database, when I should be using GlassFish's connection pool.