wood burning stoves 2.0*
The moose likes Other Application Frameworks and the fly likes [SOLVED] This is going to drive me nuts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "[SOLVED] This is going to drive me nuts" Watch "[SOLVED] This is going to drive me nuts" New topic
Author

[SOLVED] This is going to drive me nuts

Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

I have been staring at this for 2 days and I am about to go insane. I have several dropdowns on a page that are populated from a database. Every single one of them works, except 1. And it worked fine before I started using Spring.

All these dropdown values are pulled from tables that have 2 columns. So for the one that is not working I have

hardware_id | hardware

All the other tables are the same except replace hardware with whatever you need it to be. Anyway, for some reason, when the values are pulled it is pulling the hardware_id for both id and hardware in my pojo. And I have no idea why. I have compared class after class to see if I was typing something in wrong or what. I have pulled the same code into a completely seperate app and it does the same thing. So the last resort is to show all my code here and hope that someone can tell me what is going on.

Bare with me, there are several classes. I will try and only put those that I think are significant.







And here is where I am populating the dropdown


Keep in mind that all this code is identical to, say, the code to pull out the Workstations, Monitors, etc. The only difference is the word hardware where applicable. My eyes hurt.

If you need any more information, let me know.
[ March 17, 2005: Message edited by: Gregg Bolinger ]

GenRocket - A Test Data Generation Platform
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
Originally posted by Gregg Bolinger:
Anyway, for some reason, when the values are pulled it is pulling the hardware_id for both id and hardware in my pojo.


I'm unclear what you mean by this. Could you expand on this statement?


Spring in Action - Unleash POJO power in your applications!
Modular Java - Discover the secret weapon to modularity on the Java platform!
XDoclet in Action - Your complete guide to code generation with XDoclet.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Originally posted by Craig Walls:


I'm unclear what you mean by this. Could you expand on this statement?


The data in the database looks like

hardware_id | hardware
----------------------
1 | -Not Applicable
2 | Motherboard
3 | Harddrive

However, instead of:

hardware.getId() | 2
hadware.getHardware() | Motherboard

I get 2 for both the Id and hardware (which is just hardware name). Here is a screenshot:

http://www.embeddedthought.com/gregg/screen.png

Hope that helps to clarify.
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
Originally posted by Gregg Bolinger:
I get 2 for both the Id and hardware (which is just hardware name).


Okay, I understand your problem now. Not sure I know what's causing it, but I do understand it.

First, are you sure you get 2 both when you call getId() and getHardware()? Have you put in a debug to print/log the results for each?

Second, I see that you're using Hibernate. What's the Hibernate mapping file look like for those two properties?

Finally, it looks like you're using JSF for the presentation...what does the JSP look like that displays that select box?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Originally posted by Craig Walls:


Okay, I understand your problem now. Not sure I know what's causing it, but I do understand it.

First, are you sure you get 2 both when you call getId() and getHardware()? Have you put in a debug to print/log the results for each?

Second, I see that you're using Hibernate. What's the Hibernate mapping file look like for those two properties?

Finally, it looks like you're using JSF for the presentation...what does the JSP look like that displays that select box?


Yes, I have done System.out's to make sure it is putting the ID in both properties. It is *very* strange. Especially since I am doing the exact same thing with all the other dropdowns on that page and they all work fine.

And here is the code. Thanks for looking at this Craig.



Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
I'm stumped...but let me have you try a few things just to see what happens.

First, when you lookup a specific Hardware instance (using the other methods in your DAO class) do you have the same problem?

Second, try changing your getHardwareList() method to look like this:



This should be functionally equivalent...Does the same thing happen?
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Originally posted by Craig Walls:
I'm stumped...but let me have you try a few things just to see what happens.

First, when you lookup a specific Hardware instance (using the other methods in your DAO class) do you have the same problem?

Second, try changing your getHardwareList() method to look like this:



This should be functionally equivalent...Does the same thing happen?


Interesting...

I changed the getHardwareList() and received the same results. I also tried the other methods in my HardwareDAOHib class and they all do the same thing whether I get the hardware by the name of id. So I would have to assume that there is something messed up in the Hibernate side of things. But my mapping file is correct and that's about the only thing Hibernate deals with that is different from the other files. I mean, it is just strange that this class is the only one that doesn't work out of 10 of them or so. I'll keep looking into my code. Thanks for the help Craig.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

So I decided to try something else. I have another page that displays current issues. So I wondered what would happen when I pulled the hardware data out of the current issue since my issue mapping file has a many-to-one mapping for Hardware. All my hibernate stuff worked fine when I was handling the session all myself. This only started happening since I started using Spring. In my jsf page I do



When I do this I get the following error:



I am off to search the hibernate and spring forums for similar errors to see what they have to say about it.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

I should mention also that I am using Hibernate3 and I downloaded the latest CVS of Springs H3 support classes. All my imports are importing the correct springframework.orm.hibernate3 classes.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Ok, update. I solved the Hibernate ERROR LazyInitializationException problem by specifying lazy="false" on the class declaration since in H3 it defaults to true.

With that being said, my Issue object that loads a Hardware object through it via the relationship in the mapping file..The Hardware object has the ID for both properties, just like on the New Issue page. Ugh! I'm tired...
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
Originally posted by Gregg Bolinger:
I should mention also that I am using Hibernate3 and I downloaded the latest CVS of Springs H3 support classes. All my imports are importing the correct springframework.orm.hibernate3 classes.


Okay, this is where you've lost me. I've not yet tried Hibernate 3 in any way whatsoever (with Spring or without Spring). Spring's support for Hibernate 3 is still not quite production-ready, so that's probably where the problem is. Furthermore, Hibernate 3 is still pre-release, so there could still be some quirks.

I'm sorry I can't help you much more with this...I just haven't had the opportunity to work with the Hibernate 3 stuff yet. I have it in my big queue of things to look at, but haven't gotten to it yet.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

Solved you say? But how? I dropped Hibernate. I am using iBatis now instead. Ok, actually, I only replaced hibernate for my hardwareService to see if that solved the problem. And it did. The cool thing?? Not including the iBatis config files, I had to create 1 extra class. My iBatis implementation of my HardwareDAO class. Then I just wired up the beans in applicationConfig. I didn't have to touch a single class that uses the service. Now that rocks!
Craig Walls
author
Ranch Hand

Joined: Sep 19, 2003
Posts: 301
Originally posted by Gregg Bolinger:
Solved you say? But how? I dropped Hibernate. I am using iBatis now instead.


That's one way to do it. I was wondering if dropping Hibernate 3 in favor of Hibernate 2.1 would've yielded a success. With H3, you have two questionable pieces: H3's pre-production status and Spring's alpha support for H3. With H2.1 you have tried and true pieces (I can personally vouch for a dozen or so projects).

Originally posted by Gregg Bolinger:
The cool thing?? Not including the iBatis config files, I had to create 1 extra class. My iBatis implementation of my HardwareDAO class. Then I just wired up the beans in applicationConfig. I didn't have to touch a single class that uses the service. Now that rocks!


A-ha! Isn't loosely coupled code a great thing? Many thanks to Spring IoC and the use of interfaces!
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15286
    
    6

It was a lot easier to throw in iBatis (already had the config files really) than to go through and refactor H3 back to H2 (mainly just imports and DTD's).

I went ahead and did that though, just to see and it worked great. I was going to grab the latest nightly of Springs H3 Support classes, but I think it will be safer for me to stick with H2 for now until I know the bugs have been worked out between H3 and Spring.

Craig, thank you so much for the aid in this. I'm glad you chose to stick around after your book promotion.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [SOLVED] This is going to drive me nuts
 
Similar Threads
Refactoring Suggestions
Problems using Hibernate Criteria API
Hibernate Annotation Non Primary Key Foreign Key Mapping with VARCHAR data type
Persisting pojo with collection attribute using Hibernate
Foreign key value null if nullable true in @OneToMany assoc