-->
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: InheritanceType.JOINED and Implicit Polymorphism
PostPosted: Fri Dec 09, 2005 2:02 pm 
Beginner
Beginner

Joined: Sat Sep 17, 2005 10:41 am
Posts: 49
Let's say I have the following three entities:

Code:
@Entity (access = AccessType.FIELD)
@Inheritance (strategy = InheritanceType.JOINED)
public class Account
  implements java.io.Serializable
{
  @Basic
  private String userName ;
  @Basic
  private String password ;

   // etc...
}

@Entity (access = AccessType.FIELD)
public class Customer
  extends Account
  implements java.io.Serializable
{
  @ManyToOne
  private Address address

  // etc...
}

@Entity (access = AccessType.FIELD)
public class Admin
  extends Account
  implements java.io.Serializable
{
  @OneToMany
  private Set<Permission> permissions ;

  // etc..
}


I can create one type of account or another, simply by constructing the object and calling:
Code:
  session.saveOrUpdate (new Admin()) ;
  session.saveOrUpdate (new Customer ()) ;


Likewise I can query.

However, what if I have an already persisted Admin object, and I would like to make it also a Customer? How can I make it such that there is one entry in the Account table that corresponds to one entry each in the Admin and Customer tables?

Thanks...


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 10, 2005 1:28 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
how can you change the object class type from Customer to Admin in plain Java at runtime?
This is not possible, hence not in ORMs
You should consider not using inheritance for what you want.

_________________
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.