[ 
https://issues.apache.org/jira/browse/OPENJPA-2882?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17432570#comment-17432570
 ] 

ASF subversion and git services commented on OPENJPA-2882:
----------------------------------------------------------

Commit 4510ac06a71b2b8714d87550b68777746d56546b in openjpa's branch 
refs/heads/2.2.x from Will Dazey
[ https://gitbox.apache.org/repos/asf?p=openjpa.git;h=4510ac0 ]

OPENJPA-2882: Exception passing javax.persistence.* String values to 
createEntityManager(Map)

Signed-off-by: Will Dazey <dazeyde...@gmail.com>


> Exception passing javax.persistence.* String values to 
> createEntityManager(Map)
> -------------------------------------------------------------------------------
>
>                 Key: OPENJPA-2882
>                 URL: https://issues.apache.org/jira/browse/OPENJPA-2882
>             Project: OpenJPA
>          Issue Type: Bug
>    Affects Versions: 2.2.3
>            Reporter: Will Dazey
>            Priority: Minor
>             Fix For: 3.2.1
>
>
> Exception:
> {code:java}
> java.lang.IllegalArgumentException: argument type mismatch
>       at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>       at 
> java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
>       at 
> java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>       at java.base/java.lang.reflect.Method.invoke(Method.java:566)
>       at org.apache.openjpa.enhance.Reflection.set(Reflection.java:777)
>       at 
> org.apache.openjpa.persistence.EntityManagerImpl.setKernelProperty(EntityManagerImpl.java:1936)
>       at 
> org.apache.openjpa.persistence.EntityManagerImpl.setProperty(EntityManagerImpl.java:1911)
>       at 
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:258)
>       at 
> org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:58)
> Caused by: java.lang.IllegalArgumentException: Error while setting value 
> 34567 of class java.lang.String by setter method public 
> org.apache.openjpa.persistence.jdbc.JDBCFetchPlan 
> org.apache.openjpa.persistence.jdbc.JDBCFetchPlanImpl.setLockTimeout(int) of 
> instance org.apache.openjpa.persistence.jdbc.JDBCFetchPlanImpl@28d133b9 by 
> reflection.
>       at 
> org.apache.openjpa.enhance.Reflection.wrapReflectionException(Reflection.java:347)
>       at org.apache.openjpa.enhance.Reflection.set(Reflection.java:779)
> {code}
> Fairly easy to reproduce:
> Test:
> {code:java}
>     Map<String, Object> properties = new HashMap<String, Object>();
>     properties.put("javax.persistence.lock.timeout", "34567");
>     EntityManager em = emf.createEntityManager(properties);
> {code}
> Whats happening:
> `org.apache.openjpa.enhance.Reflection.findSetter(org.apache.openjpa.persistence.jdbc.JDBCFetchPlanImpl,
>  "LockTimeout")` is returning a setter 
> ```
>     public org.apache.openjpa.persistence.jdbc.JDBCFetchPlan 
> org.apache.openjpa.persistence.jdbc.JDBCFetchPlanImpl.setLockTimeout(int)
> ```
> However, 
> `org.apache.openjpa.persistence.EntityManagerImpl.convertUserValue("javax.persistence.lock.timeout",
>  "34567", int)` is failing to accurately convert the value from String -> 
> int. You might think "oh, well then just pass in (int) 34567 and not (String) 
> 34567". However, this isnt always possible. The actual usecase that exposed 
> this issue is using deployment descriptors to pass the persistence context 
> property:
> {code:java}
>     <persistence-context-ref>
>         <persistence-property>
>             <name>javax.persistence.lock.timeout</name>
>             <value>34567</value>
>         </persistence-property>
>     </persistence-context-ref>
> {code}
> also, this reflection exception doesnt occur if the same property is passed 
> to createEntityManagerFactory(Map)! Inconsistent behavior and a runtime 
> reflection exception that shouldn't occur.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to