13 Replies Latest reply on Aug 11, 2009 5:51 PM by Brian Pedersen

    No tables are generated from entities

    henrik kristiansen Newbie
      @Entity
      @Table(name="BoatType")
      @Name("BoatType")
      public class BoatType implements Serializable {

          @Id
          @GeneratedValue
          protected long Id;

          @NotNull
          @Length(max=250)
          protected String name;

          public long getId() {
              return Id;
          }

          public String getName() {
              return name;
          }

          public void setName(String name) {
              this.name = name;
          }
      }

      <persistence xmlns="http://java.sun.com/xml/ns/persistence"
                   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
                   version="1.0">
                       <persistence-unit name="Hison">
            <provider>org.hibernate.ejb.HibernatePersistence</provider>
            <jta-data-source>HisonDatasource</jta-data-source>
            <properties>
               <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
               <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
               <property name="hibernate.show_sql" value="true"/>
               <property name="hibernate.format_sql" value="true"/>
               <property name="jboss.entity.manager.factory.jndi.name" value="java:/HisonEntityManagerFactory"/>
            </properties>
         </persistence-unit>
           </persistence>


      11:43:00,656 INFO [SchemaExport] Running hbm2ddl schema export
      11:43:00,656 INFO [SchemaExport] exporting generated schema to database
      11:43:00,656 INFO [SchemaExport] Executing import script: /import.sql
      11:43:00,656 INFO [SchemaExport] schema export complete

      after deploying my database is still empty
        • 1. Re: No tables are generated from entities
          Brian Pedersen Newbie

          I have exactly the same problem. Someone must know the solution for this?

          • 2. Re: No tables are generated from entities
            Daniel Wachter Newbie

            I don't know if this is the problem but in your example there is missing the setter for id, jpa needs this for setting the value in the table.


            Beside you should habituate to make the jpa annotations on the getters and not on the variable declarations.

            • 3. Re: No tables are generated from entities
              Shervin Asgari Master

              And you datasource? How does that look?


              Should be like this


              <?xml version="1.0" encoding="UTF-8"?>
              
              <!DOCTYPE datasources
                  PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
                  "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
                  
              <datasources>
                 
                 <local-tx-datasource>
                    <jndi-name>HisonDatasource</jndi-name>
                        <connection-url>jdbc:mysql://localhost:3306/saksapp</connection-url>
                    <driver-class>com.mysql.jdbc.Driver</driver-class>
                    <user-name>user</user-name>
                    <password>password</password>
                    
                 </local-tx-datasource>
                  
              </datasources>



              • 4. Re: No tables are generated from entities
                henrik kristiansen Newbie
                I have updated my entity but it still doesn't generate my table.
                I used seam-gen to build my configuration. Should I have done some extra configuration manually afterwards?!

                @Entity
                @Table(name="BoatType")
                @Name("BoatType")
                public class BoatType implements Serializable {

                    protected long Id;
                    protected String name;

                    @Id
                    @GeneratedValue
                    public long getId() {
                        return Id;
                    }

                    @NotNull
                    @Length(max=250)
                    public String getName() {
                        return name;
                    }

                    public void setId(long id) {
                        Id = id;
                    }

                    public void setName(String name) {
                        this.name = name;
                    }
                }



                Here is my datasource

                <?xml version="1.0" encoding="UTF-8"?>
                <!DOCTYPE datasources
                    PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
                    "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
                <datasources>
                  
                   <local-tx-datasource>
                      <jndi-name>HisonDatasource</jndi-name>
                      <use-java-context>false</use-java-context>
                      <connection-url>jdbc:mysql://localhost:3306/Hison</connection-url>
                      <driver-class>com.mysql.jdbc.Driver</driver-class>
                      <user-name>root</user-name>
                      <password>password</password>
                   </local-tx-datasource>
                   
                </datasources>
                • 5. Re: No tables are generated from entities
                  Henki Lubis Newbie

                  Try add this line in your persistence.xml




                  <class>your.package.and.your.class.name</class>



                  and restart app server

                  • 6. Re: No tables are generated from entities
                    Daniel Wachter Newbie

                    Did you receive any warnings, errors in your log file?
                    Without the informations from the log it's very hard to help you!


                    Try to alter your persistence.xml by adding the java:/ to your datasource.xml:


                    <jta-data-source>java:/HisonDatasource</jta-data-source>



                    • 7. Re: No tables are generated from entities
                      Oguzhan YALCIN Newbie

                      If your project is a WAR project instead of EAR project you have to manually map the entity classes mentioned in the previous  replies if the problem  still occurs after applying this try removing the <use-java-context> from datasource.

                      • 8. Re: No tables are generated from entities
                        Ambrish Singh Newbie

                        Hi,


                        Change this line in (persistence.xml)




                        <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
                        





                        with this one,




                        <property name="hibernate.hbm2ddl.auto" value="create"/>





                        or you can also use validate,update inplace of create.



                        Regards


                        Ambrish

                        • 9. Re: No tables are generated from entities
                          Leo van den berg Master

                          Henrik,


                          Some questions/remarks:


                          - Does the database Hison exist, prior to deploying (in other words have you created an empty database with the name Hison),
                          - Are you checking the existence of tables while the application is still running (create-drop means that the tables will be dropped after closing the application). Do not use validate, but that used when you already have a database with tables. It will not create anything.
                          - take out


                          <use-java-context>false</use-java-context> 



                          which is needed for (not) prefixing with java:/ and is used for accessing the datasource remotely. Possibly wont hurt, but you never know for sure
                          - As of jboss 5.1 I needed to mention each class mapping in persistence.xml for JPA. If you're using this server-version add class lines as mentioned by kie kie before.
                          - I also use the java prefix so change the line to:



                          <jta-data-source>java:/HisonDatasource</jta-data-source>






                          Finally, I don't want to start a holy war on JPA annotation usage; I doesn't matter where you put your annotations. Hibernate looks at the @Id placement (on the variable or on the getter) and assumes that the rest is on the same location. Just a matter of taste, works the same.



                          • 10. Re: No tables are generated from entities
                            henrik kristiansen Newbie
                            First of all I'm sorry about my late reply...
                            My project is an EAR project, I can post the configuration if needed
                            I have created the empty “Hison” database before I deployed the application.
                            After the deployment, I check the database and it's still empty

                            I thought J2EE located the class annotated by @entity, so that you didn't have to write them yourself in the persistence file?
                            I have updated my persistence.xml to:

                            <persistence-unit name="Hison">
                                 <provider>org.hibernate.ejb.HibernatePersistence</provider>
                                       <jta-data-source>java:/HisonDatasource</jta-data-source>
                                       <class>org.hison.model.BoatType</class>
                                       <properties>
                                               <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
                                               <property name="hibernate.hbm2ddl.auto" value="create"/>
                                               <property name="hibernate.show_sql" value="true"/>
                                               <property name="hibernate.format_sql" value="true"/>
                                               <property name="jboss.entity.manager.factory.jndi.name"  value="java:/HisonEntityManagerFactory"/>
                                       </properties>
                            </persistence-unit>

                            My updated  datasource:  

                            <datasources>  
                               <local-tx-datasource>
                                  <jndi-name>HisonDatasource</jndi-name>
                                  <connection-url>jdbc:mysql://localhost:3306/Hison</connection-url>
                                  <driver-class>com.mysql.jdbc.Driver</driver-class>
                                  <user-name>root</user-name>
                                  <password>horsens</password>
                               </local-tx-datasource>   
                            </datasources>

                            After the changes I'm getting the following errors/warnings:

                            14:16:26,171 WARN  [JBossASSecurityMetadataStore] WARNING! POTENTIAL SECURITY RISK. It has been detected that the MessageSucker component which sucks messages from one node to another has not had its password changed from the installation default. Please see the JBoss Messaging user guide for instructions on how to do this.

                            14:16:26,203 WARN  [AnnotationCreator] No ClassLoader provided, using TCCL: org.jboss.managed.api.annotation.ManagementComponent

                            14:16:26,375 WARN  [AnnotationCreator] No ClassLoader provided, using TCCL: org.jboss.managed.api.annotation.ManagementComponent

                            14:16:45,531 WARN  [InjectInterceptorsFactory] WEIRDNESS IN AOP: advisor org.jboss.ejb3.aop.ExtendedManagedObjectAdvisor@17e7be4

                            14:16:45,546 WARN  [InjectInterceptorsFactory] WEIRDNESS IN AOP: advisor org.jboss.ejb3.aop.ExtendedManagedObjectAdvisor@17e7be4

                            14:16:45,562 WARN  [InjectInterceptorsFactory] WEIRDNESS IN AOP: advisor org.jboss.ejb3.aop.ExtendedManagedObjectAdvisor@17e7be4

                            14:16:45,562 WARN  [InjectInterceptorsFactory] WEIRDNESS IN AOP: advisor org.jboss.ejb3.aop.ExtendedManagedObjectAdvisor@17e7be4

                            14:16:47,281 WARN  [Ejb3Configuration] Persistence provider caller does not implement the EJB3 spec correctly. PersistenceUnitInfo.getNewTempClassLoader() is null.

                            14:16:50,062 WARN  [SessionFactoryObjectFactory] InitialContext did not implement EventContext

                            14:17:00,421 WARN  [PersistentPermissionResolver] no permission store available - please install a PermissionStore with the name 'org.jboss.seam.security.jpaPermissionStore' if persistent permissions are required.


                            • 11. Re: No tables are generated from entities
                              Brian Pedersen Newbie

                              I'm using Seam 2.2.0.GA , JBoss Application 5.1.0.GA, Mysql and Java 1.6
                              I have updated my files as described in the posts but I get the same warnings as Henrik.
                              Is this a common error or have I/We just filled seam-gen with bad information?!

                              • 12. Re: No tables are generated from entities
                                Leo van den berg Master

                                Hi Brian,
                                I think it has to do with permissions and/or access to the databasde, because to be honets I can't see anything wrong in your code, so it should work.


                                Leo

                                • 13. Re: No tables are generated from entities
                                  Brian Pedersen Newbie

                                  The database is on my local PC. I can log on it with my credentials, which i also use in the code.
                                  I have had seam up and running earlier, but I have updated both JBoss, seam and Mysql to the latest versions. Can it be a compatibility issue?


                                  btw sorry for hijacking the thread