• 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

Creating Tables using JPA

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great. Now I understand. Thank you
 
Greenhorn
Posts: 7
MySQL Database Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Definitely Sir I am working on it. Thanks for the word.
 
Ben Morse
Greenhorn
Posts: 7
MySQL Database Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok cool! Post back if you need more help
 
reply
    Bookmark Topic Watch Topic
  • New Topic