-
1. Re: access to inherited properties of entity-ejbs
gavin.king Feb 1, 2006 10:08 AM (in response to paper)I don't understand the question.
-
2. Re: access to inherited properties of entity-ejbs
paper Feb 1, 2006 1:22 PM (in response to paper)I've a entity EJB "Resource" and a class "Room" which extends Resource. In the beta1-Version I can't access properties of the Resource-part of an Room-object. The getters/setters are all public.
Should this be possible? Is this a problem in my code?
I thought, I'd read something about this problem ... can't find it ...
Greetings
Dennis -
3. Re: access to inherited properties of entity-ejbs
paper Feb 9, 2006 11:28 AM (in response to paper)Now i do it by overriding the getters/setters of the superclass, but annotated as @Transient. Now Seam provides access to the properties of the superclass to JSF-Pages.
Ar there other solutions?
Greetings
Dennis -
4. Re: access to inherited properties of entity-ejbs
gavin.king Feb 9, 2006 1:29 PM (in response to paper)Have you read the section of the Hibernate documentation which describes the caveats of using proxies for lazy fetching?
You need to. -
5. Re: access to inherited properties of entity-ejbs
paper Feb 9, 2006 2:32 PM (in response to paper)Hmm, I cant find anything about lazy fetching, proxies in relation to inheritance. Could you point me to the chapter?
I can access the resourceId (by getter on subclass) in the SFSB which implements the JSF-actionMethod.
Without the ### marked Block in the subclass i get an:
Bean: org.termtimer.model.Room, property: resourceId (not accessible!)
To avoid the transient methods I tried:
- to set "strategy=InheritanceType.JOINED" in subclasses
- to use "@org.hibernate.annotations.Entity(polymorphism = PolymorphismType.EXPLICIT)" in the superclass
(also i can't see any polymorphism in this case)
To me it seems that seam doesnt recognize the inherited getters and so cant access the corresponding properties.
Thanks for any help
Dennis@Entity @Inheritance(strategy=InheritanceType.JOINED) abstract class Resource implements Serializable{ private int resourceId; private int version; public Resource(){ } @Version public Integer getVersion() { return version; } public void setVersion(int version) { this.version = version; } @Id (generate = GeneratorType.AUTO) @Column (name = "id") public int getResourceId() { return resourceId; } public void setResourceId(int resourceId) { this.resourceId = resourceId; } @Destroy @Remove public void destroy() { } } ______________________________________________ @Entity @Name("room") @Scope(SESSION) @Inheritance public class Room extends Resource { private String roomNumber; public Room() { super(); } //### is this part needet? ###### @Transient public int getResourceId() { return super.getResourceId(); } public void setResourceId(int resourceId) { super.setResourceId(resourceId); } //############################### @Length(min = 1, max=100) public String getRoomNumber() { return roomNumber; } public void setRoomNumber(String roomNumber) { this.roomNumber = roomNumber; } @Destroy @Remove public void destroy() { } }
-
6. Re: access to inherited properties of entity-ejbs
gavin.king Feb 9, 2006 2:36 PM (in response to paper)http://www.hibernate.org/hib_docs/reference/en/html/performance.html#performance-proxies
Basically, if you *lazily* retrieve an instance of a subclass, by specifying the superclass type in the getReference() method, or navigation of an association of the superclass type, you will not be able to downcast.
So simply re-retrieve the same instance using find(), and you will have an instance of the subclass. -
7. Re: access to inherited properties of entity-ejbs
paper Feb 9, 2006 3:05 PM (in response to paper)Thanks for the fast reply.
I'm quite new to JBoss and related things and hope my questions aren't annoying.
The problem isn't related to casting I guess, just in accessing inherited parts.
I use:rooms = (List<Room>) em.createQuery("from Room").getResultList();
Form the Entity-Manager-Reference about "getResultList()":
A query is usually executed by invoking getResultList(). This method loads the resulting instances of the query completly into memory.
This doesn't mean there aren't used proxies. I can't use find here, but what can I do?
Thanks
Dennis
In the SFSB I've:@DataModel private List<Room> rooms;
and in the Facelet:
<h:dataTable value="#{rooms}" var="theroom" rendered="#{not empty rooms}">
<h:column>
<f:facet name="header">roomNumber</f:facet>
#{theroom.roomNumber}
</h:column>
<h:column>
<f:facet name="header">resourceId</f:facet>
#{theroom.resourceId}
</h:column>
<h:column>
<f:facet name="header">Action</f:facet>
<h:commandLink action="#{RoomAction.deleteRoom}">delete</h:commandLink>
<h:commandLink action="#{RoomAction.editRoom}">edit</h:commandLink>
</h:column>
</h:dataTable> -
8. Re: access to inherited properties of entity-ejbs
gavin.king Feb 9, 2006 3:07 PM (in response to paper)The you have done something else wrong. A query does not return proxies. All objects should be instances of Room.
-
9. Re: access to inherited properties of entity-ejbs
paper Feb 9, 2006 5:06 PM (in response to paper)Ehm, yes. Lookes like.
now i've tested to set the annotations@Name("resource") @Scope(SESSION)
to the superclass "Ressource"
and to use the seam propagation to jsf by#{room.resourceId}
in the edit-jsf (which works without accessing the resourceId).
All with the same conclusion:An Error Occurred: /roomedit.xhtml @18,81 value="#{room.resourceId}": Bean: org.termtimer.model.Room, property: resourceId (not accessible!)
No way ...
I think I'll use the ugly transient methods ...
thankful for any help
Dennis
Beside: I'm using JBoss 4.0.3RC1 and Seam 1 beta1