-->
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.  [ 1 post ] 
Author Message
 Post subject: Could not make the mappings work...
PostPosted: Sun May 09, 2010 9:55 pm 
Newbie

Joined: Tue Feb 16, 2010 6:57 pm
Posts: 17
I have 4 classes - Category, Consumer, Business, Document. They all have ManyToMany relationships. From all that I had read and tried and using petclinic as a template, I decided to map them with OneToMany and ManyToOne.

They do not work. I am new and I could be doing this totally wrong. Please give me some guidence.

I did not see any mapping data generated.

Code:
public class Document {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;

   public long getId() {
        return this.id;
    }
   
   public void setId(Long id) {
        this.id = id;
    }
   
    @ManyToOne(targetEntity = Business.class)
    @JoinColumn
    private Business business;
   
    @ManyToOne(targetEntity = Consumer.class)
    @JoinColumn
    private Consumer consumer;

    @ManyToOne(targetEntity = Category.class)
    @JoinColumn
    private Category category;
 
    @NotNull
    @Column(name = "cou_id")
    private long couId;
.....



Code:
public class Business {

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

      public Long getId() {
           return this.id;
       }

      public void setId(Long id) {
           this.id = id;          
       }
      
       @OneToMany(cascade = CascadeType.ALL, mappedBy = "business")
       private List<Document> documents = new ArrayList<Document>();             
      
       @ManyToOne(targetEntity = Consumer.class)
       @JoinColumn
       private Consumer consumer;

       @ManyToOne(targetEntity = Category.class)
       @JoinColumn
       private Category category;

       @NotNull
       @Column(name="bus_id")
       private long busId;
   .....


Code:
public class Category {
   
    @Id   
    @GeneratedValue(strategy=GenerationType.AUTO)           
    @Column(name = "id")   
    private Long id;   

   public Long getId() {
        return this.id;
    }
   public void setId(Long id) {
        this.id = id;
    }
   
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "category")
    private List<Business> businesses = new ArrayList<Business>();   
   
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "category")
    private List<Document> documents = new ArrayList<Document>();   

    @ManyToOne(targetEntity = Consumer.class)
    @JoinColumn
    private Consumer consumer;

    @Column(name = "cat_id")
    private long catId;
    ....


Code:
public class Consumer {

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

    public long getId() {
        return id;
    }
   
     public void setId(Long id) {
        this.id = id;
    }
   
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "consumer")
    private List<Document> documents = new ArrayList<Document>();             

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "consumer")
    private List<Category> categories = new ArrayList<Category>();             

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "consumer")
    private List<Business> businesses = new ArrayList<Business>();             
                      
    @NotNull
    @Column(name = "con_id")
    private long conId;
.....


Looking forward to any ideas and suggestions. Many Thanks.


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

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.