package com.sx.model;import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
public class UserTest {
static SessionFactory sessionFactory = null;

@BeforeClass
public static void beforeClass() {
new SchemaExport(new AnnotationConfiguration().configure()).create(false, true);
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
}
@AfterClass
public static void afterClass() {
sessionFactory.close();
}

@Test
public void UserSaveTest() {


}

public static void main(String[] agr) {
beforeClass();
}
}Junit 测试生成表。出错:15:54:45,031  INFO SchemaExport:226 - Running hbm2ddl schema export
15:54:45,046 DEBUG SchemaExport:242 - import file not found: /import.sql
15:54:45,078  INFO SchemaExport:251 - exporting generated schema to database
15:54:47,765  INFO SchemaExport:268 - schema export complete
15:54:48,359  INFO SchemaExport:226 - Running hbm2ddl schema export
15:54:48,359 DEBUG SchemaExport:242 - import file not found: /import.sql
15:54:48,359  INFO SchemaExport:251 - exporting generated schema to database
15:54:48,359  INFO SchemaExport:268 - schema export complete找不到import.sql
我的hibernate.cfg.xml如下:
<?xml version='1.0' encoding='gb2312'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"><hibernate-configuration>    <session-factory>
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://localhost:3306/hibernate</property>
        <property name="connection.username">root</property>
        <property name="connection.password">root</property>
        <property name="show_sql">true</property>
        <property name="format_sql">true</property>
        <!--<property name="connection.pool_size">1</property>
        -->
        <property name="current_session_context_class">thread</property>
        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
       <property name="hbm2ddl.auto">create</property>
        <mapping class="com.sx.model.User"/>
       <mapping class="com.sx.model.UserCard"/>
    </session-factory>
</hibernate-configuration>实体简单一个:package com.sx.model;import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToOne;public class User {
private int id;
private String name;
private String password;
private String card;
private UserCard usercard; @OneToOne
@JoinColumn(name="usercard_id")
public UserCard getUsercard() {
return usercard;
} public void setUsercard(UserCard usercard) {
this.usercard = usercard;
} private String depa; @Id
@GeneratedValue
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;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String getDepa() {
return depa;
} public void setDepa(String depa) {
this.depa = depa;
} public String getCard() {
return card;
}

public void setCard(String card) {
this.card = card;
}
}我把hibernate.cfg.xml中 <property name="hbm2ddl.auto">create</property>去掉也不行。
郁闷呀!!!!!