[jboss-user] [JBoss Cache] New message: "Inconsistent behaviour when fetching cached subclass entities?"
Jimmy Borg
do-not-reply at jboss.com
Mon Feb 22 08:08:54 EST 2010
User development,
A new message was posted in the thread "Inconsistent behaviour when fetching cached subclass entities?":
http://community.jboss.org/message/527588#527588
Author : Jimmy Borg
Profile : http://community.jboss.org/people/jborg
Message:
--------------------------------------------------------------
Hi all,
The use of jboss-cache as hibernate second-level cache is leading to inconsistent behaviour when fetching cached subclass entities as opposed to fetching non-cached subclass entities.
*Scenario*
Consider a simple scenario having a parent entity:
> @Entity
> @Table(name = "tt_test")
> @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
> public abstract class ParentEntity implements Serializable {
>
> private static final long serialVersionUID = 5751958972675892020L;
>
> @Id
> private String id;
>
> protected ParentEntity() {
> super();
> }
>
> public ParentEntity(String id) {
> this.id = id;
> }
>
> public String getId() {
>
> return id;
> }
>
> }
and two subclass entities extending the above entity:
> @Entity
> public final class Subclass1 extends ParentEntity {
>
> private static final long serialVersionUID = -4329753920470094896L;
>
> protected Subclass1() {
> super();
> }
>
> public Subclass1(String id) {
> super(id);
> }
>
> @Override
> public String toString() {
>
> return "Subclass1 [ID={" + getId() + "}, Class={" + getClass() + "}]";
> }
> }
> @Entity
> public final class Subclass2 extends ParentEntity {
>
> private static final long serialVersionUID = -6102575763486357670L;
>
> /**
> * Default constructor (required for hibernation reasons)
> */
> protected Subclass2() {
> super();
> }
>
> public Subclass2(String id) {
> super(id);
> }
>
>
> @Override
> public String toString() {
>
> return "Subclass2 [ID={" + getId() + "}, Class={" + getClass() + "}]";
> }
> }
After persisting an instance of Subclass1 using:
> em.persist(new Subclass1("identifier1"));
Trying to fetch an instance of Subclass2 using:
> em.find(Subclass2.class, "identifier1");
will result in a +null+ return if the entity is not cached. This is the expected, correct behaviour.
However, when the entity with id +identifier1+ is cached, this will match and return an instance (of Subclass1) if the entity is cached. This appears to be both inconsistent behaviour, and a wrong result, as the entity with identifier +identifier1+ is of type Subclass1 not SubClass2, as requested in the call to em.find().
*Environment*
jboss-cache 1.4.1.SP13
hibernate 3.2.5
jboss 4.2.2
--------------------------------------------------------------
To reply to this message visit the message page: http://community.jboss.org/message/527588#527588
More information about the jboss-user
mailing list