刚刚学习hebirnate
  一个关于多对一的问题:
    
  第一个:User.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.hao.hibernate.User" table="t_User">
<id name="id">
<generator class="native"/>
</id>
<property name="name"/>
<many-to-one name="group"  unique="true"/>
</class>
</hibernate-mapping>
第二个:Group.hbm.xml<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.hao.hibernate.Group" table="t_Group">
<id name="groupNo">
<generator class="native"/>
</id>
<property name="gname"/>
</class>
</hibernate-mapping>
在进行建表的时候遇到了如下问题
14:47:37,609  INFO SchemaExport:154 - Running hbm2ddl schema export
14:47:37,625 DEBUG SchemaExport:170 - import file not found: /import.sql
14:47:37,625  INFO SchemaExport:179 - exporting generated schema to database
alter table t_User drop foreign key FKCB5540D6C4C43CFD
14:47:38,859 DEBUG SchemaExport:303 - alter table t_User drop foreign key FKCB5540D6C4C43CFD
14:47:38,953 DEBUG SchemaExport:288 - Unsuccessful: alter table t_User drop foreign key FKCB5540D6C4C43CFD
14:47:38,953 DEBUG SchemaExport:289 - Table 'hibernatedb_test4.t_user' doesn't exist
drop table if exists t_Group
14:47:38,953 DEBUG SchemaExport:303 - drop table if exists t_Group
drop table if exists t_User
14:47:39,234 DEBUG SchemaExport:303 - drop table if exists t_User
create table t_Group (groupNo integer not null auto_increment, gname varchar(255), primary key (groupNo))
14:47:39,265 DEBUG SchemaExport:303 - create table t_Group (groupNo integer not null auto_increment, gname varchar(255), primary key (groupNo))
create table t_User (id integer not null auto_increment, name varchar(255), group integer unique, primary key (id))
14:47:39,437 DEBUG SchemaExport:303 - create table t_User (id integer not null auto_increment, name varchar(255), group integer unique, primary key (id))
14:47:39,437 ERROR SchemaExport:274 - Unsuccessful: create table t_User (id integer not null auto_increment, name varchar(255), group integer unique, primary key (id))
14:47:39,437 ERROR SchemaExport:275 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group integer unique, primary key (id))' at line 1
alter table t_User add index FKCB5540D6C4C43CFD (group), add constraint FKCB5540D6C4C43CFD foreign key (group) references t_Group (groupNo)
14:47:39,437 DEBUG SchemaExport:303 - alter table t_User add index FKCB5540D6C4C43CFD (group), add constraint FKCB5540D6C4C43CFD foreign key (group) references t_Group (groupNo)
14:47:39,437 ERROR SchemaExport:274 - Unsuccessful: alter table t_User add index FKCB5540D6C4C43CFD (group), add constraint FKCB5540D6C4C43CFD foreign key (group) references t_Group (groupNo)
14:47:39,437 ERROR SchemaExport:275 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group), add constraint FKCB5540D6C4C43CFD foreign key (group) references t_Group' at line 1
14:47:39,437  INFO SchemaExport:196 - schema export complete
急求帮助!谢谢!!!

解决方案 »

  1.   

    此回复为自动发出,仅用于显示而已,并无任何其他特殊作用
    楼主【h495854943】截止到2008-06-27 14:48:35的历史汇总数据(不包括此帖):
    发帖数:4                  发帖分:61                 
    结贴数:0                  结贴分:0                  
    未结数:4                  未结分:61                 
    结贴率:0.00  %            结分率:0.00  %            
    如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
      

  2.   

    ERROR SchemaExport:274 - Unsuccessful: create table t_User (id integer not null auto_increment, name varchar(255), group integer unique, primary key (id)) 
    14:47:39,437 ERROR SchemaExport:275 - You have an error in your SQL syntax; check the manual that corresponds to <id name="id" type="java.lang.Integer"> 
    <generator class="native"/> 
    </id>