Re: [JBoss-user] Finder method question
Using BMP this is definitely possible. All you would have is a finder method which looks something like this: public String ejbFindByFirstName(Person p) { PreparedStatement pstmt = myDBConnection.prepareStatement("select emp_id from employee where firstname = ?"); pstmt.setString(1, p.getFirstName()); ResultSet res = pstmt.executeQuery(); // parse the results return strEmpId; } Not sure how this would work under CMP. Hope it helps, Ijonas. - Original Message - From: "Nordahl, David C" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, April 19, 2001 4:27 PM Subject: [JBoss-user] Finder method question > I'm wondering if it is possible to create a finder method for an attribute > which is nested in another object attribute of my bean. For example, say I > have an Employee bean with an attribute of type Person (non bean) which has > an attribute of last and first name, and I want to make a method > findByFirstName. Is this possible? And if so how is it done? > > ___ > JBoss-user mailing list > [EMAIL PROTECTED] > http://lists.sourceforge.net/lists/listinfo/jboss-user > ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user
RE: [JBoss-user] Finder method question
I am under the impression that custom finders (ejbFindBy...) are supported under CMP. Just add the FindBy method in the home interface and all should be well. ps. I hope it works, I'll need to code some real soon :) btw. as a precision, what you return is the primary key class... be it Integer, String, CustomPK etc. and also, returning a Collection should work AFAIK. HTH Daniel -Message d'origine- De : Ijonas Kisselbach [mailto:[EMAIL PROTECTED]] Envoyé : 19 avril, 2001 13:08 À : [EMAIL PROTECTED] Objet : Re: [JBoss-user] Finder method question Using BMP this is definitely possible. All you would have is a finder method which looks something like this: public String ejbFindByFirstName(Person p) { PreparedStatement pstmt = myDBConnection.prepareStatement("select emp_id from employee where firstname = ?"); pstmt.setString(1, p.getFirstName()); ResultSet res = pstmt.executeQuery(); // parse the results return strEmpId; } Not sure how this would work under CMP. Hope it helps, Ijonas. - Original Message - From: "Nordahl, David C" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, April 19, 2001 4:27 PM Subject: [JBoss-user] Finder method question > I'm wondering if it is possible to create a finder method for an attribute > which is nested in another object attribute of my bean. For example, say I > have an Employee bean with an attribute of type Person (non bean) which has > an attribute of last and first name, and I want to make a method > findByFirstName. Is this possible? And if so how is it done? > > ___ > JBoss-user mailing list > [EMAIL PROTECTED] > http://lists.sourceforge.net/lists/listinfo/jboss-user > ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user
RE: [JBoss-user] Finder method question
Let's asume the Employee remote interface inherits from (interface) Person. Let's also asume the Employee home interface inherits from PersonHome (Where person is not a bean itself!) and PersonHome has a finder-method which returns a object of type person. (I tried to implement this.) Then the container is not able to cast the interface as assumed. I would expect an instance of Employee which is casted to Person. But the container throws runtime exceptions. The EJB specification is not clear at this point. Inheritance between EJB's is not specified, but inherit home and remote interfaces is allowed. (EJB 1.1 spec appedix B.2) Now I use a workaround: If I have Employee und Customer EB which are logical Persons, I define a finder-method in each home interface an use reflection to envoke the finder-method on the interface. So I dont need to know with wich EB I work really. Object parentHome = initial.lookup(name evaluated at runtime i.e EmployeeEntity); Class thisRemote = Class.forName(name evaluated at runtime too i.e Employee); java.lang.reflect.Method finder = thisRemote.getMethod("findByPrimaryKey", new Class[] {java.lang.String.class} ); Person thisPerson = (Person)finder.invoke(parentHome, new Object[] {new String(parentId)} ); this.sel = thisPerson.getSelection(childName); //some method from interface Person > -Original Message- > From: Nordahl, David C [SMTP:[EMAIL PROTECTED]] > Sent: 19 April 2001 17:28 > To: '[EMAIL PROTECTED]' > Subject: [JBoss-user] Finder method question > > I'm wondering if it is possible to create a finder method for an attribute > which is nested in another object attribute of my bean. For example, say > I > have an Employee bean with an attribute of type Person (non bean) which > has > an attribute of last and first name, and I want to make a method > findByFirstName. Is this possible? And if so how is it done? > > ___ > JBoss-user mailing list > [EMAIL PROTECTED] > http://lists.sourceforge.net/lists/listinfo/jboss-user ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user
[JBoss-user] Finder method question
I'm wondering if it is possible to create a finder method for an attribute which is nested in another object attribute of my bean. For example, say I have an Employee bean with an attribute of type Person (non bean) which has an attribute of last and first name, and I want to make a method findByFirstName. Is this possible? And if so how is it done? ___ JBoss-user mailing list [EMAIL PROTECTED] http://lists.sourceforge.net/lists/listinfo/jboss-user