File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Creating Tables using JPA Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Creating Tables using JPA" Watch "Creating Tables using JPA" New topic
Author

Creating Tables using JPA

vinay abhishek
Greenhorn

Joined: Nov 23, 2012
Posts: 18
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

Joined: Jan 10, 2002
Posts: 60049
    
  65

Why would each user need their own table rather than a row in a single table?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
vinay abhishek
Greenhorn

Joined: Nov 23, 2012
Posts: 18
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

Joined: Jan 10, 2002
Posts: 60049
    
  65

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

Joined: Nov 23, 2012
Posts: 18
Great. Now I understand. Thank you
Ben Morse
Greenhorn

Joined: Dec 01, 2012
Posts: 7

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

Joined: Nov 23, 2012
Posts: 18
Definitely Sir I am working on it. Thanks for the word.
Ben Morse
Greenhorn

Joined: Dec 01, 2012
Posts: 7

Ok cool! Post back if you need more help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Creating Tables using JPA
 
Similar Threads
servlet and jdbc (urgent)
To check if failed attempts is more than 5 within 24hrs
How many Session Objects ??
Invisible Website Hit Counter
How to develop a secure website