I am using eclipse IDE with google app engine as my application
server.

I hav 2 classes trains and cabins which are mapped by OneToMany
relationship

When i provide the values and after assigning the concerned fields
using the setter methods i persisted the train entity.

The train entity is correctly persisted but regarding the cabin its
not getting created and i am not able to find the data.

Instead there is another entity class created where these transactions
are maintained but the cabin entity is not created at all.

Pls help me

I am providing the code for these 2 classes.:

Train.java


        @Entity(name="Train")
        public class Train implements Serializable {
            private static final long serialVersionUID = 1L;
            @Id
            @GeneratedValue(strategy = GenerationType.IDENTITY)
            private Long id;

            private String tname, src, destn, tdate, ttime;

            @OneToMany(mappedBy="train", cascade=CascadeType.ALL)
            @JoinColumn(name="TrainID")
            public static Collection<Acabin> acabins;

            public Collection<Acabin> getAcabin() {
                return acabins;
            }

            public void setAcabin(Collection<Acabin> acabin) {
                acabins = acabin;
            }

            public String getDestn() {
                return destn;
            }

            public void setDestn(String destn) {
                this.destn = destn;
            }

            public String getSrc() {
                return src;
            }

            public void setSrc(String src) {
                this.src = src;
            }

            public String getTdate() {
                return tdate;
            }

            public void setTdate(String tdate) {
                this.tdate = tdate;
            }

            public String getTname() {
                return tname;
            }

            public void setTname(String tname) {
                this.tname = tname;
            }

            public String getTtime() {
                return ttime;
            }

            public void setTtime(String ttime) {
                this.ttime = ttime;
            }
            public Long getId() {
                return id;
            }

            public void setId(Long id) {
                this.id = id;
            }

            public static Train tr;
            public static Acabin ac;
            //public static Collection <Acabin> acabins;
            public static Train addTrain(String src, String destn, String
tname, String tdate, String ttime, int ac3, int ac2, int sleeper) {
                EntityManager
em=TrainService.getTrainFactory().createEntityManager();
                tr=new Train();
                ac=new Acabin();
                tr.setTname(tname);
                tr.setSrc(src);
                tr.setDestn(destn);
                tr.setTdate(tdate);
                tr.setTtime(ttime);
                ac.setName("AC 3 Tier");
                ac.setAvail(ac3);
                ac.setPrice(600);
                acabins=new ArrayList<Acabin>();
                acabins.add(ac);
                ac=new Acabin();
                ac.setName("AC 2 Tier");
                ac.setAvail(ac2);
                ac.setPrice(400);
                acabins.add(ac);
                ac=new Acabin();
                ac.setName("Sleeper");
                ac.setAvail(sleeper);
                ac.setPrice(200);
                acabins.add(ac);
                tr.setAcabin(acabins);
                try{

                        em.persist(tr);

                }finally{
                        em.close();
                }


                return tr;
            }
}



Cabins:

package com.trains.entities;

import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.EntityManager;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;

import com.trains.service.TrainService;


@Entity(name="Acabin")
public class Acabin implements Serializable {
    private static final long serialVersionUID = 1L;

    public Acabin(){
        EntityManager
em=TrainService.getTrainFactory().createEntityManager();
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private double price;

    @ManyToOne(fetch=FetchType.LAZY)
    private Train train;

    public Train getTrain() {
                return train;
        }

        public void setTrain(Train train) {
                this.train = train;
        }

        public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }
    private int avail;
    private String name;



    public int getAvail() {
        return avail;
    }

    public void setAvail(int avail) {
        this.avail = avail;
    }

    public String getName() {
        return name;
    }

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

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

}

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine-java?hl=en.

Reply via email to