Hibernate没有创建表

时间:2016-06-28 16:35:28

标签: database spring hibernate model-view-controller

Hibernate没有在数据库中创建表我不知道为什么我试图改变hibernate.hbm2ddl.auto来创建但似乎没有任何工作可以有人检查我在这里做错了什么:

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="org.h2.Driver"/>
    <property name="url" value="jdbc:h2:tcp://localhost/~/database"/>
    <property name="username" value="sa"/>
    <property name="password" value=""/>
</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"></property>
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
            <prop key="hibernate.hbm2ddl.auto">create</prop>
            <prop key="hibernate.show_sql">true</prop>
            <prop key="hibernate.format_sql">true</prop>
        </props>
    </property>
    <property name="packagesToScan">
        <list>
            <value>com.vacature.controller</value>
        </list>
    </property>
</bean>

。                   

@Entity
public class Vacature {
@Id
@Column(name="id")
@GeneratedValue(strategy= GenerationType.IDENTITY)
public String vacatuurId;

public String naam;

public String getVacatuurId() {
    return vacatuurId;
}

public void setVacatuurId(String vacatuurId) {
    this.vacatuurId = vacatuurId;
}

public String getNaam() {
    return naam;
}

public void setNaam(String naam) {
    this.naam = naam;
}
}

   .JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
jul 01, 2016 12:52:41 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.3.8.Final}
jul 01, 2016 12:52:41 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
jul 01, 2016 12:52:41 PM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
jul 01, 2016 12:52:41 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
jul 01, 2016 12:52:41 PM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
jul 01, 2016 12:52:41 PM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
jul 01, 2016 12:52:42 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000228: Running hbm2ddl schema update
jul 01, 2016 12:52:42 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000102: Fetching database metadata
jul 01, 2016 12:52:42 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000396: Updating schema
jul 01, 2016 12:52:42 PM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: HHH000232: Schema update complete
jul 01, 2016 12:52:42 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping registerHandlerMethod
INFO: Mapped "{[/],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String com.vacature.controller.HomeController.home(org.springframework.ui.Model)
jul 01, 2016 12:52:42 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Fri Jul 01 12:52:40 CEST 2016]; root of context hierarchy
jul 01, 2016 12:52:42 PM org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter initControllerAdviceCache
INFO: Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Fri Jul 01 12:52:40 CEST 2016]; root of context hierarchy
jul 01, 2016 12:52:42 PM org.springframework.web.servlet.handler.SimpleUrlHandlerMapping registerHandler
INFO: Mapped URL path [/resources/**] onto handler 'org.springframework.web.servlet.resource.ResourceHttpRequestHandler#0'
jul 01, 2016 12:52:42 PM org.springframework.orm.hibernate4.HibernateTransactionManager afterPropertiesSet
INFO: Using DataSource [org.springframework.jdbc.datasource.DriverManagerDataSource@21722714] of Hibernate SessionFactory for HibernateTransactionManager
jul 01, 2016 12:52:42 PM org.springframework.web.context.ContextLoader initWebApplicationContext
 INFO: Root WebApplicationContext: initialization completed in 1467 ms

1 个答案:

答案 0 :(得分:0)

@Id应为longintshort类型。
例如。 public long vacatuurId;

如果这没有解决问题,你可以包括堆栈跟踪吗?

旁注:因为你已经有了setter和getter,所以你应该将这些变量设为私有 例如。 private long vacatuurId;