This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Creating Tables using JPA

 
vinay abhishek
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am developing a web application to count the hit rate of websites that a user is interested in. My application can host multiple users. so each user is supposed to have his own table in the database that stores his websites and their corresponding count. My idea is to automatically generate a table in the name of the user once he/she signs up with the application. How can this be possible using Java Persistence API?.............. Please help
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why would each user need their own table rather than a row in a single table?
 
vinay abhishek
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because each user would have his own list of Websites and their respective counts, I thought generating a table with two colums (website, count) for each user would be a good idea to ingest and retrive data . Please correct me if I am wrong
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm still not getting why you think you need multiple tables rather than a single table. Each row in a single table can identify which "user" the row is referring to.
 
vinay abhishek
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great. Now I understand. Thank you
 
Ben Morse
Greenhorn
Posts: 7
Chrome MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would create a table of users, a table of websites, and a mapping table. The user table has data about the user, and in integer primary key. The website table has a varchar for url, and an integer primary key. The mapping table can be a ManyToMany in JPA, or you can do it manually with an integer primary key, and then two foreign keys, one for users, and one for websites.

Each time you see a totally new website, add a row to the websites table, and add a row to the mapping table.
Each time you see an existing website, you only need to add a row to the mapping table.

Does this make things more clear?
 
vinay abhishek
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Definitely Sir I am working on it. Thanks for the word.
 
Ben Morse
Greenhorn
Posts: 7
Chrome MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok cool! Post back if you need more help
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic