我有一个名为" User"的实体。由于Oracle无法创建具有该名称的表,因此我给它@Entity(name =)和@Table(name =)属性以确保它可以创建。但是,由于某些原因,表格还没有创建。为了使事情变得更奇怪,所有定义的@JoinTable都是正确创建的,具有相应的名称。任何人都知道可能导致这种情况的原因吗?
我的课程:
@Entity(name="USERTABLE")
@Table(name="USERTABLE")
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>();
@Id
@GeneratedValue(generator="user_seq")
@SequenceGenerator(name="user_seq",sequenceName="User_Sequence",allocationSize=1)
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;
}
@ManyToOne
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;
}
@ManyToMany
@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;
}
@ManyToMany
@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;
}
}
我的persistence.xml:
<?xml version="1.0" encoding="UTF-8"?>
<persistence
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
version="1.0">
<persistence-unit name="weaver">
<jta-data-source>java:/weaverDS</jta-data-source>
<properties>
<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"/>
</properties>
</persistence-unit>
</persistence>
更新:我尝试创建一个命名策略,在每个表的开头添加一个前缀,但该表仍然是未创建的
答案 0 :(得分:0)
好的,我发现了问题。我没有注意到布尔被设置为'tinyint'(在OracleSQL中是不存在的)并且Date不能在OracleSQL中正常保存(你需要为它分配一个@ Temporal = TemporalType.TIMESTAMP来执行它)。删除'tinyint'部分并添加anotation解决了它。故事的道德:总是检查数据类型。