Hello All,
I am currently using Hibernate 3.2 with annotations and have a question regarding the use of proxies with entity inheritance.
I ran into unexpected behavior (although now realize I should have expected it) with the use of proxies and entity inheritance.
If I have inheritance B --> A and return an A proxy reference, I will get a ClassCastException since the generate class is an extension of A.
I found some good descriptions of this problem and understand now what is happening. My question is in regards to using interfaces for the proxies instead of concrete classes. Would this would eliminate the problem?
For example :
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
@org.hibernate.annotations.Proxy(proxyClass = A.class)
@Table(name = "A")
public class AImpl implements A, Serializable
@Entity
@PrimaryKeyJoinColumn(name="key")
@org.hibernate.annotations.Proxy(proxyClass = B.class)
@Table(name = "B")
public class BImpl extends AImpl implements B, Serializable
I was curious as to how this would work differently. Would hibernate generate a proxy differently in this case? If a "BImpl" object was loaded
but an "A" proxy was returned, could this be cast to "B"?
Best Regards,
Kurt
|