-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 
Author Message
 Post subject: How do I (Can I?) define an entity for a nonexistent table?
PostPosted: Sat Mar 25, 2006 1:18 pm 
Newbie

Joined: Sat Mar 25, 2006 12:43 pm
Posts: 6
Location: Santa Fe, NM
Hi. I have what seems to be a rather unique problem. I am leading an initiative in my agency to overhaul a rather dated J2EE project which makes extensive use of embedded JSP Java, JDBC/SQL, and BMP entity beans.

The RDBMS belongs to the public branch of our state agency, and as such, our IT department is not allowed to make schema changes. However, we have several tables (phone, printer_users, security) that have a "user_id" column. This is, semantically, a foreign key to nothing, since we handle our web logins via a transient SSH session to our UNIX server.

However, I would like to have a "User" entity that knows about all the entities that refer to a particular user_id, for convenience's sake. Problem is, none of the tables has a complete set of all the user ids. I can collect the user ids using a SQL UNION statement, but as I cannot touch the database schema, I can't create a view for the entity to point to.

I played with the idea of using a NamedQuery or NamedNativeQuery for the User entity, but as there is no users table, I cannot use User in association mappings, and must invoke the query any time I want to convert a user id to a User object.

I've also thought about having PhoneUser extend PrintUser which extends SecurityUser, mapping user_id as the Id field, but again, no table's collection of user_ids is a complete superset or subset of any other, and to complicate things, in the security table the primary key is a composite of the table_name and user_id columns, and in the phone table, some duplicate records exist for a few user_ids.

Is there a way to simulate some kind of virtual table or view, not at the database level but visible as far as Hibernate is concerned, that I can map the User entity to? If I'm barking up the wrong tree here, any advice would be helpful. Thanks in advance.

Derek

Hibernate version: 3

Mapping documents: hibernate.cfg.xml and annotations

Code between sessionFactory.openSession() and session.close(): Using Seam to manage sessions

Name and version of the database you are using: Informix (version unknown)

_________________
Life would be simpler if I only had the source code.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 27, 2006 7:46 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
You can use HSQL (hsqldb.org) with C-JDBC (c-jdbc.objectweb.org) and your existing DB.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 29, 2006 5:21 pm 
Newbie

Joined: Sat Mar 25, 2006 12:43 pm
Posts: 6
Location: Santa Fe, NM
OK - the problem with that approach is I then can't do table joins from tables in two different databases unless I use RAIDb2 - and then ridiculous amounts of time are spent copying data from the various tables to the HSQLDB database. So I can't do associations between entities coming from different databases, which is something I need to be able to do.

Am I not seeing an easier solution here?

_________________
Life would be simpler if I only had the source code.


Last edited by dberner727 on Thu Mar 30, 2006 6:26 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 2:41 am 
Expert
Expert

Joined: Sat Oct 25, 2003 8:49 am
Posts: 490
Location: Vrhnika, Slovenia
Create the fake ones on HSQL.
Then use C-JDBC so that both your DBs look like a single DB.
Then you can do joins.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 5:52 pm 
Newbie

Joined: Sat Mar 25, 2006 12:43 pm
Posts: 6
Location: Santa Fe, NM
Quote:
Create the fake ones

You mean create fake tables on HSQL? I was under the impression that C-JDBC required the data to already be present in both databases. Or does it just migrate the data that it needs so HSQLDB acts as a database cache??

It's still a massive task; we have over 250 tables and views, some with 50+ columns. And since HSQLDB runs by default in memory we'll have to recreate the schema every time we restart the app server. I could automate this with ResultSetMetaData but that's still pretty tricky.

_________________
Life would be simpler if I only had the source code.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 04, 2006 12:58 pm 
Newbie

Joined: Sat Mar 25, 2006 12:43 pm
Posts: 6
Location: Santa Fe, NM
From the Sequoia (C-JDBC) documentation:

"Distributed Joins are not supported".

I cannot do joins on separate databases, even with C-JDBC/Sequoia.

_________________
Life would be simpler if I only had the source code.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.