-->
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.  [ 3 posts ] 
Author Message
 Post subject: problem with inheritance
PostPosted: Tue Jul 15, 2008 8:26 am 
Newbie

Joined: Fri Jul 11, 2008 5:35 am
Posts: 4
Hello everyone.

I have encountered a problem with inheritance mapping. Here is my class hierarchy with annotations:

@Entity
@org.hibernate.annotations.Entity(polymorphism = PolymorphismType.EXPLICIT)
@Table(name = "EXECUTORS")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "IS_GROUP", discriminatorType = DiscriminatorType.INTEGER)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public abstract class Executor

@Entity
@DiscriminatorValue(value = "1")
final public class Group extends Executor

@Entity
@DiscriminatorValue(value = "0")
public class Actor extends Executor

There is the following method in another class:
@ManyToOne(fetch = FetchType.LAZY, targetEntity = Executor.class)
@JoinColumn(name = "EXECUTOR_ID", nullable = false, insertable = true, updatable = false)
@Index(name = "EXEC_GROUP_REL_EXEC_ID_IDX")
public Executor getExecutor() {
return executor;
}

The problem is that whenever this method is called Anonymous inner class of Executor is generated (not Actor or Group). Is there any way to make hibernate generate instances of Executor's subclasses, not of abstract Executor class?

Will be grateful for any help.

Thx in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 21, 2008 11:42 am 
Beginner
Beginner

Joined: Mon Nov 19, 2007 4:40 pm
Posts: 46
I don't use annotations, so this may not apply... but, with the hibernate mapping files, you can specify if the base class is abstract (abstract="true") and that will prevent hibernate from instantiating that class.

Hope that helps.

Paul


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 21, 2008 12:01 pm 
Newbie

Joined: Fri Jul 11, 2008 5:35 am
Posts: 4
Thanks for your response, pppoole.

I managed to solve this problem. The solution was to change fetch type in getExecutor method from LAZY to EAGER.


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