hibernate怎么在控制台查看自动生成的建表语句啊,hibernate.cfg.xml配置加了 hbm2ddl.auto的配置,能自动建表,但是控制台如何看到建表语句啊?
show_sql也加了,只能看到插入语句,看不到建表语句,每次测试程序都在mysql成功删除表,为何啊?????其实我是想搜 为什么 hibernate映射枚举类型,到了mysql上成了tinyblob类型了
annotaitons  注解完全正确
我是想把枚举类型映射成varchar的
import java.util.Date;import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;@Entity
public class Cat { private int id;
private String name;
private Date birthday;

@Enumerated(EnumType.STRING) 
private DengJi dj;

@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}

//定制时间精度
@Temporal(TemporalType.DATE)
public Date getBirthday() {
return birthday;
}
public void setBirthday(Date birthday) {
this.birthday = birthday;
}

//注解枚举类型
@Enumerated(EnumType.STRING)
public DengJi getDj() {
return dj;
}

public void setDj(DengJi dj) {
this.dj = dj;
}
}
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration>    <session-factory>        <!-- Database connection settings -->
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost/hibernate</property>
        <property name="connection.username">root</property>
        <property name="connection.password">root</property>        <!-- SQL dialect -->
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>        <!-- Enable Hibernate's automatic session context management 在线程中找session -->
       <property name="current_session_context_class">thread</property>        <!-- Echo all executed SQL to stdout -->
        <property name="show_sql">true</property>
         <property name="format_sql">true</property>        <!-- Drop and re-create the database schema on startup -->
        <property name="hbm2ddl.auto">create</property>
        <property name="hbm2ddl.auto">update</property>        <mapping class="hibernate.Cat"/>
        <mapping resource="hibernate/Cat.hbm.xml"/>    </session-factory></hibernate-configuration>

解决方案 »

  1.   

    楼主还是去查查hibernate的文档吧 配置里应该有这个吧
      

  2.   

    都说CSDN是高手如云,怎么这么大的CSDN没人了吗?
      

  3.   

    所谓强大的CSDN让我见识一下你的威力吧
      

  4.   

    new SchemaExport(new AnnotationConfiguration().configure("/hibernate.cfg.xml")).create(true, false);
    SchemaExport 这个类可以查看创表语句,具体的你可以搜一下或是看哈文档
      

  5.   


    请问这个SchemaExport 类是想你说的一样使用了,但具体怎么操作才会打印建表语句到控制台啊?
      

  6.   

    很久木有用hibernate啦,都忘记了
      

  7.   

    我是用的Junit进行单元测试的,后来发现我自己写main方法测试,不用Junit就不会出现这样的问题,但不知道为什么,求高人解答?还有其实我是想搜:为什么 hibernate映射枚举类型,到了mysql上成了tinyblob类型了annotaitons 注解完全正确,我是想把枚举类型映射成varchar的,怎么办?
      

  8.   

    晕,果真这么大的CSDN论坛没人鸟我了?
      

  9.   

    show_sql   设置为  true
      

  10.   

    问题已经解决,答案请看:
    http://blog.csdn.net/getchance/article/details/7667983
      

  11.   

    汗,建表语句都让 Hibernate 去生成???
      

  12.   


    呵呵,现在还只是学习测试,实际工作中,当然都是先建表的,但是需要在控制台打印DDL语句,不仅建表语句,对表的操作,还是需要的,见笑了。
      

  13.   

    为什么 hibernate映射枚举类型,到了mysql上成了tinyblob类型了
    annotaitons 注解完全正确
    我是想把枚举类型映射成varchar的
      

  14.   

    把@Enumerated(EnumType.STRING)注解与其他的注解一样放在方法上,而不是在字段上