Persistent Bean framework

I am struggling with an architectural question, surrounding persistent beans. Here is the problem.
Supposed I have two classes, Group and Person. Obviously, Group contains some number of members. Thus, Group has a private HashMap (could have been Vector, but HashMap guarantees unique entries) listing all Person members. Finally, Group has get/set methods for its list of members.
I have a simple persistence framework, whereby a "manager" can Introspect a bean, find all its properties, then save them to a data store, commonly a JDBC store, but in this case LDAP (using JNDI).
The problem becomes how best to represent the Person members in the Group class. I could represent them as a Vector/HashMap/array of Person, but then persisting the Group becomes difficult, since when the manager Introspects the Group and finds the list of Person objects, it does not have basic elements to persist but rather complex user-defined Person objects. I do not want to store serialized objects, which make the data specific to my application, but rather the properties, so that the data can be used by other apps.
When my data store was an RDBMS, I simply stored IDs for the list of members, since this mapped nicely to a relational model. However, in the case of an LDAP store, the member attributes (representing the list) contain a DN rather than just the ID (which is inside the DN).
Here is my catch-22: if I store the serialized Person objects or even just the unique IDs of the Persons, then the underlying data in the LDAP directory become unique to my app; if I somehow get it to translate to the entire DN representing the Person, then my application objects become specific to my LDAP store and not reusable in other storage contexts.
Any ideas?

Hi Jhon,
Nothing like that exists for DB XML at the moment. Berkeley DB JE supports object persistence in Java using simple annotations, if that's what you need.
John

Similar Messages

  • Persistance of beans in JSF-based sites

    I'm new to Java EE 5, so take it easy on me. I'm trying to learn some Java EE stuff, focusing first on JavaServer Faces. I've got an idea for a little site I want to build as part of my learning process, but there's one thing I haven't figured out how to do.
    I basically want to make a few JSF pages with some persistent beans. Can JSF-managed beans be made persistant? Can JSF use EJBs as JSF-managed beans? What's the best way to do all of this?
    Thanks in advance.

    ya i have declared even my console says the init of the jsp file is successful.
    so i could reach to the jsp but it is not able to instantiate the bean managed class. also the stacktrace says cannot find that class even though the compiled .class file is in classes folder inside WEB-INF.
    thanx,
    Karthik

  • Need help in design/framework of a project requirements

    Hi there.
    I need some input/design suggestion and/or comments regarding 2 projects that I'm undertaking currently. The project duration is 8 weeks starting now.
    Some background information of the current technology we are using right now. We are using weblogic 7.0 SP2 and our database is ms sqlserver 2000 and/or mysql. The persistance layer/framework we are using is a home grown JDBC framework. We are using only stateless session beans and our client which is a swing ui access the servers side thru webservices via a session facade. We use also Transfer objects on the client and our own DataObjects on the server side. Current consideration is that we can not upgrade to the current weblogic version at this time and can only use java 1.4 and use existing persistence framework we have. I've considered using Spring/Hibernate but it will involve major refactoring on our existing system, which we can not afford right now. But we can augment or add new framework to handle this 2 projects.
    1. The first project is a mass update/creation of orders and order items. In our system the update and creation of order and order items are complicated and perform several validations (e.g. vendor/client is valid; item are valid and have enough to on-hand, etc.) and lookups before we can create/update an order and it's order items. We estimated that process to be around 1.5 - 3.0 secs and typically we will be processing between a few hundreds to about 5000. The max ceiling we put is 10,000.
    Now the requirements are:
    a. Ensure that the process will be completed and in the event of failure (physical or network or power) and recovery to start where it failed and start processing from that point of failure.
    b. The transaction should be atomic on per order basis and not on whole process - meaning we will commit all changes for an order and start a new transaction on the next order. This will ensure that we have a complete order committed.
    c. Don't tie the client from this process and when the process is finished give a feedback to the client who invoke the process.
    2. The second project is related to the first, is that before they post the process above, the user will look at the set of data and do some editing and then post the data. So this project is on the UI side and would present the user a table/grid view of the data and since data set could be large, we want our swing ui to fetch only a set of rows/data so that it does not take so long to load all the data or run out of memory. A button or by the user scrolling on the scrollbar would fetch the next succeeding rows/data. The problem we have as stated on the first paragraph is these- we are using webservices and stateless session beans and there is no way that the server can recognized who the user is when that user request the next set of row/data set without querying the database again.
    So your input and help is very much appreciated and if you know an existing framework that would help me is most welcome.
    Have a blessed day.
    Jun Victorio

    Take the statistics of the tables and check again.
    begin
    DBMS_STATS.gather_table_stats(ownname=>'syslog',tabname=>'logs');
    end;
    Regards
    Asif Kabir

  • How to get stateful and stateless session bean in second jsp

    I create stateful session bean in the first jsp, then how can I get the stateful session bean in the second jsp? I find that somebody store the bean in HttpSession.
    If I store the stateful session bean in HttpSession, then I can get it in the second jsp. My problem is that I can store the stateless session bean in HttpSession, and get it in the second jsp. Then, both stateful and stateless can maintain the state in the second jsp. What is the difference between stateful and stateless session bean in this case ?
    I understand the definition of stateful and stateless session bean, but I'm confuse how to use session bean. Can anyone provide sample jsp to show difference of stateful and stateless? How the stateful session bean can maintain the state for the client?

    Greetings,
    I create stateful session bean in the first jsp, then how can I get the stateful session bean in the
    second jsp? I find that somebody store the bean in HttpSession.Which is the correct scope for sharing client-specific data when 'request' scope is insufficient.
    If I store the stateful session bean in HttpSession, then I can get it in the second jsp. My problem is
    that I can store the stateless session bean in HttpSession, and get it in the second jsp. Then, bothWhy is that a "problem"? Does your application not require the stateless bean to be shared? If so, then don't store the EJBObject reference in the session...
    stateful and stateless can maintain the state in the second jsp. What is the difference betweenWhat do you mean by this exactly?..
    stateful and stateless session bean in this case ?Statefulness of session beans is in regard to maintaining client state (er, in all cases). If your "stateless" bean is receiving information from the client (i.e. its caller) - either through a create method or a business method - and that information is available (retrievable from the bean) on subsequent method calls, then that bean is, in fact, stateful - regardless of how it is deployed.
    I understand the definition of stateful and stateless session bean, but I'm confuse how to use
    session bean.The correct question, it here seems, is "when" to use which type... Use a "stateful" bean when information about (from) the client (i.e. the caller) must be maintained across method calls of the bean. Use a "stateless" bean for general business methods that do not depend on "prior knowledge" of the client (i.e. the caller).
    Can anyone provide sample jsp to show difference of stateful and stateless? How the statefulA "sample JSP" would yield nothing additional... The semantics of calling, using, and "persisting", bean references are always the same - regardless of type or class. However, the reason(s) for using one over the other depends entirely on the needs of your application.
    session bean can maintain the state for the client?I recommend that you spend more time learning about EJBs generally. In particular, it seems you require more fundamental understanding of their scope and lifecycle. Refer to sections 4, 6, and 7 of the EJB 2.0 Specification.
    Regards,
    Tony "Vee Schade" Cook

  • Single Persistent instance of a Object, Many non persistant. Same Identity on persist

    I have a persistent bean class with two Strings as member fields. (example
    below)
    I have many other classes that use it a part of they're member fields.
    I need to have only one persistant version of it (One row, to many Rows in
    different tables). But can have many non persistant versions. I can't
    control the creation of the non persistant objects.
    i.e.
    On persist, How can I configuration JDO to detect that it's the same as an
    object already in the database and use that instead?
    example:
    // Example class One
    package foo;
    public class One(){
    public String var1;
    public String var2;
    public String getVar1(){
    return this.var1;
    public void setVar1(String var1Set){
    this.var1 = var1Set
    public String getVar2(){
    return this.var2;
    public void setVar2(String var2Set){
    this.var2 = var2Set
    /// one.jdo
    <?xml version="1.0"?>
    <jdo>
    <package name="foo">
    <class name="One"/>
    </package>
    </jdo>
    ///Example Scenario
    One oneObject = new One();
    oneObject.setVar1("Value1");
    oneObject.setVar2("Value2");
    pm.makePersistent(oneObject); // one row in database
    /// Some time later, in a different thread, or since JVM shutdown and
    restart
    One oneObject = new One();
    oneObject.setVar1("Value1");
    oneObject.setVar2("Value2");
    pm.makePersistent(oneObject); // one row in database, instead of two.

    You cannot. You should either find the object by query or retrieve it
    using application identity.
    Graham Cruickshanks wrote:
    I have a persistent bean class with two Strings as member fields. (example
    below)
    I have many other classes that use it a part of they're member fields.
    I need to have only one persistant version of it (One row, to many Rows in
    different tables). But can have many non persistant versions. I can't
    control the creation of the non persistant objects.
    i.e.
    On persist, How can I configuration JDO to detect that it's the same as an
    object already in the database and use that instead?
    example:
    // Example class One
    package foo;
    public class One(){
    public String var1;
    public String var2;
    public String getVar1(){
    return this.var1;
    public void setVar1(String var1Set){
    this.var1 = var1Set
    public String getVar2(){
    return this.var2;
    public void setVar2(String var2Set){
    this.var2 = var2Set
    /// one.jdo
    <?xml version="1.0"?>
    <jdo>
    <package name="foo">
    <class name="One"/>
    </package>
    </jdo>
    ///Example Scenario
    One oneObject = new One();
    oneObject.setVar1("Value1");
    oneObject.setVar2("Value2");
    pm.makePersistent(oneObject); // one row in database
    /// Some time later, in a different thread, or since JVM shutdown and
    restart
    One oneObject = new One();
    oneObject.setVar1("Value1");
    oneObject.setVar2("Value2");
    pm.makePersistent(oneObject); // one row in database, instead of two.
    Steve Kim
    [email protected]
    SolarMetric Inc.
    http://www.solarmetric.com

  • EJB3- get id after persist

    Hi to all...i have an entity bean (UserEBean) and its "Id" is defined like:
    @Id(generate=GeneratorType.SEQUENCE, generator="USERS_SEQ")
    @javax.persistence.SequenceGenerator(
              name="USERS_SEQ",
              sequenceName="users_user_id_seq"
    @Column(name="user_id", nullable=false)     
         public Long getUserId() {
              return userId;
    Respective session bean has the method:
    public void save(UserEBean bean)
              // TODO Auto-generated method stub
              manager.persist(bean);          
    In an other class i set properties in an UserEBean variable and then i call:
    userDAO.save(my_userbean);
    How can i get the entity's ID which i just persisted?
    Thanks to all!
    Paolo.

    Hi to all...i have an entity bean (UserEBean) and its "Id" is defined like:
    @Id(generate=GeneratorType.SEQUENCE, generator="USERS_SEQ")
    @javax.persistence.SequenceGenerator(
              name="USERS_SEQ",
              sequenceName="users_user_id_seq"
    @Column(name="user_id", nullable=false)     
         public Long getUserId() {
              return userId;
    Respective session bean has the method:
    public void save(UserEBean bean)
              // TODO Auto-generated method stub
              manager.persist(bean);          
    In an other class i set properties in an UserEBean variable and then i call:
    userDAO.save(my_userbean);
    How can i get the entity's ID which i just persisted?
    Thanks to all!
    Paolo.

  • Need some help in understanding J2EE

    Hi guys,
    I have been doing java for the past 3 years... From OOP to WAD (Windows Application Development), however i didn't study EAD (Enterprise Application Development) which teaches J2EE, thus i have no knowledge of J2EE... i have tried to read the J2EE tutorial...but dun realli understand it...can anyone help me by providing some good links to learn J2EE

    J2EE defines a framework for server-side applications. It actually "sits" on top of J2SE, and extends the functionality of J2SE by adding services for managing web applications and managing beans that can be persisted/saved.
    The J2EE environment "hosts" web applications and persistent Java beans. Web applications run inside a web "container", which handles loading, initializing and dispatching requests to the web application components, and the persistent Java beans are managed by a separate bean container, which handles loading and persisting the beans.
    A web application consists of Java servlets, Java Server Pages (JSPs), Java tag libraries (taglibs), and any other Java classes. The persistent beans are called Enterprise Java Beans (EJBs) and are otherwise ordinary Java beans, except that they implement specific interfaces so that the bean container can manage them and allow applications running in remote JVMs to access them.
    A server that provides containers for both the web application and the Enterprise Java Beans is called a J2EE application server. One J2EE application server can host multiple web applications. To prevent each application from directly accessing or affecting the other applications on the server, each application runs in its own "context". The context is actually called the servlet context because servlets are the standard Java component for processing requests within a web application.
    While I'm sure there are purists who will disagree with me, most applications do not use, nor need to use EJBs, and can be ran comfortably with the web container alone. Tomcat is a J2EE web container you can download for free, and it comes with sample applications you can study. I recommend starting with Tomcat because it's free, it's easy to install, and it is just a web container, without the thousands of irrelevant features that vendors add-on that distract you from really understanding the core technology. Tomcat comes with fairly extensive online help, and there are probably as many books available today for Tomcat as there are for any other web application server, if not more.
    I hope this is helpful. There's certainly plenty of information available on the Internet about J2EE, and I've only scratched the surface here. If you have specific questions about J2EE, post them here and I'm sure someone will be able to help you out.
    Regards,
    James W. Anderson
    Alpharetta, Georgia USA
    [email protected]

  • Number Overflow when it is within the range (Long)

    Hi,
    I am using Oracle JDBC Drivers to write a CMP (Container Managed Persistance) beans which has a CMP Field of long value in
    the table it is Number(14) which is well under the limits of long datatype, the value is also currentmillis which is millis
    from 1-1-1970, the value is also 1046836194640L which is withing long datatypes limits but gives the overflow exception,
    please help me with the same. try to use the oracle.sql.NUMBER.toLong which expects a byte[] on the value it gives an error.
    simple way to test this is get the above value from dual table get the rs.getBytes and take the byte[] and pass it to the
    oracle.sql.NUMBER.toLong it will give the error. and one more strange observation i found is when this number is stored in the table and you try to just perform a select in SQL Query Manager or SQLPlus in windows 2000 you will receive an windows Excepton telling that program tried to refer to memeory outside and you have to quit the client app.
    Database is oracle 8i on windows 2000 advanced Server
    Expired Commands Not Found javax.ejb.FinderException: Exception in 'findExpiredCommandsOfThisMaster' while using result set:
    'weblogic.jdbc.rmi.SerialResultSet@7d78ce'
    java.sql.SQLException: Overflow Exception
    java.sql.SQLException: Overflow Exception
    at oracle.sql.NUMBER.toLong(NUMBER.java:371)
    at oracle.jdbc.dbaccess.DBConversion.NumberBytesToLong(DBConversion.java:2915)
    at oracle.jdbc.driver.OracleStatement.getLongValue(OracleStatement.java:4373)
    at oracle.jdbc.driver.OracleResultSetImpl.getLong(OracleResultSetImpl.java:529)
    at weblogic.jdbc.pool.ResultSet.getLong(ResultSet.java:107)
    at weblogic.jdbc.rmi.internal.ResultSetImpl.getLong(ResultSetImpl.java:216)
    at weblogic.jdbc.rmi.internal.ResultSetStraightReader.getLong(ResultSetStraightReader.java:62)
    at weblogic.jdbc.rmi.SerialResultSet.getLong(SerialResultSet.java:204)
    at
    net.devicesWorld.deviceServer.server.device.command.InstructionalUnit_7krj5v__WebLogic_CMP_RDBMS.ejbFindExpiredCommandsOfThis
    Master(Instruc
    tionalUnit_7krj5v__WebLogic_CMP_RDBMS.java:1877)
    at java.lang.reflect.Method.invoke(Native Method)
    at weblogic.ejb20.cmp.rdbms.RDBMSPersistenceManager.collectionFinder(RDBMSPersistenceManager.java:278)
    at weblogic.ejb20.manager.BaseEntityManager.collectionFinder(BaseEntityManager.java:670)
    at weblogic.ejb20.manager.BaseEntityManager.collectionFinder(BaseEntityManager.java:643)
    at weblogic.ejb20.internal.EntityEJBHome.finder(EntityEJBHome.java:448)
    at
    net.devicesWorld.deviceServer.server.device.command.InstructionalUnit_7krj5v_HomeImpl.findExpiredCommandsOfThisMaster(Instruc
    tionalUnit_7kr
    j5v_HomeImpl.java:267)
    at
    net.devicesWorld.deviceServer.server.device.command.CommandsToSendBean.getCommandToSend(CommandsToSendBean.java:97)
    at
    net.devicesWorld.deviceServer.server.device.command.CommandsToSendBean_uqhqrf_EOImpl.getCommandToSend(CommandsToSendBean_uqhq
    rf_EOImpl.java
    :413)
    at net.devicesWorld.deviceServer.server.device.command.PollOnline.process(PollOnline.java:110)
    at net.devicesWorld.deviceServer.server.device.command.CmdMessageBean.onMessage(CmdMessageBean.java:267)
    at weblogic.ejb20.internal.MDListener.execute(MDListener.java:268)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    Regards
    LJS Narayana

    Hi Abrami,
    Thank you for your reply. It is like this i am storing System.currentMillies() which gives Millis in long data type into a table having a number column with (14). Now i wrote a CMP bean which uses this table, for almost a year and half it is in production with no problem but from few days back when we try to use a finder method to query data SQL returns Exception telling that Number Overflow, a sample number for getting this overflow is 1046836194640L which represents 'Wed Mar 05 11:49:54 SGT 2003' this date. I found that the CMP which got generated is using oracle.sql.NUMBER.toLong(byte[] inputNumber) and thus giving the error. I try to use your suggested way, if we can directly work on the long it would be more convenient.
    Regards
    LJS Narayana

  • JNDI Lookup in JSP fails for EJB 3.0

    I am new to Java technology. I read the EJB FAQ, NetBeans docs and may forum discussions and I am still confused with the error I am having.
    Background:
    I have developed a persistance bean and related sessions beans (similar to the customer-cmp-ear application in the Java App Server samples). Now I am trying to access this bean using a JSP. After deploying the war file in the App Server and try to access the page, I get the following error.
    javax.naming.NameNotFoundException: No object bound to name java:comp/env/ConsumerSessionLocal
    After reading many articles, I understood that I dont have to prepare any descriptors, or JAR files for EJB 3.0.
    Environment Details:
    Java App Server Ver 9.0
    NetBeans 5.5
    I normally build the war files using NetBeans.
    I use App Server Admin console to deploy the web applications using the above war file.
    EJB details:
    Persistance EJB : person.java
    Session Objects
    Consumer.java (this implements ConsumerSessionLocal, ConsumerSessionRemote). This Stateless bean accesses the methods in person.java.
    ConsumerSessionLocal.java - local interface
    ConsumerSessionRemote.java - remote interface
    SearchConsumer.jsp
    This JSP page is calling the ConsumerSessionLocal using the JNDI lookup through InitialContext.
    Here is the Code snippet:
    try {
    InitialContext ic = new InitialContext();
    Object o = ic.lookup("java:comp/env/ConsumerSessionLocal");
    ConsumerSessionLocal consSession = (ConsumerSessionLocal) o;
    I am able to see the jsp page in the browser, however, after a submit action, I get the Java Naming Exception error.
    javax.naming.NameNotFoundException: No object bound for java:comp/env/ConsumerSessionLocal
    I would appreciate your help/any of your thoughts.
    Thanks in advance.
    -Ram

    I did not really solve it. Instead I used some of the tutorials that used JNDI lookup and modified those as my way forward. I did not really find out exactly what I was doing wrong.
    /Anders

  • Virtual Interface generation bug in NetWeaver ?

    I use the Web Service generation wizard to generate a virtual interface which exposes methods in an EJB. As one of the parameters I pass a simple java bean, lets say:
    public class StatusCode
    private String name;
    private boolean buggy;
    public String getName() {...}
    public void setName(String newName){...}
    public boolean isBuggy() {...}
    public void setBuggy(boolean trueOrFalse){...}
    When I look at the virtual interface generated, especially at the Types tab, my boolean attribute is not included.
    If I change the getter to "getBuggy()", the attribute is included in the VI. The only problem is that the typical Java Bean framework, say from sun or ibm, always map 'boolean' getters to 'isSomething()' and not 'getSomething()'.
    Is this a bug with NW? Is there a fix or workaround for this ?
    My version of NW:
    Version: 2.0.7
    Build id: 200407270250
    Thanks in advance,
    Mark
    I posted this question also in the NW development forum, but so far no replies.

    I try to login by use:
    username : Administrator
    password : <master password> (at least 1 number)
    I try to login many times but it always fails.
    (I am very sure about my password since i also try to reinstall many times - 10th. both J2EE 1.4 and Java EE 5)
    Ivaylo Ivanov, do you sure that you test with this new edition. (Not the previous edition)
    I see the other persons get the result like me:
    Telnet Administration
    SAP J2EE Engine v7.100
    User name: Administrator
    Password:
    The user account is either expired, or not valid yet.
    Login failed. Reason: The user account is either expired, or not valid yet.
    Connection to host lost.
    if my login is not correct, it will tell the other messags.
    Telnet Administration
    SAP J2EE Engine v7.100
    User name: f
    Password:
    Cannot authenticate the user.
    Login failed. Reason: Cannot authenticate the user.

  • Virtual Interface generation bug with NetWeaver ?

    I use the Web Service generation wizard to generate a virtual interface which exposes methods in an EJB. As one of the parameters I pass a simple java bean, lets say:
    public class StatusCode
        private String name;
        private boolean buggy;
        public String getName() {...}
        public void setName(String newName){...}
        public boolean isBuggy() {...}
        public void setBuggy(boolean trueOrFalse){...}
    When I look at the virtual interface generated, especially at the Types tab, my boolean attribute is not included.
    If I change the getter to "getBuggy()", the attribute is included in the VI. The only problem is that the typical Java Bean framework, say from sun or ibm, always map 'boolean' getters to 'isSomething()' and not 'getSomething()'.
    Is this a bug with NW? Is there a fix or workaround for this ?
    My version of NW:
    Version: 2.0.7
    Build id: 200407270250
    Thanks in advance,
    Mark
    (If this is not the right forum, could someone suggest where I can post this question?)

    Hi.  As of Netweaver 2004s,  the virtual interface piece has be absorbed into the creation of the web service definition, so there is no need to create it as well.   When you are getting the 403,  how are you trying to run this, using the Web Service Homepage?  If so, you will need to configure what j2e engine that you want to use to use.  You can do this in WSADMIN under the Administration settings.   Check that this is set.  YOu must know the URL of your j2e engine.
    Regards,
    Rich Heilman

  • Recommended structure of database-backed JSF app.

    I'm learning how to put together a web application using JSF 2.0, Spring and hibernate. I've done a lot of reading on various sites on the 'right' way to do it, and I think I've got the right idea, but I just want to check that I've understood it correctly. (Of course this is more about the structure rather than any specific implementation.)
    Here's what seems to be the case:
    Hibernate is configured via spring.
    POJOs for any persistent entities are mapped to hibernate via annotations (or xml), containing only trivial getters & setters. These methods are never accesses directly by JSF (i.e. these are not managed beans)
    Each of these entities has a DAO that does create, read, update, delete (or whatever). These take only object ids (or other identifiers) for reads or entity objects for the other ones, i.e. they don't access all the setters of the POJOs. (As such, can be made generic to reduce code duplication.)
    Optionally, each DAO can have a service object that presents the various database operations to the next layer, possibly performing checks and grouping operations together.
    Via spring, the service objects are accessible to the JSF beans (or pages).
    Now, suppose a simple use case where a user is entering a new record to the database via a web form. The JSF managed bean will be a POJO mirroring all the fields of the relevant entity bean (but not actually be an instance of one). These fields will be bound to the input fields of the form, and if they pass validation, the action (a method of the JSF managed bean) will create a new instance of the entity bean, copy all of its own field into this using its setters, then persist the newly created object with the service object (made available by spring).
    Displaying a previously persisted bean would be a similar process in reverse; the JSF managed bean would read an entity bean from the service object, load all its own fields using the getters from the loaded entity bean, then populate the page with these values.
    (Obviously this is a very simple case, I imagine there would be cases where the two beans would differ a bit, or perhaps more than simple get/set methods would be used, but I'm just starting out here)
    Is this about right? It seems odd to me that one would duplicate all the fields. It should be possible to make the beans do a dual duty, acting as both the entity bean and the JSF managed bean. Hibernate would simply ignore any action methods, and presumably such cases are what the @transient annotation is for.
    You'd end up with a single class that has both hibernate and JSF annotations on it.
    Is that right?

    There is a design forum.
    I think you have a few too many keywords in there. Hopefully someone with experience end to end might clear that up.
    You'd end up with a single class that has both hibernate and JSF annotations on it.Even if possible I suspect that no one is going to recommend that.

  • Error found in component h:selectOneMenu

    Hi,
    I think i found an error in in JSF1.2_04-b16-P02 (tomcat 6.0.13)
    -------------------------------- class persistent bean
    public abstract class PersistentBean<T extends PersistentBean> implements Serializable {
         private long id;
         public long getId() {
              return id;
         public void setId(long id) {
              this.id = id;
         public boolean equals(Object object) {
              if (this == object){
                   return true;
              if ((object == null) || !(object instanceof PersistentBean)){
                   return false;
              return ((PersistentBean) object).getId() == id;
         public int hashCode() {
              return super.hashCode();
    -------------------------------- class a
    public class A extends PersistentBean<A>{
    -------------------------------- class b
    public class B extends A{
    -------------------------------- Handler myJSFBean
    public class MyJSFBean{
         private B b;
         private ArrayList<SelectItem> options;
         // ----------------- init
              b = new B();
              b.setId(2);
         // ----------------- GETTERS + SETTERS
         public B getB() {
              return b;
         public void setB(B b) {
              this.b = b;
         public ArrayList<SelectItem> getOptions() {
              if(options == null){
                   options = new ArrayList<SelectItem>();
                   A a = new A();
                   a.setId(1);
                   A a2 = new A();
                   a2.setId(2);
                   options.add(new SelectItem(a, "First value"));
                   options.add(new SelectItem(a2, "Second value"));
              return options;
         public void setOptions(ArrayList<SelectItem> options) {
              this.options = options;
    ------------------------------------ JSP code
              <h:selectOneMenu
                   value="#{myJSFBean.b}"
                   converter="pbConverter">
                   <f:selectItems value="#{myJSFBean.options}" />
              </h:selectOneMenu>
    ----------------------------------- pbConverter
    public class PersistentBeanConverter implements Converter, Serializable {
         public static final String CONVERTER_ID = "pbConverter";
         private static final long serialVersionUID = 1L;
         public Object getAsObject(FacesContext context, UIComponent component,
                   String value) {
              if (value == null || value.equals(StringUtils.EMPTY)) {
                   return null;
              long id;
              try {
                   id = Long.parseLong(value);
              } catch (NumberFormatException e) {
                   id = 0;
                   e.printStackTrace();
              if (((UIInput) component).getValue() == null) {
                   return createNewValue(context, component, id);
              } else {
                   PersistentBean pk = (PersistentBean) ((UIInput) component)
                             .getValue();
                   //To be sure the valueChangeListener is called
                   if(pk.getId() != id){
                        return createNewValue(context, component, id);
                   return pk;
         private Object createNewValue(FacesContext context, UIComponent component, long id){
              ValueExpression ve = component.getValueExpression("value");
              try {
                   PersistentBean pk = (PersistentBean) ve.getType(context.getELContext())
                             .newInstance();
                   pk.setId(id);
                   return pk;
              } catch (Exception e) {
                   e.printStackTrace();
                   throw new RuntimeException(
                             "pbConverer error could not instanciate the assignable object of the persistent bean",
                             e);
         public String getAsString(FacesContext context, UIComponent component,
                   Object value) {
              if (value == null || value.equals(StringUtils.EMPTY)) {
                   return StringUtils.EMPTY;
              if (value instanceof PersistentBean) {
                   return String.valueOf(((PersistentBean) value).getId());
              } else {
                   throw new RuntimeException(
                             "The pbConverter required a value of PersistentBean");
    }---------------------------------------- Expected result
    I expect that the second value (Second value) of my listbox is selected.
    ----------------------------------------- Result
    No value is selected
    Strange I think, somebody knows why?
    Thanks in advance,
    Pieter
    Belgium

    I found a sollution by changing the core JSF libraries.
    I changed the following:
    --------------------- class javax.faces.component.UISelectOne starting at line 185
                   Class type = value.getClass();
                    Object newValue = getFacesContext().getApplication().
                        getExpressionFactory().coerceToType(item.getValue(), type);
                    if (value.equals(newValue)) {
                        return (true);
                    }.......................... in
                    if(value.equals(item.getValue())){
                         return (true);
                    }The second class i changed is the
    --------------------- class com.sun.faces.renderkit.html_basic.MenuRenderer starting at line 580
              Object newValue = context.getApplication().getExpressionFactory().
                  coerceToType(itemValue, type);
              isSelected = isSelected(newValue, valuesArray);.......................... in
    isSelected = isSelected(itemValue, valuesArray);I'm not sure this is the correct way of handeling this error.
    So my question is if somebody have some advice.
    Thanks in advance,
    Pieter

  • Why Threading is not allowed in EJB?

    Hello,
    I learnt that threading concepts is not allowed/used in EJB.
    can u please post your view, regarding the above question.
    Thanks

    Good mourning...
    EJB isn't used to web applications only, and also exist the Entity beans, the persistent beans and Message Driven Beans. EJB is a enterprise component that is deployed in Application Server. The AS harness the EJB instances amount. This amount is defined in ejb-jar.xml file. And, really, the EJB is thread-safety, thus only a client is connected in the specific time. For more and better information, read the Mastering EJB book, it's free download in theserverside.com, and this sections:
    - Several Entity Bean Instances May Represent the Same Underlying Data (pag. 114);
    - Entity Bean Instances Can Be Pooled (p�g 116).
    treat this specific issue.
    bye!

  • Instanciate an object depending on a variable value

    Hi there,
    I am developing a Web application based on a JSP+persistency MVC framework. In a number of classes, I have to be able to instanciate a "model" object (OO mapping from an RDBMS table) whose type depends on the value of a String variable. Currently, this is done this way:
      if(Constants.CONSTANT1.equals(value)) {
        return new Type1Model(args);
      } else if(Constants.CONSTANT2.equals(value)) {
        return new Type2Model(args);
      } // else if...The Type1Model, Type2Model, etc. classes extend the same base class. But I find this code ugly - while quite efficient.
    So I am trying to come to a design in which I call ModelFactory.getModel(value, args), period (more accurately, semi-colon). This factory holds a Hashtable, mapping possibles values for "value" to Class. Thus, each Type*Model class registrers itself in the ModelFactory for a given value, guaranteeing simple extensibility without modifying the factory nor the code that uses it.
    Now, am I complicating a lot too much this task which is so easy to perform in C-style code ? Or is this the path to OO-enlightenment ?
    Thanks and regards.

    I would in general avoid the if's as doing a more flexible approach is just as easy to code and more flexible.
    It is always best to first focus on the way you would like to call your code and then work on the details of what you need to do to get the code working (i.e. focus on the interface first).
    You could use reflection and pass in the class name you would like to construct, and simply use the class name as your constant. This is very simple and flexible. The following is close although I didn't test it.
    A sample invocation would be:
    Model myModel=ModelFactory.getModel("com.ssouza.MyModel", args);
    public class ModelFactory {
      public static Model getModel(String className, Object[] args) {
       // this is more psuedo code and I don't know the exact syntax, but
       Class cls=Class.forName(className);
        Class[] argTypes=loop through args array getting the Class associated with each and put it into this Class array
       Constructor con=cls.getConstructor(argTypes);
        return (Model) con.newInstance(args);
    }Steve http://www.jamonapi.com - JDBC/SQL monitoring in jamon 2.3!

Maybe you are looking for

  • Cannot print on LOCAL printer, but only from one application server

    Hello guys, we have a  case of user being unable to print directly on their own LOCAL printer from a certain application server. The status of their spool requests is stuck on "Waiting"/"Waiting for output formatter." If the print request is started

  • How to optimize Database Calls to improve performance of an application

    Hi, I have a performance issue with my applications. It takes a lot of time to load, as it is making several calls to the database. And, moreover, the resultset has more than 2000 records that are returned. I need to know what is the better way to im

  • Configuration of Solman as Ticketing Tool

    Dear Experts, Need yr guidance to configure Solution Manager as a ticketing tool in the below scenario: Scenario: We hv 04 Production Clents in R/3 (02 Nos - ECC 6.0; 02 Nos - ECC 5.0); Solution Manager has been already been installed in one the Prod

  • Can not run forms in Oracle Form Builder

    I get FRM-10142: The HTTP listener is not running on computer1 at port 8890. Please start the listener or check your runtime preferences. When I try running a form in Oracle form builder. Can someone please help with a solution to this problem.

  • Jagged images on xml gallery

    http://codadesign.net/newsite/design.html The images on both the thumbs and the final seem jagged. Any idea why?