KatVolkov KatVolkov -4 years ago 65
Java Question

Hibernate isn't creating a named tabled in the DB

I have a Entity with the name "User". Since Oracle can't create a table with that name, I gave it @Entity(name=) and @Table(name=) properties to ensure it can be created. But still, for some reason the table isn't created. To make matters weirder, all the @JoinTable defined are created correctly, with the according names. Anyone has an idea of what may be causing this?

My class:

public class User implements Serializable {
private static final long serialVersionUID = -3895959057511877608L;

private Integer id;
private String name;
private String userName;
private Domain domain;
private String password;
private Boolean mustChangePassword;
private String email;
// 19/07/2012 RP [WEAVER-83]
private Date lastLogin;
private List<Profile> profiles = new ArrayList<Profile>();
private List<Role> roles = new ArrayList<Role>();

public Integer getId() {
return id;

public void setId(Integer id) {
this.id = id;

public String getName() {
return name;

public void setName(String name) {
this.name = name;

@Column(unique = true)
public String getUserName() {
return userName;

public void setUserName(String userName) {
this.userName = userName;

public Domain getDomain() {
return domain;

public void setDomain(Domain domain) {
this.domain = domain;

public String getPassword() {
return password;

public void setPassword(String password) {
this.password = password;

@Column(columnDefinition = "tinyint")
public Boolean getMustChangePassword() {
return mustChangePassword;

public void setMustChangePassword(Boolean mustChangePassword) {
this.mustChangePassword = mustChangePassword;

public String getEmail() {
return email;

public void setEmail(String email) {
this.email = email;

public Date getLastLogin() {
return lastLogin;

public void setLastLogin(Date lastLogin) {
this.lastLogin = lastLogin;

@JoinTable(joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "profile_id") })
@IndexColumn(name = "listOrder")
public List<Profile> getProfiles() {
return profiles;

public void setProfiles(List<Profile> profiles) {
this.profiles = profiles;

@JoinTable(joinColumns = { @JoinColumn(name = "user_id") }, inverseJoinColumns = { @JoinColumn(name = "role_id") })
@IndexColumn(name = "listOrder")
public List<Role> getRoles() {
return roles;

public void setRoles(List<Role> roles) {
this.roles = roles;

My persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
<persistence-unit name="weaver">
<property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" />
<!-- <property name="hibernate.hbm2ddl.auto" value="update"/> -->
<property name="hibernate.hbm2ddl.auto" value="create"/>
<!-- http://www.jboss.com/index.html?module=bb&op=viewtopic&t=78806 -->
<property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.DefaultComponentSafeNamingStrategy"/>

UPDATE: I tried creating a naming strategy that adds a prefix at the start of every table, but the table remains uncreated

Answer Source

Ok, I found the problem. I didn't noticed the Boolean was set as 'tinyint' (innexistant in OracleSQL) and that the Date can't be normally persisted in OracleSQL (you need to assign a @Temporal=TemporalType.TIMESTAMP for it to do it). Removing the 'tinyint' part and adding the anotation solved it. Moral of the story: always check data types.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download