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