Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Breaking one table into two Entity Beans

 
Sheriff
Posts: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on an EJB 3 project where I need something where there is information related to a person. There are a lot of information like DOB, homepage, like, dislike etc. Now I want to retrieve a list of all users. But due to a lot of information, the page renders very slowly. So I want that when someone views a list of users, then only the first name and last name should be retrieved from the database. When someone sees the profile of the user, then only the full information of the user must be retrieved.

For this I thought that @Embedded should be great. But I didn't find much detail about embedded fields in any book. I thought that I would lazily load the embedded field. I don't know if that is possible or not. Also I am not sure how would the embedded field will be updated. So I am stuck now.

If embedded is not the solution, then I can go for one to one mapping. I can split the table into two also. So please suggest me the best way of solving this problem.

Also can I have 10 columns in the database and have two separate java classes which map to different columns of the same table using EJB 3. This may sound stupid as I don't know if this is possible or not.

Thanks in advance...
 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried mapping two classes, with different levels of detail, to that one table?
 
Ankit Garg
Sheriff
Posts: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Edvins. Well I have not tried this. This seems a good solution. But I don't know how to do this. Is it done by creating two entities and having less fields in one of the entities and all the fields in the other. If yes then how will I use queries with entity manager to manipulate the entity?? Can anyone give me a sample of how to do this or some internet tutorial...
 
Ankit Garg
Sheriff
Posts: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I made it work. Thanks Edvins. The idea was enough for me to do it . I never thought about that. I was thinking about embedded objects and one to one mapping :XD: . Now the performance of my code has increased many folds.

Thanks again...
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Edvins Reisons wrote:Have you tried mapping two classes, with different levels of detail, to that one table?



That is a dirty trick but works. Cool idea.
Another option could be simply to have the data spread over two tables in 1 to 1 realation to each other, that share the primary key.
 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ankit,

It seems that you have found a way to map two classes to one table. Could you please share how you made it possible? I have a similar situation in my project. I also am using EJB3 and similar situation to yours.

Thank you.
 
Hitesh Rathod
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got my answer .... thanks :-)
 
Ankit Garg
Sheriff
Posts: 9671
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Hitesh I saw this very late. But still if you need any help you can ask me. Debbie it seems you are right. One of the senior person scolded me for using this design saying that it is a bad design for future changes. I don't know what he meant by that but at least it works for now
 
Water proof donuts! Eat them while reading this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic