0

I'm using Wicket in combination with Spring and Hibernate, at least that's what I'm trying to do, the problem comes with auto generating the tables with Hibernate annotations.

I've been trying many changes in the configuration but can't seem to figure out why my configuration doesn't generate any tables. And I'm hoping someone can point me in the right direction, even about the Spring configuration I'm not sure.

I've included all the files I'm using to try to make this work in links, so that it won't be a very long list of configuration files.

I'm using the following class with annotations, 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 } 

I'm using the following dependencies described in my pom.xml:

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

I'm using the following configuration in applicationContext.xml and properties:

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

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

And finally web.xml:

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

If I'm missing any files you'd like to see, just ask.

Edit :-

Added start up logging:

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 [email protected]:8080 INFO - SslContextFactory - Enabled Protocols [SSLv2Hello, SSLv3, TLSv1, TLSv1.1, TLSv1.2] of [SSLv2Hello, SSLv3, TLSv1, TLSv1.1, TLSv1.2] INFO - AbstractConnector - Started [email protected]:8443 

Edit :-

I tried renaming my User class to MediaUser and the @Table annotation to mediaUser to avoid problems with the USER word being reserved for some databases.

What I've found from the start up logging, as seen above, is that it does say it's running the export:

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

Also tried different approaches to the Hibernate annotations, like using other imports, @Table is now used by importing javax.persistence.Table, but I also tried the Hibernate org.hibernate.annotations.table, thus far without a solution to my problem.

10
  • 1
    What's the value of hibernate.hbm2ddl.auto in your hibernate config? Commented Nov 28, 2012 at 18:34
  • The value of hibernate.hbm2ddl.auto is create Commented Nov 28, 2012 at 18:35
  • Where is hibernate.cfg.xml ? Commented Nov 28, 2012 at 18:36
  • @BhavikAmbani what should be in hibernate.cfg.xml? I'm quite the beginner what comes to configuring these things. Commented Nov 28, 2012 at 18:40
  • 1
    What does it mean "does not generate table"? Do you see any errors related to missing tables? In other words, are you sure that Hibernate gets initialized in your test scenario? Commented Nov 28, 2012 at 18:45

3 Answers 3

1

I've found the answer to my problem, the annotations need either be set on the instance variables or on the class and it's methods and it needs to implement Serializable like:

@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; } } 
Sign up to request clarification or add additional context in comments.

Comments

0

I had the same problem ... in my case, the problem was because the USER word is reserved for some data bases.

So, considering that your hibernate configuration files are right, just add a prefix in all your tables and the problem was solved.

I hope this solve your problem too =)

4 Comments

Unfortunately that didn't help. I renamed my User class to MediaUser and the @Table annotation to mediaUser and still nothing happened. It does say it's running the export. INFO - SchemaExport - Running hbm2ddl schema export INFO - SchemaExport - exporting generated schema to database INFO - SchemaExport - schema export complete
are you sure , <prop key="hibernate.show_sql" >true</prop> and see the queries going
user is a reserved keyword in most databases, so use something like user_table in @Table annotation
@SubinS Like I said, I renamed the table annotation and the class to mediaUser and MediaUser. That didn't help. The property does say true, but it doesn't show me any queries, that's probably why there isn't a table created, but I can't find the solution to why it isn't generating queries/sql.
0

Try to use

@EntityScan({" yourentitypackagehere "}) 

in your springboot application

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.