• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Can't retriev data from dataBase using hibernate.

 
Greenhorn
Posts: 9
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Guys! I've just started to learn hibernate and spring. And now I am trying to create simple WEB application using this monsters. But right now I am stacked with little problem. I can't retrieve data from existing database table.
here some code

My entity Bean (I think that problem is here)


Implementation of DAO


Here is some xml - configurations for Spring


My DataBase Tables
TRAINING.PERSON


TRAINIG.USERS

I am using IBM WebSphere Application Server, Spring 3.2.9 and hibernate 4.3.6 Final Relies, Data Base is IBM DB2. It is not whole source code, because I've configured my app with spring to work with plain old JDBC
Sorry for long post and numerous of grammar mistakes.
Hope you'll explain where the problem is.
 
Bartender
Posts: 3648
16
Android Mac OS X Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mentioned you were able to get the results without Hibernate (eg using JDBC with Spring). Correct? How does Hibernate code/config files affect the approach?

Also I doubt you need a transaction in your getUsers() method.

You may want to check out hibernate query criteria
 
Oleksandr Mykhailov
Greenhorn
Posts: 9
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

K. Tsang wrote:You mentioned you were able to get the results without Hibernate (eg using JDBC with Spring). Correct? How does Hibernate code/config files affect the approach?

Also I doubt you need a transaction in your getUsers() method.

You may want to check out hibernate query criteria



Yes I am not sure if it is nice way to use it (and is it Realy JDBC. I was told that this is it and that's all) but here is some code

About approach. Hibernate actually didn't has any effect on other parts of program and I was working the way i did before.(Not sure if is what you asked for)
Thanks for the link I'll check it out. And Sorry for headache.
 
Rancher
Posts: 4801
50
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your SecondaryTable annotation doesn't seem to have the mapping between your primary and secondary tables.

Something like:


Note, untested, so you'll probably need to double check with the JPA docs.

ETA: Not that this is necessarily your problem.
 
Oleksandr Mykhailov
Greenhorn
Posts: 9
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:Your SecondaryTable annotation doesn't seem to have the mapping between your primary and secondary tables.

Something like:


Note, untested, so you'll probably need to double check with the JPA docs.

ETA: Not that this is necessarily your problem.


Thanks, Dave! Now I see where the problem is. Also I've noted that I've forgot to set package scan enable for my SessionFactory. But does it actually important in this case?
 
Oleksandr Mykhailov
Greenhorn
Posts: 9
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank for replays I've already received. I think I've figured out where the problem is.
First, I didn't make package with my entity visible for hibernate sesionFactory.
I've add this to mySesionFactory bean in xml.
Also I've made some changes to entity


But still I am getting Eror

I wasn't able to find any information why this is happening and how to fix it. Please help.
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I think that should be mapping to PERSON_ID?
Isn't that the correct FK column on the USERS table?
The above is mapping to the PK ID column, which doesn't relate to the PERSON ID column.
 
Oleksandr Mykhailov
Greenhorn
Posts: 9
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:

I think that should be mapping to PERSON_ID?
Isn't that the correct FK column on the USERS table?
The above is mapping to the PK ID column, which doesn't relate to the PERSON ID column.



Sorry my bad. Yeah I've correct it but no changes happens still getting same error. I'm going to put my mapping to separate xml, but as far as i understand it wont effect much.
 
Oleksandr Mykhailov
Greenhorn
Posts: 9
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem is solved. I've moved my mapping to separate xml file and I saw a miracle - everything is working fine now, but I can not understand why!
Please explain me why with this xml everything is working, and how should I've done mapping using annotation.
 
Without deviation from the norm, progress is not possible - Zappa. Tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic