[Hibernate-JIRA] Created: (HHH-5094) PersistenceUtilHelper cannot access non-public fields/methods (it should be able to)
by Philip Clay (JIRA)
PersistenceUtilHelper cannot access non-public fields/methods (it should be able to)
------------------------------------------------------------------------------------
Key: HHH-5094
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-5094
Project: Hibernate Core
Issue Type: Bug
Components: entity-manager
Affects Versions: 3.5.0-Final
Environment: 3.5.0-Final. Any environment
Reporter: Philip Clay
Attachments: hibernate-entitymanager-bugreproduction.tgz
PersistenceUtilHelper is only able to access public fields and public methods. As it is written, it cannot access non-public members.
Internally, it incorrectly uses Class.getField(...) and Class.getMethod(...).
It should use Class.getDeclaredField(...) and Class.getDeclaredMethod(...), so that it can see non-public members.
I believe the use of getField and getMethod is not indented, because setAccessibility is the next call after that. Here is the code...
{code}
private static Object get(Object proxy, String property) {
final Class<?> clazz = proxy.getClass();
try {
try {
final Field field = clazz.getField( property ); // only retrieves public fields!!!
setAccessibility( field ); // if you really only wanted public fields, this call is unnecessary!
return field.get( proxy );
}
catch ( NoSuchFieldException e ) {
final Method method = getMethod( clazz, property );
if (method != null) {
setAccessibility( method ); // if you really only wanted public methods, this call is unnecessary!
return method.invoke( proxy );
}
...
}
private static Method getMethod(Class<?> clazz, String methodName) {
try {
char string[] = methodName.toCharArray();
string[0] = Character.toUpperCase( string[0] );
methodName = new String( string );
try {
return clazz.getMethod( "get" + methodName ); // only retrieves public methods!!!
}
catch ( NoSuchMethodException e ) {
return clazz.getMethod( "is" + methodName ); // only retrieves public methods!!!
}
...
}
private static void setAccessibility(Member member) {
if ( !Modifier.isPublic( member.getModifiers() ) ) {
//Sun's ease of use, sigh...
( ( AccessibleObject ) member ).setAccessible( true ); // This is dead code! The input member will always be public
}
}
{code}
Notice the call to setAccessibility. The call to setAccessibility shows that one assumes that the field retrieved from getField() (or method from getMethod()) could be non-public, which in fact it can't. All fields returned from getField will always be public (same for getMethod()). So, essentially the code inside the if statement in setAccessibility is dead code.
I have attached a tarball containing a failing testcase that shows the incorrect behavior.
Explode the tarball and run "mvn test" to reproduce the incorrect behavior.
Also, within the tarball, I have included an svn diff for a proposed patch.
See the README.txt file within the tarball for more info.
I first noticed this problem when using hibernate validator to validate some protected members, but I narrowed it down to a problem in PersistenceUtilHelper.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years, 6 months
[Hibernate-JIRA] Created: (HHH-4568) Sybase - Test "BatchTest" fails due to "unexpected row count from update"
by Strong Liu (JIRA)
Sybase - Test "BatchTest" fails due to "unexpected row count from update"
-------------------------------------------------------------------------
Key: HHH-4568
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4568
Project: Hibernate Core
Issue Type: Bug
Components: core
Affects Versions: 3.5.0-Beta-2, 3.5.0.Beta-1, 3.3.2, 3.2.4.sp1
Environment: Sybase
Reporter: Strong Liu
Assignee: Strong Liu
Fix For: 3.2.x, 3.3.x, 3.5, 3.3.0.GA, 3.2.4.sp1
The test "BatchTest" fails due to "org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1". The database server seems configured properly, as the "BatchUpdates" sample from jConnect 6 works correctly.
The problem specifically occurs with a table that has a numeric column with precision (e.g. numeric(10,4))
Sybase does not thrown any SQLException when you try and persist a numeric value whose scale exceeds that defined on the column. Instead, it returns an updateCount of zero
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
14 years, 6 months