-->
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: @ManyToMany - complaining about joinTable missing
PostPosted: Fri Apr 30, 2010 6:12 pm 
Newbie

Joined: Tue Feb 16, 2010 6:57 pm
Posts: 17
Hi,

I am getting this error and have no idea what it meant, let alone fixing it. Any help will be greatly appreciated.

Error:
Code:
Caused by: org.hibernate.HibernateException: Missing table: con_cat
   at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1086)
   at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:116)
   at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:317)...


'con_cat' is supposed to be my joinTable and I expect it to be created for me automatically.

Here are the @ManyToMany declarations on both tables:

Class Consumer <----- OWNER
Code:
..........@ManyToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE},
               mappedBy = "consumers",
               targetEntity = Category.class)
          
    private List<Category> categories = new ArrayList();
   
    public Category getCategories() {
       if (this.categories.isEmpty()) {
           return null;
       }
       return this.categories.get(0);
       }
   
    public void setCategory(Category category) {
       if (this.categories.isEmpty()) {
           this.categories.add(category);
       } else {
           this.categories.set(1, category);
       }

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "id")
    private Long id;
 
    private int con_id;  // consumer ID - this id is for App use
     .....
    // getter. setters
..........

Class Category <----THE OTHER SIDE
Code:
.....    @ManyToMany(targetEntity=Consumer.class, cascade={CascadeType.PERSIST, CascadeType.MERGE})
    @JoinTable(
        name="con_cat",
        joinColumns=@JoinColumn(name="cat_id", referencedColumnName="cat_id"),
        inverseJoinColumns=@JoinColumn(name="con_id", referencedColumnName="con_id")
    )
    private List<Consumer> consumers = new ArrayList();
   
    public Consumer getConsumers() {
       if (this.consumers.isEmpty()) {
           return null;
       }
       return this.consumers.get(0);
       }
   
    public void setConsumer(Consumer consumer) {
       if (this.consumers.isEmpty()) {
           this.consumers.add(consumer);
       } else {
           this.consumers.set(1, consumer);
     }
     
    @Id   
    @GeneratedValue(strategy=GenerationType.AUTO)           
    @Column(name = "id")   
    private Long id; 

    private int cat_id;   // category ID,  also for App use
  // getters & setters ...


If I don't want to use 'cat_id' and 'con_id' but use the auto-generated 'id' as primary key from both sides, what should I put in below? Substitute both sets of 'cat_id', 'con_id' with 'id'?

@JoinTable(
name="Con_Cat",
joinColumns=@JoinColumn(name="cat_id", referencedColumnName="cat_id"),
inverseJoinColumns=@JoinColumn(name="con_id", referencedColumnName="con_id")
)

And, why the Missing table: con_cat exception?

I shall greatly appreciate any help.

Many Thanks in advance...Mimi


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.