It's not a secret anymore!*
The moose likes EJB and other Java EE Technologies and the fly likes URGENT HELP in EJB-QL USING WEBLOGIC 8.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "URGENT HELP in EJB-QL USING WEBLOGIC 8.1" Watch "URGENT HELP in EJB-QL USING WEBLOGIC 8.1" New topic
Author

URGENT HELP in EJB-QL USING WEBLOGIC 8.1

Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
Hey All,

I am developing Entity Beans using CMP ( Container Managed Persistence ) in Weblogic ( Version 8.1) server. this is the scenario.

I have two tables . Table A is a list of entity types and table B is the list of entities and they are both related by the entity type id ( primary key - foreign key relationship ). I have deployment descriptor with relationship and everythign works fine.

My requirement is -- I need to get all the entities and sort them based on entity type id. I need also the entity type name , which is available in entity type table. I tried to write query that returns columns from both the tables, apparently ejb-ql does not like it.

If you need any information , please let me know.

uggestions will be greatly appreciated
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
If EntityType has a Collection of related Entities, you can create a findAll finder for EntityType. Load all EntityTypes (and thus all Entities) and sort them.

Next, you'll need some simple DTO to contain all of the fields you want. Loop over the sorted EntityTypes, and for each one loop over the related Entities (sorting those first if you want), building a DTO for each Entity.

Of course, you could also work it the other way. Load all Entities (with references to their related EntityType), create the DTOs, and finally sort the DTOs. Now that I think about it, I'd probably favor this route.

Finder methods can only return a whole entity bean or a Collection of whole entity beans -- not a subset of columns nor a combination of columns from multiple beans. Select methods are similarly limited: they can return either a whole bean or a single bean field (or Collections of either). There is no simple CMP method to return a "view" across multiple beans.
Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
Thanks for your response.

My understanding is, once i get all the entity types, i can get the entities for each entity type. Does that mean iterating through entity types and then calling the home iterface to get all entitties for each entity type ? If that is the case, is it better to work with DAO with a single query that gets all the data ?

I wanted to use entity beans, as i can cache it ( we do use cluster) and then invalidate it upon change in data. For straight-forward approach, it works fine. Since i want to cache the data, i am beginning to think if entity bean might not be a good fit for this logic.

Also, i read in an article that weblogic-ql does support the query to return resultset.

Any thoughts ?
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Originally posted by Mohen Vijay:
My understanding is, once i get all the entity types, i can get the entities for each entity type. Does that mean iterating through entity types and then calling the home iterface to get all entitties for each entity type ?
If you are using CMR (container-managed relationships) and you have a relationship defined between EntityType and Entity and it is navigable from EntityType to Entity, then EntityType must define an abstract methodwhich WebLogic's CMR service will implement for you. This would allow you to do the following:If you aren't using CMR or don't/can't create the necessary one-to-many relationship between the objects, you'll need to either load both sets of beans separately or bypass them with JDBC.
Also, i read in an article that weblogic-ql does support the query to return resultset.
Well, I looked it up in the EJB spec before posting, but it's possible I misread it and have misunderstood it for the past couple years, but I've only been using entity beans for a little over a year so anything's possible.
Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
Thanks for your reply.

I have defined my relationships in ejb-jar.xml like this

----------------------
<relationships>
<ejb-relation>
<ejb-relation-name>GrievanceNature - GrievanceNatureType</ejb-relation-name>
<ejb-relationship-role>
<ejb-relationship-role-name>GrievanceNature has one GrievanceNatureType</ejb-relationship-role-name>
<multiplicity>Many</multiplicity>
<relationship-role-source>
<ejb-name>GrievanceNature</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>grievanceNatureType_grieveNatureTypeId</cmr-field-name>
</cmr-field>
</ejb-relationship-role>
<ejb-relationship-role>
<ejb-relationship-role-name>GrievanceNatureType may have many GrievanceNature</ejb-relationship-role-name>
<multiplicity>One</multiplicity>
<relationship-role-source>
<ejb-name>GrievanceNatureType</ejb-name>
</relationship-role-source>
<cmr-field>
<cmr-field-name>grievanceNature_grieveNatureTypeId</cmr-field-name>
<cmr-field-type>java.util.Collection</cmr-field-type>
</cmr-field>
</ejb-relationship-role>
</ejb-relation>
</relationships>

----------------------


When i tried to define the abstract method as mentioned in your post, I get an exception.

[java] In bean GrievanceNatureType, the abstract method, getGrievanceNatures(), does not correspond to any
container-managed field and is not implemented in the bean class or any of its superclasses.
[java] .


I am not sure what mistake i am making here.

I would appreciate suggestions.
Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
Well, EJB 2.0 allow relationship with Local Interfaces and not Remote Interfaces.

I added the method to get the collection of entitties from Entity Type Local Interface. It did work fine.
 
Consider Paul's rocket mass heater.
 
subject: URGENT HELP in EJB-QL USING WEBLOGIC 8.1