I'm writing some sample codes in hibernate to understand the association and just started with One-One mapping. I ran into an issue where it says
Below are my codes
Address.java
Student.java
Address.hbm.xml
Student.hbm.xml
The reason which I'm thinking of here is when we say getStudent(), toString() method of Student class invoked as expected and in toString(), we have a reference of Address and it would invoke toString() method defined in Address class. This is getting into the infamous vicious circle of circular reference and finally throwing the error. I'm almost certain on this, as when I print only student name, it is working fine. But it is throwing error, when I try to refer Address from Student object.
My questions
1) Is my understanding of the error correct ? Or is there something else that could have caused the issue (which I'm certainly not hoping for).
2) Are there any hidden caveats in this code, which I should be aware of ?
3) How can this be better designed ?
I'm not sure I understand why you're doing this--can't you just save an object without casting it? The save method, after all, doesn't have specific save methods for each class.
But yes, you're in an infinite loop.
And please don't try to include BB Code markup in source code--surely you can see it didn't have the intended effect.
But some how I'm thinking that this bidirectional association is not correctly designed and there is a high risk of circular dependencies and references. Is there any good approach/industry standard that can be suggested espicially while handling bidirectional assocation.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.
subject: Reason for stack overflow exception while trying to read hibernate managed objects