• 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

Dynamic Entities in JPA

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All!
First of all, thanks for a great forum. I have learned a lot in here, so now I thought I would ask a question of my own:

Is it in some way possible to create an entity at runtime to hold the result from a given query, in JPA? I am doing a webcrawling project, where I retrieve data and put it into some tables. The tables will have various sizes and number of columns, so I am a little stuck on how to map these differing tables to entities. I do not know the size of the table or the number of rows, before the query has been executed.

Thank you in advance for helping. Feel free to ask questions, if I have not been clear
 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm confused why you mean by 'dynamic entities'. If you define a database structure, populate it with records from a web crawler, you can then run queries on it whether or not you knew the data ahead of time.
 
Lysander Poulsen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah yes, I see I was not clear. I do NOT define the database structure ahead of time. My webcrawler defines the tables it needs, and then puts data in them. Therefore, I do not know the structure of the tables. I only have the table names.
 
Scott Selikoff
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It's hard for me to imagine a web crawler capable of defining the database structure dynamically. Usually (good) database structure requires the care of skilled DBA or programmer. I know I'm a little off-topic, but are you sure you really want to construct it dynamically? It seems like a risky thing to me.
 
Lysander Poulsen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well in this case, the webcrawler is defining the database tables, or at least the ones it uses to store data in. So that is a requirement. Have you got any ideas about how to create the dynamic entities?
 
Saloon Keeper
Posts: 27819
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The main problem I see is using JPA. JPA is fundamentally based on having a predefined record structure, which means that at least one table in your database would presumably be fixed in format at all times.

You can construct classes completely dynamically - in fact JPA commonly re-engineers classes at runtime to add the extra persistency fields it needs. However that's not a task for the faint of heart.
 
Lysander Poulsen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well we found another way of doing it, which does not use JPA, but thank you all for your quick answers
 
reply
    Bookmark Topic Watch Topic
  • New Topic