-->
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.  [ 1 post ] 
Author Message
 Post subject: Possibility to ONLY persist superclass?
PostPosted: Sun Sep 30, 2007 1:43 pm 
Newbie

Joined: Sun Sep 30, 2007 12:59 pm
Posts: 5
Hello everybody,

I have a question about inheritance mapping in Hibernate. I need something like the opposite of the
Code:
@MappedSuperclass
annotation, because I want to persist only the objects of the superclass. I am getting crazy. Please take a look at this 2 simple classes...

Code:
@Entity
public class User implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String login;
    private String password;
   
    ... getter & setter code
}

@Entity
public class RegisterForm extends User {
    @Transient
    private String passwordConfirm;

    ... getter & setter for added field.
}
.

The inheritance I used for convenience. The
Code:
RegisterForm
I only use for password confirmation input field.

When the user submits the form I want to persist the RegisterForm object as a User object in Database. At first I tried something like the following, but it is obvious that it does not work...

Code:
    User user = (User) registerForm;
    userDAO.persist(user);


Is there some easy way to make sure that objects of the subclass are persisted und handled in the exact same way as the superclass?

I also read about the inheritance strategies in hibernate, but these three strategies does not really fit to my problem. I do not want to have an extra table for the subclass and I do not want to have an extra row in my table to distinguish the objects of the superclass from the subclass objects, because they look are the same.

I also thougt about to copy all fields from a RegisterForm object to a new User object and persist it then, but my User class is much bigger than in my example above and there must be another nicer way.

Thank you very much in advance!
Dumbi


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

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.