-
1. Re: Polymorphism and properties
lvdberg Sep 10, 2010 3:41 PM (in response to beligum.b.beligum.org)Hi,
Try using a get Method for selectedProfile and see if the
standard
way works.#{pageManager.selectedProfile.dormAddress}
The Hibernate JavaAssist (the Query) is not the same as the JSF-one.The JSF error states that it has a Person and Not a Student.
Leo
-
2. Re: Polymorphism and properties
beligum.b.beligum.org Sep 11, 2010 11:21 AM (in response to beligum.b.beligum.org)Hmm, no doesn't seem to work..
This is the code I'm using:
public Person getSelectedProfile() { Person retVal = (Person)this.entityManager.createQuery("SELECT DISTINCT p FROM Person p " + " LEFT JOIN FETCH p.picture " + " LEFT JOIN FETCH p.resume " + " LEFT JOIN FETCH p.idCard " + " WHERE p.id=:profileId") .setParameter("profileId", this.selectedProfileId) .getSingleResult(); return retVal; }
I thought polymorphism was supposed to work transparently?
Strange thing is, when I put a breakpoint at
return retVal
, I'm seeing a Person object with a org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer (handler property) containing a Student target-object with all the right fields initialized.Is there something wrong with my lazy loading or something?
b.
-
3. Re: Polymorphism and properties
lvdberg Sep 11, 2010 7:37 PM (in response to beligum.b.beligum.org)Hi,
have you checked the entry in the DB and can you see the generated SQL ?
Because a stared at your code, but I can't see anything strange! The only thing is the Layinitalizer stuff, which looks strange because everything is inside the same table (unless you have defined properties with lazy loading with @Basic)
Leo
-
4. Re: Polymorphism and properties
beligum.b.beligum.org Sep 12, 2010 7:47 PM (in response to beligum.b.beligum.org)Whow.. I traced this back to the presence of an rss (Atom) feed in the header of the page.
When I include this line of html in the header of a page that loads a polymorph object, it went wrong:
<link rel="alternate" type="application/atom+xml" href="blah.rss" />
Could this be a (very) obscure bug?
-
5. Re: Polymorphism and properties
nuuh Sep 23, 2010 11:49 AM (in response to beligum.b.beligum.org)Hi,
I have Employee, Manager.. entityes
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "EmployeeType", discriminatorType = DiscriminatorType.CHAR)
@DiscriminatorValue("E")
@Table(name = "employee")
public class Employee implements Serializable {}
--------------
@Entity
@DiscriminatorValue("M")
public class Manager extends Employee implements Serializable {
--------------
in user table i have OneToOne Relation with Employee entity
and when user login to system i have to know what is the what is the employee tpye?
like 'E' or 'M'
i tryed like that:
System.out.println("TYPE:"+this.user.getClass().getSimpleName().toString());
System.out.println("TYPE:"+this.user.getEmployee().getClass().getSimpleName().toString());
first is gived to me class name but i didnt take class name from second code..
i am waiting your answer.. thanks.. -
6. Re: Polymorphism and properties
nuuh Sep 23, 2010 12:11 PM (in response to beligum.b.beligum.org)i found my problem..
i used the same way what i wrote befoure comment..
so if you need you can use this way :) -
7. Re: Polymorphism and properties
lvdberg Sep 23, 2010 12:13 PM (in response to beligum.b.beligum.org)Hi,
Hopefully I understand you but you should define the class hierachy in another way. You can define the class User and Employee and Manager extend the User. Or - far better approach - have a User only and define a Role class.
There should be a ManyToMany between User and Rols. So everybody is employee, but the Manager has an additional Role. This way you will not have problems with the AuthenticationManager as provided by Seam. If you take this path, you can additionally use the Seam annotations for User and Role (see the documentation under security)
Leo