I have a spring mvc application integrated with hibernate. I have 3 pojo which are marked for hibernate table creating.
- Book.java with @Table(name = "BOOKS") .
- User.java with @Table(name = "USER_TABLE")
- Role.java with @Table(name = "ROLE_TABLE")
I have configured session factory and all.
My hibernate.hbm2ddl.auto = create-drop. But also tried create, update.
When I start my application BOOKS table is getting created in DB. but USER_TABLE and ROLE_TABLE is not getting created.
I get no exception.
When I do select * from USER_TABLE;
the output is table or view doesn't exist.
package com.ca.service.form;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
/**
* @author jamju02
*/
@Entity
@Table(name = "ROLE_TABLE")
public class Role {
    private long id;
    private String roleName;
    private Set<User> users = new HashSet<User>();
    /**
     * @return the id
     */
     @Id
     @GeneratedValue
     @Column(name = "ROLE_ID")
    public long getId() {
        return id;
    }
    /**
     * @param id the id to set
     */
    public void setId(long id) {
        this.id = id;
    }
    /**
     * @return the roleName
     */
    public String getRoleName() {
        return roleName;
    }
    /**
     * @param roleName the roleName to set
     */
    public void setRoleName(String roleName) {
        this.roleName = roleName;
    }
    /**
     * @return the users
     */
     @ManyToMany(cascade = CascadeType.ALL)
     @JoinTable(
            name = "USERS_ROLES_TABLE",
            joinColumns = @JoinColumn(name = "ROLE_ID"),
            inverseJoinColumns = @JoinColumn(name = "USER_ID")
     )
    public Set<User> getUsers() {
        return users;
    }
    /**
     * @param users the users to set
     */
    public void setUsers(Set<User> users) {
        this.users = users;
    }
}
package com.ca.service.form;
import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
/**
* @author jamju02
*/
@Entity
@Table(name = "USER_TABLE")
public class User {
    private long id;
    private String username;
    private String password;
    private String email;
    private Set<Role> roles = new HashSet<Role>();
    public User(String username, String password, String email) {
        this.username = username;
        this.password = password;
        this.email = email;
    }
    // public void addRole(Role role) {
    // this.roles.add(role);
    // }
    /**
     * @return the id
     */
    @Id
    @GeneratedValue
    @Column(name = "USER_ID")
    public long getId() {
        return id;
    }
    /**
     * @param id
     *            the id to set
     */
    public void setId(long id) {
        this.id = id;
    }
    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }
    /**
     * @param username
     *            the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }
    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }
    /**
     * @param password
     *            the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }
    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }
    /**
     * @param email
     *            the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }
     /**
     * @return the roles
     */
     @ManyToMany(mappedBy = "users")
     public Set<Role> getRoles() {
         return roles;
     }
     /**
     * @param roles the roles to set
     */
     public void setRoles(Set<Role> roles) {
         this.roles = roles;
     }
}
package com.ca.service.form;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;
@Entity
@Table(name = "BOOKS")
public class Book {
    @Id
    @Column(name="ID")
    @GeneratedValue
    private Integer id;
    @Column(name="BOOK_NAME")
    private String bookName;
    @Column(name="AUTHOR")
    private String author;
    @Column(name="PRICE")
    private int price;
    @Column(name="QTY")
    private int quantity;
    public Integer getId() 
    {return id;}
    public String getBookName() 
    {return bookName;}
    public String getAuthor() 
    {return author;}
    public int getPrice() 
    {return price;}
    public int getQuantity() 
    {return quantity;}
    public void setId(Integer id) 
    {this.id = id;}
    public void setBookName(String bookName) 
    {this.bookName = bookName;}
    public void setAuthor(String author) 
    {this.author = author;}
    public void setPrice(int price) 
    {this.price = price;}
    public void setQuantity(int quantity) 
    {this.quantity = quantity;}
}
 
     
    