-->
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.  [ 2 posts ] 
Author Message
 Post subject: Design question for using Abstract classes
PostPosted: Mon Feb 12, 2007 1:14 pm 
Newbie

Joined: Fri Oct 17, 2003 11:31 am
Posts: 19
I've got a question to see if there's a better way to design the following simple example (I've got more complex tables, but this is a good example):

I have a User database table with the following columns :
id
first_name
last_name

And what I want to have is a UserBase class, and a User class. The User class will have accessor methods that are used by the UI. Following is an example of the code :


Code:
@Entity
@Table(name = "USER")
public abstract class UserBase implements java.io.Serializable {
    protected String firstName ;
    protected String lastName;
    // appropriate getFirstName and getLastName methods

}

public class User extends UserBase {

    // Put any transient methods / variables here   

    public String getFullName() {
        return firstName + ", " + lastName;
    }

}


I have tried using @MappedSuperclass on my UserBase class, and then using @Entity on my User class, the problem is that then Hibernate expects me to have a database column associated with the fullName field on my User class.

I've also tried marking my getFullName() with @Transient, which seems to work fine, but my question is whether or not there's a better way to implement this pattern. I'd prefer not to have to mark all my methods in my User class with @Transient, it just doesn't seem like a clean design.

Any help / suggestions would be greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 15, 2007 7:02 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
@mappedsuperclass and @Transient seem the right choice for me

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.