-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 
Author Message
 Post subject: use_reflection_optimizer
PostPosted: Wed Feb 23, 2005 10:45 am 
Beginner
Beginner

Joined: Wed Feb 23, 2005 10:37 am
Posts: 29
Hi.
I am newbie in Hibernate but we cant get it to work as far as use_reflection_optimizer is concerned. We use a lot of primitive data types as fields and we would prefer not to change them by java wrapper objects. I am now trying to disable the hibernate.cglib.use_reflection_optimizer property with no success. We looked at the source code and (not having to much knowledge about the source code) it seems to me that this could possibly be a bug in this class:
net.sf.hibernate.persister.AbstractEntityPersister line 771:
optimizer = !foundCustomAccessor && Environment.useReflectionOptimizer() ?
ReflectHelper.getBulkBean(mappedClass, getterNames, setterNames, types, fastClass) :
null;

foundCustomAccessor variable is true because there is setter for the property which is used. Shouldn't it be:
optimizer = foundCustomAccessor && Environment.useReflectionOptimizer() ?
ReflectHelper.getBulkBean(mappedClass, getterNames, setterNames, types, fastClass) :
null;

instead.

Sorry if I am wrong and hope to get an answer.
Thanks in advance.[/i]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 23, 2005 12:22 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
No that is not a bug and is perfectly correct.

You notice both conditions have to be true for optimization to be in effect, right? You are obviously not setting 'hibernate.cglib.use_reflection_optimizer' to false, otherwise that condition resolves to false regardless of the outcome of foundCustomAccessor.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 23, 2005 12:27 pm 
Beginner
Beginner

Joined: Wed Feb 23, 2005 10:37 am
Posts: 29
yeah, you are right about that. I was a bit too fast at my conclusion.
But anyway, I wrote out the Environment.useReflectionOptimizer() which shows me false value but still the optimizer somehow, somewhere is set, ie it is not null when it tries to setPropertyValues


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 23, 2005 1:23 pm 
Beginner
Beginner

Joined: Wed Feb 23, 2005 10:37 am
Posts: 29
OK, I dont really know why but that exception dissappeared and now I am getting this:
total objects hydrated: 1
resolving associations for [com.newve2.Board#74416]
net.sf.hibernate.PropertyAccessException: Null value was assigned to a property of primitive type setter of com.newve2.Board.pensionTypeId
at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:42)
at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:230)
at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2224)

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 23, 2005 10:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
well, java primitives cannot be null...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 4:40 am 
Beginner
Beginner

Joined: Wed Feb 23, 2005 10:37 am
Posts: 29
But wouldn't it assign 0 if ResultSet.getObject() returns null as it is in Oracle DB if the value is null, then ResultSet.getLong() would be 0`?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 10:51 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
No, because that loses the semantic of the concept of "null" :) zero and null are not the same thing. What would happen if it did do what you suggest, and then later needed to synch that object back to the db? It would see zero and need to write zero back to the database. Again, zero and null are *not* the same thing and now you'd have just lost that semantic in your data.

Look, its simple really. If the corresponding database column can logically contain nulls, you must use the java wrapper types to represent this in your java domain model.

Optionally, you *could* supply custom user type to do what you suggest. But that would not be recommended as, again, you are circumventing the semantics of the data.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 12:22 pm 
Beginner
Beginner

Joined: Wed Feb 23, 2005 10:37 am
Posts: 29
agree, I already started to sync it with DB values.
Thanks for your inputs.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.