diff --git a/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/TestEMProperties.java b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/TestEMProperties.java
new file mode 100644
index 000000000..bcff7b196
--- /dev/null
+++ b/openjpa-persistence-jdbc/src/test/java/org/apache/openjpa/persistence/property/TestEMProperties.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agEmployee_Last_Name to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.openjpa.persistence.property;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.persistence.EntityManager;
+
+import org.apache.openjpa.persistence.OpenJPAPersistence;
+import org.apache.openjpa.persistence.OpenJPAQuery;
+import org.apache.openjpa.persistence.test.SingleEMFTestCase;
+
+/**
+ * TestEMProperties is used to test various persistence properties set through EntityManager.setProperty() API
+ * to ensure no errors are thrown.
+ */
+public class TestEMProperties extends SingleEMFTestCase {
+
+ @Override
+ public void setUp() {
+ setUp(EntityContact.class,
+ EmbeddableAddress.class,
+ DROP_TABLES, "javax.persistence.query.timeout", 23456);
+ }
+
+ public void testQueryTimeoutPropertyDefault() {
+ EntityManager em = emf.createEntityManager();
+
+ String sql = "select * from EntityContact";
+ OpenJPAQuery> query = OpenJPAPersistence.cast(em.createNativeQuery(sql));
+ assertEquals(23456, query.getFetchPlan().getQueryTimeout());
+
+ em.clear();
+ em.close();
+ }
+
+ public void testQueryTimeoutPropertyOnEntityManagerCreation() {
+ Map properties = new HashMap();
+ properties.put("javax.persistence.query.timeout", "12345");
+ // Setting a value of type String should convert if possible and not return an error
+ EntityManager em = emf.createEntityManager(properties);
+
+ String sql = "select * from EntityContact";
+ OpenJPAQuery> query = OpenJPAPersistence.cast(em.createNativeQuery(sql));
+ assertEquals(12345, query.getFetchPlan().getQueryTimeout());
+
+ em.clear();
+ em.close();
+ }
+
+ public void testQueryTimeoutPropertySetOnEntityManager() {
+ EntityManager em = emf.createEntityManager();
+
+ // Setting a value of type String should convert if possible and not return an error
+ em.setProperty("javax.persistence.query.timeout", "12345");
+
+ String sql = "select * from EntityContact";
+ OpenJPAQuery> query = OpenJPAPersistence.cast(em.createNativeQuery(sql));
+ assertEquals(12345, query.getFetchPlan().getQueryTimeout());
+
+ em.clear();
+ em.close();
+ }
+}
diff --git a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/JPAProperties.java b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/JPAProperties.java
index 89f2a79ea..162003c1a 100644
--- a/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/JPAProperties.java
+++ b/openjpa-persistence/src/main/java/org/apache/openjpa/persistence/JPAProperties.java
@@ -18,6 +18,8 @@
*/
package org.apache.openjpa.persistence;
+import java.math.BigDecimal;
+import java.math.BigInteger;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@@ -134,8 +136,18 @@ public class JPAProperties {
} else if (value instanceof CacheStoreMode || (value instanceof String && CACHE_STORE_MODE.equals(key))) {
return (T)DataCacheStoreMode.valueOf(value.toString().trim().toUpperCase(Locale.ENGLISH));
}
+
+ // If the value doesn't match the result type, attempt to convert
+ if(resultType != null && !resultType.isAssignableFrom(value.getClass())) {
+ if (value instanceof String) {
+ if ("null".equals(value)) {
+ return null;
+ }
+ return StringUtil.parse((String) value, resultType);
+ }
+ }
}
- return (T)value;
+ return (T) value;
}
/**