-->
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: Hibernate inheritance problem
PostPosted: Wed Jun 03, 2009 7:10 am 
Newbie

Joined: Wed Jun 03, 2009 6:11 am
Posts: 1
Code:

PERSON Class:
===========
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)

@DiscriminatorColumn(
      name="version"
)
@DiscriminatorFormula("case when version=(select max(p.version) from supervisory_owner.gss_person p where p.prism_id = prism_id) then '1' else '0' end")
@DiscriminatorValue("0")
public class PersonImpl implements Person { }


LatestPerson Subclass of PersonImpl
===========================
@Entity
@DiscriminatorValue("1")

public class LatestPerson extends PersonImpl {
   private static final long serialVersionUID = -5859833321414460749L;
   
   /**
    * The person's prism id.
    */
   @BeanProperty
   @javax.persistence.Column(
         name="prism_id", insertable=false, updatable=false
   )
   private Integer prismId;

   public Integer getPrismId() {
      return prismId;
   }

   public void setPrismId(Integer prismId) {
      this.prismId = prismId;
   }
}

Manager Class:
===========
public class PersonManagerImpl extends HibernatePersistenceManager<Person>
      implements PersonManager {

   public Person byEmailAddress(String emailAddress, Long version)
         throws PersistenceException {
      
         Person test = null;
         DetachedCriteria criteria = getExampleCriteria();
         criteria.add(Restrictions.eq("version.identifier", version));
         criteria.add(Restrictions.eq("emailAddress", emailAddress));
         test = unique(queryByCriteria(criteria));
         return test;

         /*Person testPerson = null;
         String query = "from PersonImpl  p where p.emailAddress = :email and p.version = :version";
         Session session = getSessionFactory().openSession();
         session.beginTransaction();
         Query q = session.createQuery(query);
         q.setString("email", emailAddress);
         q.setLong("version", version);
         testPerson = (Person)q.uniqueResult();
         session.close();
         
         return testPerson;*/
   }
}



1).If i use the person manager to get person object by email address by using criteria its working for all the persons,,,
except only for one person email.. . The person name has special character '.
Note:
-----
Becuase of the descriminator LatestPerson class is get loaded....for all persons it is loading correctly...
but only for that particular person its not loading....


2).but if i use HQL no probelem at all it working also for all persons.....

3).I just try to get person by email in test jsp ... Here also working with out problem


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.