-->
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.  [ 6 posts ] 
Author Message
 Post subject: Interceptor.instantiate and default constructors
PostPosted: Tue Sep 28, 2004 2:39 pm 
Newbie

Joined: Mon Sep 13, 2004 6:02 pm
Posts: 12
Location: Seattle, WA
Hibernate version: 2.1.6

Is it really necessary that AbstractEntityPersister in its constructor enforce persisted classes provide a default constructor? I'm in a scenario where I'm persisting some classes that don't/can't have a default constructor, but I'm using an Interceptor instance that uses the instantiate method to create the instances for these classes. It works great, but I can't use the standard EntityPersister, since it requires any non-interface/abstract class to provide a default constructor.

Based on my reading of various Hibernate documents, the "default constructor" requirement seems like a fundamental tenet of Hibernate use. But this seems unnecessary, given the availability of Interceptor.instantiate and that AbstractEntityPersister adequately handles interfaces and abstract classes, which clearly provide no default constructors.

My workaround for this was to create my own ClassPersister implementation that looks eerily similar to EntityPersister + AbstractEntityPersister. Its only difference is that it doesn't throw an exception if the persisted class doesn't provide a default constructor; it just sets the constructor field to null.

I'm not terribly fond of this solution, even though it works great, since I'm basically duplicating the whole of EntityPersister. There doesn't seem to be an easy way around this, since the contstructor requirement is in AbstractEntityPersister's constructor; there's no method to overload or setting to change. Thus, I think it could constitute a bug, but I thought I'd discuss it in the forum first to make sure there's no fundamental Hibernate issue that I'm violating or not understanding completely.

Any comments appreciated.

-Scott


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 28, 2004 7:19 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
That probably would be a good chance for a JIRA entry, perhaps including a patch?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 28, 2004 7:24 pm 
Newbie

Joined: Mon Sep 13, 2004 6:02 pm
Posts: 12
Location: Seattle, WA
I'd love to provide a patch, but I'm not sure what the expected behavior should be. Given that current code assumes non-interface classes should have default ctors, and that if they don't they fail early (i.e., at persister creation), I'm not sure if the correct behavior (for everyone) should be to only fail if the constructor is needed and not available, or if some other configuration should be set to override the current behavior. If failing "late" is acceptable, the fix is straightforward.

I guess I'll open the bug and submit the "late failure" patch. If the Hibernate team decides that a different fix is more appropriate, then at least they'll see what one proposed solution looks like.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 28, 2004 7:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
IMHO (little bit drunk right now:) it should be acceptable to fail "late" and just throw an error about a missing default constructor if the class can not be instantiated by Interceptor.instantiate(). So I'd try with a JIRA entry on this one.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 28, 2004 7:29 pm 
Newbie

Joined: Mon Sep 13, 2004 6:02 pm
Posts: 12
Location: Seattle, WA
Awesome. Will do.

Enjoy your evening!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 29, 2004 4:41 pm 
Newbie

Joined: Mon Sep 13, 2004 6:02 pm
Posts: 12
Location: Seattle, WA
For those that may be following this issue, here's the bug I entered:

http://opensource.atlassian.com/projects/hibernate/browse/HB-1243


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.