This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes EJB and other Java EE Technologies and the fly likes how to perform query on multiple tables dynamically? tables that has no mapped entity Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "how to perform query on multiple tables dynamically? tables that has no mapped entity" Watch "how to perform query on multiple tables dynamically? tables that has no mapped entity" New topic
Author

how to perform query on multiple tables dynamically? tables that has no mapped entity

raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
Hi
Thank you for reading my post
My question is mostly technical and i want to know whether EJB 3.0 can do this or not.
we have an application which we are going to port it to EJB 3.0 from plain JDBC.

in our application, we have tables which are created after we complete the code, those tables contains some data which we do not know about its fields and.... in our application design time.

what we have in runtime is a set of metadata that describe those tables, for example thier fields and .....


now we want to be able to query those table with EJBQL , meanwhile we have no entity mapped for those table because they are created after we designed the application,

What i want to know is:
-how we can query them,
-what will be the query result? it is a collection? if it is a collection, then what are collection elements?

Thanks
[ December 16, 2006: Message edited by: raminaa niilian ]
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Well, there are two different options, if you do not map them, then it will be a two dimenstional Object array, Object[][].

Mark

so there is only one option. I was going to suggest mapping them programatically.


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
Thank you very much for reply.
-can you please explain about mapping them programatically?
-How much effort it will need to map them programatically if we have access to mapping files for those table in runtime?
-one more important thing, what will happen when we need to excute a query which include two type of objects?

Thanks
raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
Any extra comment ?
thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Well, the Configuration and SessionFactory object can be modified programatically, there is an API.

"one more important thing, what will happen when we need to excute a query which include two type of objects?"

Can you query on two types of tables and union those queries together? It is kind of the same question. Do they have fields that relate to each other, same structure. If not, you will need two seperate queries. There is too many questions about what youa re doing to be able to completely ansewr your questions.

Mark
raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
Thank you for the hint about Session Factory and configuration,
another question is :
how we can generate Java classes on the fly to map them with tables and add them to configuration object?


thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

"how we can generate Java classes on the fly"

Exactly, unless you can through Reflection, or the Class object, which I don't recall that you can do this, but I haven't really looked or wanted to try this.

Mark
raminaa niilian
Ranch Hand

Joined: Jul 14, 2005
Posts: 551
Thank you sheriff,
I searched about reflection and byte code engineering and i find some libraries that make using reflection easier.

Also i thought that hibernate can generate entity from database, maybe i can use this functionality of hibernate to generate those classes from Tables on the fly.

is it a good suggestion?

thanks
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Well, something interesting that I saw today in the code of Hibernate, is that they have classes that utilize Javaassist to instrument byte code where you can add attributes and methods. Kind of cool.

I still doubt that you will find a solution for your problem of mapping to objects that are defined at runtime.

Mark
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how to perform query on multiple tables dynamically? tables that has no mapped entity
 
Similar Threads
J2EE Design Question -- Am I On The Right Track?
Pass JPA entities across tiers?
dynamic entity beans
Use of @SecondaryTable in EJB3.0
Hibernate - Slow Query on Entity Superclass