Hi all,

         I have a requirement where I need to assign a Objects to a list.
I tried the example given in showcase there is working (in the site).
But It is not assigning to that list

I am also attaching code for your refernce.

---Vamsi
/*
 * $Id: PersonAction.java 471756 2006-11-06 15:01:43Z husted $
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

package test.actions;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.PersistenceUnit;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.exception.ConstraintViolationException;

import test.examples.Person;

import com.opensymphony.xwork2.ActionSupport;

        
@SuppressWarnings("serial")

public class PersonAction extends ActionSupport {

        //private Person person;
        private List persons = new ArrayList();
        
        private Log _logger = LogFactory.getLog(PersonAction.class);
        
        
        
        
        public List getPersons() {
                return persons;
        }

        public void setPersons(List persons) {
                this.persons = persons;
        }

        @SuppressWarnings("unchecked")
        
        public String save()  {
                EntityManager e = SfmsEntityManagerFactory.getEntityManager();
                EntityTransaction txn  =e.getTransaction();
                txn.begin();
                try{
                        _logger.error("Person ::::::::::::::::::::::::::");
                        _logger.error("Person ::::::::::::::::::::::::::");
                        for (Object object :persons) {
                                Person person  = (Person) object;
                                _logger.error("Person 
::::::::::::::::::::::::::" + person);
                                
                                e.persist(person);
                        }
                        _logger.error("Person ::::::::::::::::::::::::::");
                        _logger.error("Person ::::::::::::::::::::::::::");
                        txn.commit();
                        addActionMessage("Record Added");
                        read(e);
                }catch(ConstraintViolationException e1) {
                        addActionError("Record Already There");
                }catch(IllegalStateException e1){
                                                
                }catch(Exception e1) {
                        addActionError("Error Inserting");
                        txn.rollback();
                }
                
        return SUCCESS;
    }
        
        private void read(EntityManager e)  {                           
                persons = e.createQuery("From Person").getResultList();
        
    }





   

}
package test.examples;

import static javax.persistence.FetchType.LAZY;

import javax.persistence.Basic;
import javax.persistence.Entity;
import javax.persistence.Id;

@Entity
public class Person implements Persister{

        
        @Id
        private String name;    
        
        @Basic(fetch=LAZY)
        private int age;

        public String getName() {
                return name;
        }

        public int getAge() {
                return age;
        }

        public void setName(String name) {
                this.name = name;
        }

        public void setAge(int age) {
                this.age = age;
        }
        
        @Override
        public String toString() {
        
                return name + "::::" + age;
        }
        
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to