首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

struts2.3.4+hibernate4.18+spring3.2 自动创办外键关联失败,创建序列失败

2013-06-25 
struts2.3.4+hibernate4.18+spring3.2自动创建外键关联失败,创建序列失败!用 struts2.3.4+hibernate4.18+s

struts2.3.4+hibernate4.18+spring3.2 自动创建外键关联失败,创建序列失败!
用 struts2.3.4+hibernate4.18+spring3.2 框架写一个web小程序,实体类用的jpa注解。
在让hibernate自动创建表时总是提示无法添加外键,并且无法创建用于生成id的sequence。
本该创建序列seq_6bit ,它却发出create table seq_6bit ( next_val bigint );insert into seq_6bit values ( 100000 )的语句!
这个程序在只用hibernate4.18时是能够自动创建相关表,建立关联关系,创建序列等。
为什么添加其他两个框架后,就不行了呢!

我用的数据库是oracle10g。

具体错误提示如下:

17:33:15,005 DEBUG org.hibernate.tool.hbm2ddl.SchemaUpdate:226 - alter table Admin add index FK3C3132FA38882C2 (userId), add constraint FK3C3132FA38882C2 foreign key (userId) references users (userId)
17:33:15,097 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:235 - HHH000388: Unsuccessful: alter table Admin add index FK3C3132FA38882C2 (userId), add constraint FK3C3132FA38882C2 foreign key (userId) references users (userId)
17:33:15,098 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:236 - ORA-00904: : 标识符无效

17:33:15,099 DEBUG org.hibernate.tool.hbm2ddl.SchemaUpdate:226 - alter table Course_Teacher add index FK2FDB6BBE2921AA00 (tid), add constraint FK2FDB6BBE2921AA00 foreign key (tid) references Teacher (tId)
17:33:15,102 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:235 - HHH000388: Unsuccessful: alter table Course_Teacher add index FK2FDB6BBE2921AA00 (tid), add constraint FK2FDB6BBE2921AA00 foreign key (tid) references Teacher (tId)
17:33:15,103 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:236 - ORA-00904: : 标识符无效

17:33:15,104 DEBUG org.hibernate.tool.hbm2ddl.SchemaUpdate:226 - alter table Course_Teacher add index FK2FDB6BBED464D56A (cid), add constraint FK2FDB6BBED464D56A foreign key (cid) references Course (cId)
17:33:15,109 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:235 - HHH000388: Unsuccessful: alter table Course_Teacher add index FK2FDB6BBED464D56A (cid), add constraint FK2FDB6BBED464D56A foreign key (cid) references Course (cId)
17:33:15,109 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:236 - ORA-00904: : 标识符无效

17:33:15,110 DEBUG org.hibernate.tool.hbm2ddl.SchemaUpdate:226 - alter table Score add index FK4C04E72EEE5C98 (sId), add constraint FK4C04E72EEE5C98 foreign key (sId) references Student (sId)
17:33:15,113 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:235 - HHH000388: Unsuccessful: alter table Score add index FK4C04E72EEE5C98 (sId), add constraint FK4C04E72EEE5C98 foreign key (sId) references Student (sId)
17:33:15,113 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:236 - ORA-00904: : 标识符无效

17:33:15,114 DEBUG org.hibernate.tool.hbm2ddl.SchemaUpdate:226 - alter table Score add index FK4C04E72D464D56A (cId), add constraint FK4C04E72D464D56A foreign key (cId) references Course (cId)
17:33:15,117 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:235 - HHH000388: Unsuccessful: alter table Score add index FK4C04E72D464D56A (cId), add constraint FK4C04E72D464D56A foreign key (cId) references Course (cId)


17:33:15,118 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:236 - ORA-00904: : 标识符无效

17:33:15,119 DEBUG org.hibernate.tool.hbm2ddl.SchemaUpdate:226 - alter table Student add index FKF3371A1BA38882C2 (userId), add constraint FKF3371A1BA38882C2 foreign key (userId) references users (userId)
17:33:15,121 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:235 - HHH000388: Unsuccessful: alter table Student add index FKF3371A1BA38882C2 (userId), add constraint FKF3371A1BA38882C2 foreign key (userId) references users (userId)
17:33:15,121 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:236 - ORA-00904: : 标识符无效

17:33:15,122 DEBUG org.hibernate.tool.hbm2ddl.SchemaUpdate:226 - alter table Teacher add index FKD6A63C2A38882C2 (userId), add constraint FKD6A63C2A38882C2 foreign key (userId) references users (userId)
17:33:15,123 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:235 - HHH000388: Unsuccessful: alter table Teacher add index FKD6A63C2A38882C2 (userId), add constraint FKD6A63C2A38882C2 foreign key (userId) references users (userId)
17:33:15,124 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:236 - ORA-00904: : 标识符无效

17:33:15,124 DEBUG org.hibernate.tool.hbm2ddl.SchemaUpdate:226 - alter table users add index FK6A68E08C2A0A140 (qxNo), add constraint FK6A68E08C2A0A140 foreign key (qxNo) references QX (qxNo)
17:33:15,148 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:235 - HHH000388: Unsuccessful: alter table users add index FK6A68E08C2A0A140 (qxNo), add constraint FK6A68E08C2A0A140 foreign key (qxNo) references QX (qxNo)
17:33:15,148 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:236 - ORA-00904: : 标识符无效

17:33:15,149 DEBUG org.hibernate.tool.hbm2ddl.SchemaUpdate:226 - create table seq_6bit ( next_val bigint )
17:33:15,242 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:235 - HHH000388: Unsuccessful: create table seq_6bit ( next_val bigint )
17:33:15,242 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:236 - ORA-00902: 无效数据类型

17:33:15,243 DEBUG org.hibernate.tool.hbm2ddl.SchemaUpdate:226 - insert into seq_6bit values ( 100000 )
17:33:15,245 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:235 - HHH000388: Unsuccessful: insert into seq_6bit values ( 100000 )
17:33:15,246 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:236 - ORA-00942: 表或视图不存在

17:33:15,246 DEBUG org.hibernate.tool.hbm2ddl.SchemaUpdate:226 - create table seq_7bit ( next_val bigint )
17:33:15,249 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:235 - HHH000388: Unsuccessful: create table seq_7bit ( next_val bigint )
17:33:15,250 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:236 - ORA-00902: 无效数据类型

17:33:15,250 DEBUG org.hibernate.tool.hbm2ddl.SchemaUpdate:226 - insert into seq_7bit values ( 2013000 )
17:33:15,252 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:235 - HHH000388: Unsuccessful: insert into seq_7bit values ( 2013000 )


17:33:15,253 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:236 - ORA-00942: 表或视图不存在

17:33:15,253 DEBUG org.hibernate.tool.hbm2ddl.SchemaUpdate:226 - create table seq_8bit ( next_val bigint )
17:33:15,255 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:235 - HHH000388: Unsuccessful: create table seq_8bit ( next_val bigint )
17:33:15,256 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:236 - ORA-00902: 无效数据类型

17:33:15,256 DEBUG org.hibernate.tool.hbm2ddl.SchemaUpdate:226 - insert into seq_8bit values ( 20130000 )
17:33:15,266 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:235 - HHH000388: Unsuccessful: insert into seq_8bit values ( 20130000 )
17:33:15,266 ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate:236 - ORA-00942: 表或视图不存在

17:33:15,267  INFO org.hibernate.tool.hbm2ddl.SchemaUpdate:240 - HHH000232: Schema update complete


我的主要程序代码:

@Entity
@SequenceGenerator(name="tidSeq", sequenceName="seq_7bit",initialValue=2013000,allocationSize=1)
public class Teacher
{
private int tId;
private List<Course> courses = new ArrayList<Course>();

@ManyToMany(mappedBy="teachers",fetch=FetchType.EAGER, cascade={CascadeType.PERSIST,CascadeType.MERGE})
public List<Course> getCourses()
{
return courses;
}

@Id
@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="tidSeq")
public int gettId()
{
return tId;
}

}


@Entity
@SequenceGenerator(name = "cidSeq", sequenceName = "seq_8bit", initialValue = 20130000, allocationSize = 1)
public class Course
{
private int cId;
private List<Teacher> teachers = new ArrayList<Teacher>();

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "cidSeq")
public int getcId()
{
return cId;
}

@ManyToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.EAGER)
@JoinTable(joinColumns = { @JoinColumn(name = "cid") }, inverseJoinColumns = { @JoinColumn(name = "tid") })
@Fetch(FetchMode.SUBSELECT)
public List<Teacher> getTeachers()
{
return teachers;
}
}


applicationContext.xml:

<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.soft103.oracletask.entity.Admin</value>
<value>com.soft103.oracletask.entity.User</value>
<value>com.soft103.oracletask.entity.QX</value>
<value>com.soft103.oracletask.entity.Course</value>
<value>com.soft103.oracletask.entity.Log</value>
<value>com.soft103.oracletask.entity.Score</value>
<value>com.soft103.oracletask.entity.Student</value>
<value>com.soft103.oracletask.entity.Teacher</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>


<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.format_sql">true</prop>
<prop key="hibernate.id.new_generator_mappings">true</prop>  
<!-- --><prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="cache.use_query_cache">false</prop>
<prop key="cache.use_second_level_cache">true</prop>
<prop key="cache.region.factory_class">org.hibernate.cache.EhCacheRegionFactory</prop>
</props>
</property>
</bean>
Spring Hibernate Struts 外键 序列
[解决办法]
你用oracle的数据库,居然敢用mysql的方言,把配置<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>改成oracle10G的方言就行了

热点排行