java.lang.NoSuchFieldError: SPATIAL_MSG_LOGGER using Hibernate and HibernateC3P0

87 Views Asked by At

Trying to query a database using Hibernate and Hibernate C3P0. It works on my local desktop but when I deploy the code, it stops with this error stack:

java.lang.NoSuchFieldError: SPATIAL_MSG_LOGGER
    2023-07-24T10:14:59.232-07:00   at org.hibernate.spatial.dialect.mysql.MySQLDialectContributor.contributeJdbcTypes(MySQLDialectContributor.java:28)
    2023-07-24T10:14:59.232-07:00   at org.hibernate.spatial.contributor.SpatialTypeContributor.contribute(SpatialTypeContributor.java:22)
    2023-07-24T10:14:59.232-07:00   at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.handleTypes(MetadataBuildingProcess.java:390)
    2023-07-24T10:14:59.232-07:00   at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.complete(MetadataBuildingProcess.java:143)
    2023-07-24T10:14:59.232-07:00   at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.build(MetadataBuildingProcess.java:97)
    2023-07-24T10:14:59.232-07:00   at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:402)
    2023-07-24T10:14:59.232-07:00   at org.hibernate.boot.internal.MetadataBuilderImpl.build(MetadataBuilderImpl.java:90)
    2023-07-24T10:14:59.232-07:00   at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:735)

Not sure where SPATIAL_MSG_LOGGER is coming from since it isnt a problem on my local desktop and its never called in my code. Also not using anything spatial related in hibernate so Im not sure why it would be trying to call that.

There is nothing that comes up for SPATIAL_MSG_LOGGER in any search engine so I dont even know where to begin to look.

1

There are 1 best solutions below

0
draganstankovic On

If you look at the source code from where error is coming from:

...
// line 28 is the one below:
HSMessageLogger.SPATIAL_MSG_LOGGER.typeContributions( this.getClass().getCanonicalName() );
...

The error says: java.lang.NoSuchFieldError: SPATIAL_MSG_LOGGER which means that the HSMessageLogger does not have the expected field SPATIAL_MSG_LOGGER. But, looking at the source here: https://github.com/hibernate/hibernate-orm/blob/main/hibernate-spatial/src/main/java/org/hibernate/spatial/HSMessageLogger.java you can see that the field is initialized which means it is supposed to have value.

Additionally, it seems like sometime in Mar 2022 (see: https://github.com/hibernate/hibernate-orm/commit/741b6b71f1552aa224fb61d38b85b32e0b8a19b4#diff-ff75339310aacf045c3aabe5190c15a4d338939a167cf7f39f096dcc7328b1c3) the original Logger field name was replaced with the SPATIAL_MSG_LOGGER which is failing for you.

To summarize the above in how they might be causing the issue you're seeing, there seems to be:

  1. either a mismatch of hibernate/spring/spatial versions in your deploy environment, or
  2. your configuration somehow needs to be ordered so spatial logger gets initialized before the code that fails (where stacktrace you shared is coming from) is executed.

What you can try to do is to disable spatial integration and see if this changes anything. The config setting is I believe: hibernate.integration.spatial.enabled (by default it is true and you can try to set it to false).

The other thing is to try to see if your configuration has some weird versions combo and try to fix that (update everything, explicitly set specific versions where possible so deploy environment can read them properly).

EDIT: (third option) you can also reach out to AWS support and ask them about the error and specifically about how they resolve hibernate dependencies

I hope this helps or at least give you some ideas where to look at. Good luck!