• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

[SOLVED] This is going to drive me nuts

 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author
Posts: 422
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 422
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 422
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 422
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 422
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic