-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Mapping did not populate field??
PostPosted: Tue May 11, 2010 9:11 pm 
Newbie

Joined: Thu Jan 28, 2010 8:38 pm
Posts: 2
I tried several variations but none worked for me. The annotated mappings did not take place (i.e. mapped fields not populated by Hibernate). I knew I am doing something wrong or lack thereof some essentials. If I may run this by you, please help point out what I need to do to make this work.

I have 4 Classes: Business, Category, Consumer, PurchasedItem.

POJO Class Business:
Code:
@Configurable
@Entity
public class Business {
       @Id
       @NotNull
       @GeneratedValue(strategy = GenerationType.AUTO)
       @Column(name = "bus_id")
       private Long busId;

      public long getBusId() {
         return busId;
      }
      public void setBusId(long busId) {
         this.busId = busId;
      }
      
   @NotNull
        @OneToMany(targetEntity=PurchasedItem.class, cascade = CascadeType.ALL)
        @JoinColumn(name="bus_id", unique=true)
   private List<PurchasedItem> purItems;
      
   @NotNull
        @ManyToOne(targetEntity = Consumer.class)
        @JoinColumn (name="con_id", updatable=false,insertable=false)
        private Consumer consumer;

        @NotNull
   @ManyToOne(targetEntity = Category.class)
   @JoinColumn (name="cat_id", updatable=false, insertable=false)
   private Category category;
      
   @NotEmpty
   @Size(max = 50)
   @Column(name = "bus_na")
   private String busNa;....

POJO Class Category:
Code:
@Configurable
@Entity
public class Category {
   
    @Id   
    @NotNull
    @GeneratedValue(strategy=GenerationType.AUTO)           
    @Column(name = "cat_id")   
    private Long catId;   
   
    public long getCatId() {
        return this.catId;
    }
    public void setCatId(long catId) {
        this.catId = catId;
    }
   
    @NotNull
    @OneToMany(targetEntity=Business.class, cascade = CascadeType.ALL)
    @JoinColumn(name="cat_id", unique=true)
    private List<Business> businesses;
   
    @NotNull
    @OneToMany(targetEntity=PurchasedItem.class, cascade = CascadeType.ALL)
    @JoinColumn(name="cat_id", unique=true)
     private List<PurchasedItem> purItems;

    @NotNull
    @ManyToOne(targetEntity = Consumer.class)
    @JoinColumn (name="con_id", updatable=false, insertable=false)
    private Consumer consumer;
   
    @NotNull
    @Size(max = 50)
    @Column(name = "cat_name")
    private String catName;.....


POJO Class Consumer:
Code:
@Configurable
@Entity
public class Consumer {

    @Id
    @NotNull
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "con_id")
    private Long conId;

    public long getConId() {
   return conId;
    }
    public void setConId(long conId) {
   this.conId = conId;
    }
   
    @NotNull
    @OneToMany(targetEntity=PurchasedItem.class, cascade = CascadeType.ALL)
    @JoinColumn(name="con_id",    unique=true)
    private List<PurchasedItem> purItems;

    @NotNull
    @OneToMany(targetEntity=Category.class, cascade = CascadeType.ALL)
    @JoinColumn(name="con_id", unique=true)
    private List<Category> categories;

    @NotNull
    @OneToMany(targetEntity=Business.class, cascade = CascadeType.ALL)
    @JoinColumn(name="con_id", unique=true)
    private List<Business> businesses;

    @Size(max = 50)
    @Column(name = "first_name")
    private String firstName;.....

POJO Class PurchasedItem:
Code:
@Configurable
@Entity
public class PurchasedItem {

    @Id
    @NotNull
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "pur_id")
    private Long purId;

   public long getPurId() {
      return this.purId;
   }
   public void setPurId(long purId) {
      this.purId = purId;
   }
   
   @NotNull
        @ManyToOne(targetEntity = Business.class)
        @JoinColumn (name="bus_id", updatable=false, insertable=false)
        private Business business; 
   
   @NotNull
        @ManyToOne(targetEntity = Consumer.class)
        @JoinColumn (name="con_id", updatable=false, insertable=false)
        private Consumer consumer; 

   @NotNull
        @ManyToOne(targetEntity = Category.class)
        @JoinColumn (name="cat_id", updatable=false, insertable=false)
        private Category category; 
   
   @NotNull
        @Column(name = "cat_id")
   private long catId;.........


After I created new rows for each class, none of the JoinColummn(s) specified under @ManyToOne or @OneToMany was populated with mapped data. E.g.

Table: Category

cat_id: 1
cat_name: Parks
con_id: NULL

Any help will be greatly appreciated.


Top
 Profile  
 
 Post subject: Re: Mapping did not populate field??
PostPosted: Tue May 11, 2010 10:02 pm 
Regular
Regular

Joined: Tue May 11, 2010 5:50 pm
Posts: 54
Location: Norman, Ok, U.S.A
First of all you have them as Insertable = false. It is if you don't want anything in these tables. Secondly, it is a good practice to put @Table(name = "tableName" after the Entity annotation.

Try these and see if these work


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.