hibernate 发出建表语句,为什么数据库中没生成表?

sw245711601 2011-06-27 01:40:07
public class DBExport_MirrorHA
{
public static void main(String[] args)
{

Configuration cfg = new Configuration().configure("hibernate-cfg.xml");

SchemaExport export = new SchemaExport(cfg);

export.create(true,true);
}
}

执行之后

drop table if exists t_empolyee
drop table if exists t_record
create table t_empolyee (id varchar(5) not null auto_increment, name varchar(50), department varchar(20), phone varchar(20), email varchar(20), primary key (id))
create table t_record (id varchar(5) not null auto_increment, username varchar(50), logindate datetime, IP varchar(20), exitdate datetime, primary key (id))


配置文件

<session-factory>
<property name="connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="connection.url">
jdbc:mysql://localhost:3306/FanFullOrder
</property>
<property name="connection.username">root</property>
<property name="connection.password">dhappy</property>

<property name="dialect">
org.hibernate.dialect.MySQLDialect
</property>
<!-- <property name="hbm2ddl.auto">true</property> -->
<property name="hbm2ddl.auto">update</property>
<property name="show_sql">true</property>

<mapping resource="fanfull/order/po/Employee.hbm.xml" />
<mapping resource="fanfull/order/po/Record.hbm.xml" />

</session-factory>

但是我运行时


om.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'fanfullorder.t_empolyee' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.Util.getInstance(Util.java:381)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1030)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1936)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:139)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2145)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:375)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:308)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:153)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1129)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at fanfull.order.dao.impl.UserDaoImpl.querylogin(UserDaoImpl.java:34)
at fanfull.order.actions.LoginAction.execute(LoginAction.java:49)
at org.springframework.web.struts.DelegatingActionProxy.execute(DelegatingActionProxy.java:110)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:305)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:191)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
1
...全文
477 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
enke_zhang 2011-12-27
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 sw245711601 的回复:]

问题解决 对象的 hbm 文件 id 不能设置成String 的自动增长。不知道怎么一回事!
[/Quote]




非常感谢你啊,我今天也遇到这个问题了,控制台打印了建表语句,可是数据库中没表,原来是主键自动增长的不能用String 类型。。。。。。。。
五哥 2011-06-27
  • 打赏
  • 举报
回复
把hibernate.cfg.xml中的这个

<property name="hbm2ddl.auto">create</property>

去掉;
宁波朱超 2011-06-27
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 jumpheightway 的回复:]
<property name="hbm2ddl.auto">update</property>
楼主大人
这里需要这样配置
<property name="hbm2ddl.auto">create</property>
[/Quote]

。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

@楼主
<property name="hbm2ddl.auto">update</property>

<property name="hibernate.hbm2ddl.auto">update</property>
jumpheightway 2011-06-27
  • 打赏
  • 举报
回复
<property name="hbm2ddl.auto">update</property>
楼主大人
这里需要这样配置
<property name="hbm2ddl.auto">create</property>
sw245711601 2011-06-27
  • 打赏
  • 举报
回复
问题解决 对象的 hbm 文件 id 不能设置成String 的自动增长。不知道怎么一回事!
zhangli198444 2011-06-27
  • 打赏
  • 举报
回复
是不是缺少<property name="myeclipse.connection.profile">mysql</property>这句啊,我的可以自动生成,好像就比你多这句。
sw245711601 2011-06-27
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 yanweijie0317 的回复:]
我在想如果是先加载你的配置文件,会加载映射文件,同时去指定的库找指定的表,这之前还没执行你那创建表的代码吧?
[/Quote]

最后不是执行create 吗?
wlf2131 2011-06-27
  • 打赏
  • 举报
回复
你把 update 改成create 就可以啦 如果先建表就要把这句注释掉不让会把你建好的表覆盖掉的


上面我是想告诉他们是 数据库.表名
yanweijie0317 2011-06-27
  • 打赏
  • 举报
回复
我在想如果是先加载你的配置文件,会加载映射文件,同时去指定的库找指定的表,这之前还没执行你那创建表的代码吧?
sw245711601 2011-06-27
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 wlf2131 的回复:]
引用 1 楼 sustbeckham 的回复:
Table 'fanfullorder.t_empolyee' doesn't exist

这不是很明白了吗


fanfullorder 数据库名字
[/Quote]

名字没错啊 一道数据库里面就是小写了
wlf2131 2011-06-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 sustbeckham 的回复:]
Table 'fanfullorder.t_empolyee' doesn't exist

这不是很明白了吗
[/Quote]

fanfullorder 数据库名字
wlf2131 2011-06-27
  • 打赏
  • 举报
回复
改成 <property name="hbm2ddl.auto">create</property> 试试 我也初学不太懂

你先建表嘛
sw245711601 2011-06-27
  • 打赏
  • 举报
回复
[Quote=引用楼主 sw245711601 的回复:]
public class DBExport_MirrorHA
{
public static void main(String[] args)
{

Configuration cfg = new Configuration().configure("hibernate-cfg.xml");

SchemaExport export = new SchemaExpo……
[/Quote]

大哥啊 我的意思是 我运行那个方法 hibernate 已经发出了建表语句啊 但是数据库里没看到表!
mznxbcv000 2011-06-27
  • 打赏
  • 举报
回复
++++
[Quote=引用 1 楼 sustbeckham 的回复:]
Table 'fanfullorder.t_empolyee' doesn't exist

这不是很明白了吗
[/Quote]
sustbeckham 2011-06-27
  • 打赏
  • 举报
回复
Table 'fanfullorder.t_empolyee' doesn't exist

这不是很明白了吗

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧