java left logo
java middle logo
java right logo
 

Home arrow Java EE Tips arrow Enterprise Java Beans arrow Using EJB-QL to create CMP finder methods
 
 
Main Menu
Home
Java Tutorials
Book Reviews
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Java Network
Java Forums
Java Blog




Most Visited Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews
Top Rated Tips
Java SE Tips
Java ME Tips
Java EE Tips
Other API Tips
Java Applications
Java Libraries
Java Games
Book Reviews


Statistics
Registered Users: 4088
Java SE Tips: 614
Java ME Tips: 202
Java EE Tips: 183
Other API Tips: 779
Java Applications: 298
Java Libraries: 209
Java Games: 16
Book Reviews:
 
 
 
Using EJB-QL to create CMP finder methods E-mail
User Rating: / 4
PoorBest 

Every entity bean home interface has a mandatory findByPrimaryKey() method. The EJB specification has always allowed you to specify custom finder methods in the home interface for more specific and different lookups.

Since EJB 2.0, the specification added a standard EJB query language (EJ-BQL). Using EJBQL to replace the implementation of a finder method does not in any way affect the source of an entity bean. To add finder methods to a CMP entity bean, you need to use EJ-BQL.

For this tip, we create some customer finder in CMP EJB.

A home interface with finder:

public interface PersonBeanHome extends EJBHome {
    
    public PersonBean create(PersonKey holding)
      throws CreateException, RemoteException;
    
    public PersonBean findByPrimaryKey(PersonKey primaryKey)
      throws FinderException, RemoteException;
    
    // our own finder method, searching persond by the first name:
    public Collection findByFirstName(String firstName)
      throws FinderException, RemoteException;
}

Deployment descriptor with EJB-QL statement:

<ejb-jar>
	<enterprise-beans>
		<!-- main bean definitions -->
		<entity>
			...
			<ejb-class>test.PersonBean</ejb-class>
			
			<!-- declaration of a primary key class  -->
			<prim-key-class>PersonKey</prim-key-class>
			<reentrant>False</reentrant>
			<cmp-version>2.x</cmp-version>
			
			<cmp-field>
				<field-name>firstName</field-name>
			</cmp-field>
			<cmp-field>
				<field-name>lastName</field-name>
			</cmp-field>
			
			<query>
				<query-method>
 				  <method-name>findByFirstName</method-name>
				  <method-params>
					<method-param>String</method-param>
				  </method-params>
				</query-method>

				<!-- a statement selecting all the persons 
                                     with the name specified: -->
				<ejb-ql>
   <![CDATA[SELECT OBJECT(p) FROM PersonBean AS p WHERE a.firstName == ?1]]>
				</ejb-ql>
			</query>
			
		</entity>
		
	</enterprise-beans>
</ejb-jar>


 Related Tips

 
< Prev   Next >

Page 1 of 0 ( 0 comments )

You can share your information about this topic using the form below!

Please do not post your questions with this form! Thanks.


Name (required)


E-Mail (required)

Your email will not be displayed on the site - only to our administrator
Homepage(optional)



Comment Enable HTML code : Yes No



 
       
         
     
 
 
 
   
 
 
java bottom left
java bottom middle
java bottom right
RSS 0.91 FeedRSS 1.0 FeedRSS 2.0 FeedATOM FeedOPML Feed

Home - About Us - Privacy Policy
Copyright 2005 - 2008 www.java-tips.org
Java is a trademark of Sun Microsystems, Inc.