views:

20

answers:

0

Summary:

I have two projects using the same database relation. I would like to map the relation differently in each project, using the same child class but different parent classes.

Detail:

I have two projects, ADMIN and SERVICE. ADMIN allows the persisted object Promo to be configured. SERVICE will read Promo. We're using Spring 3.0 and Hibernate 3.5.1.

To use ADMIN, a user must be logged in as a User, which is a persisted Object. Promo.user is the most recent User to edit Promo.

pseudo code:

class User {
@Id Integer id;
String name;
String encryptedPassword; }

class Promo {
@Id Integer id;
@ManyToOne(targetEntity=User.class) User;
String promoData; }

Both tables are Read/Write for ADMIN, and Read Only for SERVICE. ADMIN and SERVICE must work if they're on the same server or different servers.

My goal is to hide User.password from SERVICE.

My favorite solution would dynamically configure the @ManyToOne targetEntity. Promo.User could become an interface and its implementing class could be dynamically configured. This would require two classes and one table. I'm stuck on how to make that happen.

My hack solution in the meantime is to create a special view UserForService for the User table that blanks the password, and use a NamingStrategy in SERVICE that renames User to UserForService. This requires one class and two tables (table and view).