While using Coacroach Db with Spring Boot and Spring Batch, I am getting the following error.
org.postgresql.util.PSQLException: ERROR: invalid value for parameter "TimeZone": "Europe/London"
Detail: The system cannot find the path specified.
Application.properties
spring.datasource.driver-class-name=org.postgresql.Driver
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.PostgreSQL95Dialect
spring.datasource.username=root
spring.datasource.password=
spring.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.datasource.url=jdbc:postgresql://localhost:26257/defaultdb?sslmode=disable&serverTimezone=UTC&useLegacyDatetimeCode=false
spring.jpa.properties.hibernate.jdbc.time_zone= UTC
spring.batch.initialize-schema = always
I also added this and above properties as mentioned somewhere but didn't help.
#PostConstruct
void started() {
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
}
Out of curiosity, which operating system are you using? We have an open issue relating to timezones, which is known to affect Windows.
When you specify the UTC timezone, do you receive the same error as you do with "Europe/London"? What if you try using a numerical offset, like "+0:00"?
Also, when setting the timezone through the URL, the parameter should be timezone=utc (or whichever other value you want).
So see a number of issues.
1. You said you are using Coacroach Db but you seem to be loading a JDBC JAR and ULR string for Postgres.
2. Posgres does not have "Europe/London" as a valid TimeZone String. There is a "Europe/London GB GB-Eire"
See: https://www.postgresql.org/docs/8.1/datetime-keywords.html
3. You have a space in the time zone property name.
This: spring.jpa.properties.hibernate.jdbc.time_zone= UTC
Should Be: spring.jpa.properties.hibernate.jdbc.time_zone=UTC
Related
when creating TYPE in cassandra cli eg: cqlsh: create type cast (name text, role text) i am getting error
" line 1:16 mismatched input '(' expecting '.' (create type
cast[(]...) "
Actually i am using spring boot for creating TYPE in
cassandra-DB. I have tried manually in cassandra cli as well as in spring boot. Both are not working spring boot is throwing exception at the time running the application.
Please refer this link for more clarity ?
http://cassandra.apache.org/doc/latest/cql/functions.html
please help me on this.
Every object in Cassandra need to be defined in some keyspace. You either need to specify the full type name in form of keyspace.name, or execute use keyspace; before executing this command.
Looks like a bug in Cassandra (feel free to file a JIRA), if you really need to use that name, you can try to specify it as:
create type test."cast"(...
but in this case, the name of the type will be case sensitive, and you'll need always specify it in double quotes.
I have created a simple application with spring boot 1.5.2. I am passing date and already mentioned the date format in application.properties file as follwoing :
spring.jackson.joda-date-time-format=yyyy-MM-dd
But while calling the rest rest service using any client for POST(Insert) or PUT(Update), date is changing to on day old. Example 2017-03-21 will change to 2017-03-20.
I had the same issue and I solved it in that way:
In your entitiy, add theses annotations:
#Temporal(TemporalType.DATE)
#JsonFormat(shape = JsonFormat.Shape.STRING, locale = "fr-FR", timezone = "Europe/Paris")
private Date yourDate;
Or you can add theses line to application.properties file:
spring.jackson.time-zone=Europe/Paris
spring.jackson.locale=fr_FR
If you are in another country you can change locale and timezone, but even if you keep France, it will work.
Just set the timezone to UTC like below
SpringApplication.run(Application.class, args);
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
It solved my problem.
After upgrading from spring boot 1.2.6.RELEASE -> 1.3.1.RELEASE there seems to be a problem when using iso 8101 dateformat with timezone offset.
In my application.yml the jackson date-format is set to format with timezone offset
spring:
jackson:
date-format: yyyy-MM-dd'T'HH:mm:ss.SSSXXX
With boot 1.2.6 this results in datetime formats with the correct iso 8601 timezone format like 2014-01-01T23:01:01.010+01:00
But with boot 1.3.1 the format is kept in Zulu time zone
2014-01-01T22:01:01.010Z
By default Jackson uses GMT time zone. You can change it by adding to your configuration file:
spring:
jackson:
time-zone: Europe/Berlin
or change it for certain property by using
public class DateStuff {
#JsonFormat(shape=JsonFormat.Shape.STRING, pattern="yyyy-MM-dd,HH:00", timezone="CET")
public Date creationTime;
}
Jackson FAQ: Date Handling
With thanks to #dimuha I figured it out. You have to add the time-zone property too to have the same behavior as before the upgrade
spring:
jackson:
date-format: yyyy-MM-dd'T'HH:mm:ss.SSSXXX
time-zone: Europe/Berlin
This will output 2014-01-01T23:01:01.010+01:00 iso 8601 dates.
In the hibernate model when using jadira-usertype org.jadira.usertype.dateandtime.threeten.PersistentLocalDateTimeAsString as Type, the conversion is not reversible.
#Column(name="requested_start")
#Type(type="org.jadira.usertype.dateandtime.threeten.PersistentLocalDateTimeAsString")
private LocalDateTime requestedStartDate;
When creating object with datetime in following format;
myObject.setRequestedStartDate(LocalDateTime.parse("2014-12-28T19:30:00"));
is stored in DB (MariaDB) as "2014-12-28T19:30" ignoring the seconds part (don't know why).
when querying back the data, I'm getting the following exception
java.time.format.DateTimeParseException: Text '2014-12-28T19:30' could not be parsed at index 16
But, If I set date as "2014-12-28T19:30:01" with seconds set to "01", it is working fine.
I also tried setting the springframework's DateTimeFormat, still facing the same exception.
#Column(name="requested_start")
#Type(type="org.jadira.usertype.dateandtime.threeten.PersistentLocalDateTimeAsString")
#DateTimeFormat(pattern="yyyy-MM-dd'T'HH:mm:ss")
private LocalDateTime requestedStartDate;
You can try this modified pattern "yyyy-MM-dd'T'HH:mm[:ss]".
The meaning of the square brackets is indicating an optional part during parsing - see javadoc.
I'm seeing a very strange behavior in my application.
My application setup: Spring + Hibernate + C3p0
Application keeps running fine, when all of a sudden I start seeing these errors in logs and system totally stop processing any database specific requests.
WARN c3p0.C3P0Registry - Could not create for find ConnectionCustomizer with class name ''.
java.lang.ClassNotFoundException:
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.mchange.v2.c3p0.C3P0Registry.getConnectionCustomizer(C3P0Registry.java:181)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolManager.getConnectionCustomizer(C3P0PooledConnectionPoolManager.java:636)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolManager.createPooledConnectionPool(C3P0PooledConnectionPoolManager.java:738)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolManager.getPool(C3P0PooledConnectionPoolManager.java:257)
at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPoolManager.getPool(C3P0PooledConnectionPoolManager.java:271)
at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:80)
at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:423)
at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)
at org.hibernate.jdbc.AbstractBatcher.prepareSelectStatement(AbstractBatcher.java:123)
at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:73)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:99)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:495)
at org.springframework.orm.hibernate3.HibernateTemplate$18.doInHibernate(HibernateTemplate.java:690)
at org.springframework.orm.hibernate3.HibernateTemplate.execute(HibernateTemplate.java:365)
at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:687)
Why would C3p0 require to create a new connection pool at this
particular time, before these exceptions application is 100% working
fine and responding perfectly.
Also I've not provided any connectionCustomizerClassName property in
my c3p0 configurations, why would it load one? in this stack trace I
see it's not-null empty string ''.
Any clues?
==============================================================================
Following hibernate jars I see in application's classpath:
hibernate-3.2.6.ga.jar
spring-hibernate-1.2.6.jar
Following c3p0 jars I see in application's classpath:
c3p0-0.9.1.jar
c3p0-0.9.2-pre5.jar
c3p0-oracle-thin-extras-0.9.2-pre5.jar
Code that manually read these properties and set on datasource (I do not read/set any connectionCustomizerClassName property here at all)
ComboPooledDataSource dataSource = new ComboPooledDataSource();
dataSource.setMinPoolSize(Integer.parseInt(props.getProperty("jdbc.hibernate.c3p0.minPoolSize")));
.....
Here are C3p0 properties being used:
jdbc.hibernate.c3p0.minPoolSize=100
jdbc.hibernate.c3p0.initialPoolSize=100
jdbc.hibernate.c3p0.maxPoolSize=1000
jdbc.hibernate.c3p0.maxIdleTime=21600
jdbc.hibernate.c3p0.maxStatementsPerConnection=0
jdbc.hibernate.c3p0.maxStatements=0
jdbc.hibernate.c3p0.numHelperThreads=30
jdbc.hibernate.c3p0.checkoutTimeout=30000
jdbc.hibernate.c3p0.idleConnectionTestPeriod=900
jdbc.hibernate.c3p0.preferredTestQuery=SELECT 1 FROM dual
jdbc.hibernate.c3p0.maxConnectionAge=0
jdbc.hibernate.c3p0.maxIdleTimeExcessConnections=3600
jdbc.hibernate.c3p0.acquireIncrement=10
jdbc.hibernate.c3p0.acquireRetryDelay=5000
jdbc.hibernate.c3p0.acquireRetryAttempts=6
jdbc.hibernate.c3p0.propertyCycle=180
Following up a conversation in the comments on the posted question, it looks like the issue here is that VisualVM updates the null valued property connectionCustomizerClassName to an empty String value, which c3p0 currently treats an non-null and interprets as a class name.
Going forward (c3p0-0.9.5-pre7 and above), c3p0 will guard against this, interpret an all-whitespace connectionCustomizerClassName as equivalent to null. But in the meantime or for older versions, take care.
One easy workaround would be to define a NullConnectionCustomizer:
package mypkg;
import com.mchange.v2.c3p0.*;
public class NullConnectionCustomizer extends AbstractConnectionCustomizer
{}
And then use mypkg.NullConnectionCustomizer for connectionCustomizerClassName, so that the corresponding field in VisualVM is not empty and ambiguously interpretable as empty String or null.