0

我将 Wicket 与 Spring 和 Hibernate 结合使用,至少这是我想要做的,问题在于自动生成带有 Hibernate 注释的表。

我一直在尝试对配置进行许多更改,但似乎无法弄清楚为什么我的配置没有生成任何表。而且我希望有人能指出我正确的方向,即使是关于我不确定的 Spring 配置。

我已经在链接中包含了我用来尝试使其工作的所有文件,因此它不会是一个很长的配置文件列表。

我正在使用以下带有注释的类http://schrealex.com/downloads/User.java

@Entity
@Table(name="user")
public class User {

    @Id
    @Column(name="user_id", unique=true, nullable=false)
    @GeneratedValue(strategy=GenerationType.AUTO)
    private Long id;

    @Column(name="username")
    private String username;

    @Column(name="password")
    private String password;

    @Column(name="firstname")
    private String firstname;

    @Column(name="lastname")
    private String lastname;

    @Column(name="birthDate")
    private Date birthDate;

    @Column(name="email")
    private String email;

    @Column(name="profile_image")
    private String profile_image;

    public User() {

    }

    public User(String username, String password, String email) {
        this.username = username;
        this.password = password;
        this.email = email;

    }

    // Getter and Setter methods

}

我正在使用 pom.xml 中描述的以下依赖项:

http://schrealex.com/downloads/pom.xml

我在 applicationContext.xml 和属性中使用以下配置:

http://schrealex.com/downloads/application.properties

http://schrealex.com/downloads/applicationContext.xml

最后是 web.xml:

http://schrealex.com/downloads/web.xml

如果我遗漏了您想查看的任何文件,请询问。

编辑 :-

添加了启动日志记录:

SSL access to the quickstart has been enabled on port 8443
You can access the application using SSL on https://localhost:8443

>>> STARTING EMBEDDED JETTY SERVER, PRESS ANY KEY TO STOP
INFO  - Server                     - jetty-7.6.3.v20120416
INFO  - tandardDescriptorProcessor - NO JSP Support for /, did not find org.apache.jasper.servlet.JspServlet
INFO  - /                          - Initializing Spring root WebApplicationContext
INFO  - ContextLoader              - Root WebApplicationContext: initialization started
INFO  - XmlWebApplicationContext   - Refreshing org.springframework.web.context.support.XmlWebApplicationContext@1c35ce99: display name [Root WebApplicationContext]; startup date [Wed Nov 28 19:53:33 CET 2012]; root of context hierarchy
INFO  - XmlBeanDefinitionReader    - Loading XML bean definitions from class path resource [applicationContext.xml]
INFO  - XmlWebApplicationContext   - Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@1c35ce99]: org.springframework.beans.factory.support.DefaultListableBeanFactory@2a9b5441
INFO  - pertyPlaceholderConfigurer - Loading properties file from URL [file:/C:/Users/CE_REAL/Documents/Development/media-database/target/classes/application.properties]
INFO  - DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@2a9b5441: defining beans [wicketApplication,placeholderConfigurer,dataSource,transactionManager,transactionInterceptor,managerTemplate,sessionFactory]; root of factory hierarchy
INFO  - Version                    - Hibernate Annotations 3.4.0.GA
INFO  - Environment                - Hibernate 3.2.6
INFO  - Environment                - hibernate.properties not found
INFO  - Environment                - Bytecode provider name : cglib
INFO  - Environment                - using JDK 1.4 java.sql.Timestamp handling
INFO  - Version                    - Hibernate Commons Annotations 3.1.0.GA
INFO  - AnnotationConfiguration    - Hibernate Validator not found: ignoring
INFO  - notationSessionFactoryBean - Building new Hibernate SessionFactory
INFO  - earchEventListenerRegister - Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
INFO  - ConnectionProviderFactory  - Initializing connection provider: org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider
INFO  - SettingsFactory            - RDBMS: MySQL, version: 5.5.16-log
INFO  - SettingsFactory            - JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.1.21 ( Revision: ${bzr.revision-id} )
INFO  - Dialect                    - Using dialect: org.hibernate.dialect.MySQLDialect
INFO  - TransactionFactoryFactory  - Transaction strategy: org.springframework.orm.hibernate3.SpringTransactionFactory
INFO  - actionManagerLookupFactory - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
INFO  - SettingsFactory            - Automatic flush during beforeCompletion(): disabled
INFO  - SettingsFactory            - Automatic session close at end of transaction: disabled
INFO  - SettingsFactory            - JDBC batch size: 15
INFO  - SettingsFactory            - JDBC batch updates for versioned data: disabled
INFO  - SettingsFactory            - Scrollable result sets: enabled
INFO  - SettingsFactory            - JDBC3 getGeneratedKeys(): enabled
INFO  - SettingsFactory            - Connection release mode: auto
INFO  - SettingsFactory            - Maximum outer join fetch depth: 2
INFO  - SettingsFactory            - Default batch fetch size: 1
INFO  - SettingsFactory            - Generate SQL with comments: disabled
INFO  - SettingsFactory            - Order SQL updates by primary key: disabled
INFO  - SettingsFactory            - Order SQL inserts for batching: disabled
INFO  - SettingsFactory            - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
INFO  - ASTQueryTranslatorFactory  - Using ASTQueryTranslatorFactory
INFO  - SettingsFactory            - Query language substitutions: {}
INFO  - SettingsFactory            - JPA-QL strict compliance: disabled
INFO  - SettingsFactory            - Second-level cache: enabled
INFO  - SettingsFactory            - Query cache: disabled
INFO  - SettingsFactory            - Cache provider: org.hibernate.cache.EhCacheProvider
INFO  - SettingsFactory            - Optimize cache for minimal puts: disabled
INFO  - SettingsFactory            - Structured second-level cache entries: disabled
INFO  - SettingsFactory            - Echoing all SQL to stdout
INFO  - SettingsFactory            - Statistics: disabled
INFO  - SettingsFactory            - Deleted entity synthetic identifier rollback: disabled
INFO  - SettingsFactory            - Default entity-mode: pojo
INFO  - SettingsFactory            - Named query checking : enabled
INFO  - SessionFactoryImpl         - building session factory
WARN  - ConfigurationFactory       - No configuration found. Configuring ehcache from ehcache-failsafe.xml  found in the classpath: jar:file:/C:/Users/CE_REAL/.m2/repository/net/sf/ehcache/ehcache/1.2.3/ehcache-1.2.3.jar!/ehcache-failsafe.xml
INFO  - essionFactoryObjectFactory - Not binding factory to JNDI, no JNDI name configured
INFO  - SchemaExport               - Running hbm2ddl schema export
INFO  - SchemaExport               - exporting generated schema to database
INFO  - SchemaExport               - schema export complete
INFO  - ContextLoader              - Root WebApplicationContext: initialization completed in 671 ms
INFO  - ContextHandler             - started o.e.j.w.WebAppContext{/,file:/C:/Users/CE_REAL/Documents/Development/media-database/src/main/webapp/},src/main/webapp
WARN  - WebXmlFile                 - web.xml: No url-pattern found for 'filter' with name 'wicket-spring-hibernate'
INFO  - WebXmlFile                 - web.xml: url mapping found for filter with name wicket-spring-hibernate:
WARN  - WicketFilter               - Unable to determine filter path from filter init-param, web.xml, or servlet 3.0 annotations. Assuming user will set filter path manually by calling setFilterPath(String)
INFO  - Application                - [wicket-spring-hibernate] init: Wicket core library initializer
INFO  - RequestListenerInterface   - registered listener interface [RequestListenerInterface name=IBehaviorListener, method=public abstract void org.apache.wicket.behavior.IBehaviorListener.onRequest()]
INFO  - RequestListenerInterface   - registered listener interface [RequestListenerInterface name=IFormSubmitListener, method=public abstract void org.apache.wicket.markup.html.form.IFormSubmitListener.onFormSubmitted()]
INFO  - RequestListenerInterface   - registered listener interface [RequestListenerInterface name=ILinkListener, method=public abstract void org.apache.wicket.markup.html.link.ILinkListener.onLinkClicked()]
INFO  - RequestListenerInterface   - registered listener interface [RequestListenerInterface name=IOnChangeListener, method=public abstract void org.apache.wicket.markup.html.form.IOnChangeListener.onSelectionChanged()]
INFO  - RequestListenerInterface   - registered listener interface [RequestListenerInterface name=IRedirectListener, method=public abstract void org.apache.wicket.IRedirectListener.onRedirect()]
INFO  - RequestListenerInterface   - registered listener interface [RequestListenerInterface name=IResourceListener, method=public abstract void org.apache.wicket.IResourceListener.onResourceRequested()]
INFO  - Application                - [wicket-spring-hibernate] init: Wicket extensions initializer
INFO  - WebApplication             - [wicket-spring-hibernate] Started Wicket version 6.2.0 in DEVELOPMENT mode
********************************************************************
*** WARNING: Wicket is running in DEVELOPMENT mode.              ***
***                               ^^^^^^^^^^^                    ***
*** Do NOT deploy to your live server(s) without changing this.  ***
*** See Application#getConfigurationType() for more information. ***
********************************************************************
INFO  - WebXmlFile                 - web.xml: url mapping found for filter with name wicket.media-database: [/login/*]
INFO  - Application                - [wicket.media-database] init: Wicket core library initializer
INFO  - Application                - [wicket.media-database] init: Wicket extensions initializer
INFO  - WebApplication             - [wicket.media-database] Started Wicket version 6.2.0 in DEVELOPMENT mode
********************************************************************
*** WARNING: Wicket is running in DEVELOPMENT mode.              ***
***                               ^^^^^^^^^^^                    ***
*** Do NOT deploy to your live server(s) without changing this.  ***
*** See Application#getConfigurationType() for more information. ***
********************************************************************
INFO  - AbstractConnector          - Started SocketConnector@0.0.0.0:8080
INFO  - SslContextFactory          - Enabled Protocols [SSLv2Hello, SSLv3, TLSv1, TLSv1.1, TLSv1.2] of [SSLv2Hello, SSLv3, TLSv1, TLSv1.1, TLSv1.2]
INFO  - AbstractConnector          - Started SslSocketConnector@0.0.0.0:8443

编辑 :-

我尝试将我的 User 类重命名为 MediaUser 并将 @Table 注释重命名为 mediaUser 以避免为某些数据库保留 USER 字的问题。

如上所示,我从启动日志记录中发现,它确实说它正在运行导出:

INFO - SchemaExport - Running hbm2ddl schema export 
INFO - SchemaExport - exporting generated schema to database 
INFO - SchemaExport - schema export complete

还尝试了 Hibernate 注释的不同方法,比如使用其他导入,@Table 现在通过导入 javax.persistence.Table 来使用,但我也尝试了 Hibernate org.hibernate.annotations.table,到目前为止还没有解决我的问题。

4

3 回答 3

1

我找到了问题的答案,注释需要在实例变量或类上设置,它的方法,它需要实现 Serializable,如:

@Entity
public class User implements Serializable {

    @Id
    @GeneratedValue
    private Long id;

    private String username;
    private String password;
    private String firstname;
    private String lastname;
    private Date birthDate;
    private String email;
    private String profileImage;

    public User() {

    }

    public User(String username, String password, String email) {
        this.username = username;
        this.password = password;
        this.email = email;

    }

    // Getter and Setter methods

    @Column
    public getUsername() {
        return username;
    }

    @Column
    public getPassword() {
        return password;
    }

    @Column
    public getFirstname() {
        return firstname;
    }

    @Column
    public getLastname() {
        return lastname;
    }

    @Column
    @Temporal(TemporalType.TIME)
    public getBirthDate() {
        return birthDate;
    }

    @Column
    public getEmail() {
        return email;
    }

    @Column
    public getProfileImage() {
        return profileImage;
    }
}
于 2012-12-20T13:06:33.743 回答
0

我有同样的问题......在我的情况下,问题是因为 USER 字是为某些数据库保留的。

因此,考虑到您的休眠配置文件是正确的,只需在所有表中添加前缀即可解决问题。

我希望这也能解决你的问题=)

于 2012-11-28T19:03:18.740 回答
0

尝试使用

@EntityScan({" yourentitypackagehere "})

在你的 springboot 应用程序中

于 2017-11-09T03:48:47.203 回答