openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kevin Sutter <kwsut...@gmail.com>
Subject Re: help me ! 2 day~ about update detail fk!!!
Date Tue, 21 Sep 2010 21:48:38 GMT
Not sure what exactly you are trying to accomplish with this example.  It
looks like your id fields are annotated to be generated values, but you have
constructors that are attempting to set the id.  And, your example is trying
to set the id of one entity type based on another entity's id.  It looks
like you have to clear up whether you want id generation or not.

On Tue, Sep 21, 2010 at 2:18 PM, ghyghost <ghyghost@sohu.com> wrote:

>
> package orm;
>
> import java.util.HashSet;
> import java.util.Set;
>
> import javax.persistence.CascadeType;
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.FetchType;
> import javax.persistence.GeneratedValue;
> import javax.persistence.GenerationType;
> import javax.persistence.Id;
> import javax.persistence.OneToMany;
> import javax.persistence.SequenceGenerator;
> import javax.persistence.Table;
>
> /**
>  * Sheng entity.
>  *
>  * @author MyEclipse Persistence Tools
>  */
> @Entity
> @Table(name = "SHENG", schema = "y246")
> public class Sheng implements java.io.Serializable {
>
>        // Fields
>
>        private Long id;
>        private String shengname;
>        private Set<Shi> shis = new HashSet<Shi>(0);
>
>        // Constructors
>
>        /** default constructor */
>        public Sheng() {
>        }
>
>        /** minimal constructor */
>        public Sheng(Long id) {
>                this.id = id;
>        }
>
>        /** full constructor */
>        public Sheng(Long id, String shengname, Set<Shi> shis) {
>                this.id = id;
>                this.shengname = shengname;
>                this.shis = shis;
>        }
>
>        // Property accessors
>        @Id
>        @Column(name = "ID", unique = true, nullable = false, precision = 9,
> scale
> = 0)
>        @SequenceGenerator(allocationSize = 1, name = "idauto", sequenceName
> =
> "idauto")
>        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
> "idauto")
>        public Long getId() {
>                return this.id;
>        }
>
>        public void setId(Long id) {
>                this.id = id;
>        }
>
>        @Column(name = "SHENGNAME", length = 50)
>        public String getShengname() {
>                return this.shengname;
>        }
>
>        public void setShengname(String shengname) {
>                this.shengname = shengname;
>        }
>
>        @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY,
> mappedBy =
> "sheng")
>        public Set<Shi> getShis() {
>                return this.shis;
>        }
>
>        public void setShis(Set<Shi> shis) {
>                this.shis = shis;
>        }
>
> }
>
>
>
>
> -------------------------------------------------------
> package orm;
>
> import javax.persistence.Column;
> import javax.persistence.Entity;
> import javax.persistence.FetchType;
> import javax.persistence.GeneratedValue;
> import javax.persistence.GenerationType;
> import javax.persistence.Id;
> import javax.persistence.JoinColumn;
> import javax.persistence.ManyToOne;
> import javax.persistence.SequenceGenerator;
> import javax.persistence.Table;
>
> /**
>  * Shi entity.
>  *
>  * @author MyEclipse Persistence Tools
>  */
> @Entity
> @Table(name = "SHI", schema = "Y246")
> public class Shi implements java.io.Serializable {
>
>        // Fields
>
>        private Long id;
>        private Sheng sheng;
>        private String shiname;
>
>        // Constructors
>
>        /** default constructor */
>        public Shi() {
>        }
>
>        /** minimal constructor */
>        public Shi(Long id) {
>                this.id = id;
>        }
>
>        /** full constructor */
>        public Shi(Long id, Sheng sheng, String shiname) {
>                this.id = id;
>                this.sheng = sheng;
>                this.shiname = shiname;
>        }
>
>        // Property accessors
>        @Id
>        @Column(name = "ID", unique = true, nullable = false, precision = 9,
> scale
> = 0)
>        @SequenceGenerator(allocationSize = 1, name = "idauto", sequenceName
> =
> "idauto")
>        @GeneratedValue(strategy = GenerationType.SEQUENCE, generator =
> "idauto")
>        public Long getId() {
>                return this.id;
>        }
>
>        public void setId(Long id) {
>                this.id = id;
>        }
>
>        @ManyToOne(fetch = FetchType.LAZY)
>        @JoinColumn(name = "SHENGID")
>        public Sheng getSheng() {
>                return this.sheng;
>        }
>
>        public void setSheng(Sheng sheng) {
>                this.sheng = sheng;
>        }
>
>        @Column(name = "SHINAME", length = 50)
>        public String getShiname() {
>                return this.shiname;
>        }
>
>        public void setShiname(String shiname) {
>                this.shiname = shiname;
>        }
>
> }
>
> ---------------------------------------------------
> package controller;
>
> import java.io.IOException;
>
> import javax.ejb.EJB;
> import javax.servlet.ServletException;
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
>
> import orm.Sheng;
> import orm.ShengFacadeLocal;
> import orm.Shi;
> import orm.ShiFacadeLocal;
>
> public class updateShi extends HttpServlet {
>
>        @EJB
>        ShiFacadeLocal shiFacadeLocalRef;
>        @EJB
>        ShengFacadeLocal shengFacadeLocalRef;
>
>        public void doGet(HttpServletRequest request, HttpServletResponse
> response)
>                        throws ServletException, IOException {
>                Sheng heilongjiangSheng =
> shengFacadeLocalRef.findById(2030L);
>
>                System.out.println(heilongjiangSheng.getShengname());
>
>                Shi shi = shiFacadeLocalRef.findById(2029L);
>
>                System.out.println(shi.getShiname());
>
>                shi.setSheng(heilongjiangSheng);
>
>                System.out.println(heilongjiangSheng.getShis());
>
>                shengFacadeLocalRef.update(heilongjiangSheng);
>
>        }
>
> }
>
>
>
> -------------------------------------
> use oracle db and weblogic10.3.3
>
> shi detail table "shengid" field not update, is old value!!!!!!!
>
> why ??help me please!! thank you!
> --
> View this message in context:
> http://openjpa.208410.n2.nabble.com/help-me-2-day-about-update-detail-fk-tp5555772p5555772.html
> Sent from the OpenJPA Users mailing list archive at Nabble.com.
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message