1

I expected JPAContainer to create a database table automatically when 'hbm2ddl.auto' is set to 'update', however this seems to not be the case. Is there something wrong in my configuration or should i use something else to get the desired functionality?

I am using the following command to create a JPAContainer

accounts = JPAContainerFactory.make(Account.class, RumUI.PERSISTENCE_UNIT);

The Accounts class is

@Entity
@Table(name="accounts")    
public class Account implements Serializable {
    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(generator="increment")
    @GenericGenerator(name="increment", strategy = "increment")
    private Long id;

    @NotNull
    @Size(min = 2, max = 24)
    @Column(name = "name", unique=true)
    private String name;

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

    @NotNull
    @Size(min = 2, max = 24)
    @Column(name = "password")
    private String password;

    @NotNull
    @Column(name = "role")
    private String role;

    public Account() {
    }

    //getters and setters

}

And the persistence.xml

<persistence-unit name="RuM">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <class>ee.ut.cs.rum.domain.Account</class>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
            <property name="hibernate.connection.url" value="jdbc:postgresql://127.0.0.1:5432/RuM"/>
            <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver"/>
            <property name="hibernate.connection.username" value="postgres"/>
            <property name="hibernate.connection.password" value="postgres"/>
            <property name="hibernate.show_sql" value="true"/>
            <property name="hibernate.format_sql" value="true"/>
            <property name="hbm2ddl.auto" value="update"/>
            <property name="hibernate.current_session_context_class" value="thread" />
        </properties>
    </persistence-unit>

I would expect that the database table 'accounts' would be created automatically since 'hbm2ddl.auto' is set to 'update'. However the table is not created.

If i create Hibernate ServiceRegistry and SessionFactory directly using the same settings (using a Configuration object), then the table is created.

What am i missing here?

FableBlaze
  • 1,785
  • 3
  • 16
  • 21

2 Answers2

0

@Entity @Table(name="t_accounts) public class Accout……

Andy Ying
  • 22
  • 2
  • The entity annotation was missing from my question, but was present in the actual source. Otherwise ServiceRegistry and SessionFactory would also not have worked. But thank you for noticing. I have edited the question accordingly. – FableBlaze Apr 12 '15 at 03:31
  • How do you solve the question? l want to learn this.Thank you ! – Andy Ying Apr 12 '15 at 06:24
  • Users can upvote or downvote the proposed solutions. The user who asked the question can select one of the solutions as the accepted one. – FableBlaze Apr 12 '15 at 13:58
  • can you show your applicationContext.xml .`accounts = JPAContainerFactory.make(Account.class, RumUI.PERSISTENCE_UNIT);` l never use this in my jpa project. I want to know ,why you need this. – Andy Ying Apr 12 '15 at 14:26
  • I believe that vaadin has applicationcontext.xml file. It least i do not seem to have one in my project. My project is based on the default Vaadin project. – FableBlaze Apr 12 '15 at 17:23
  • Can you tell me what frame are you use in your project? – Andy Ying Apr 13 '15 at 04:54
0

org.hibernate.ejb.HibernatePersistence you can try this provider

Andy Ying
  • 22
  • 2
  • Tried it and 'hbm2ddl.auto' == 'update' setting is still ignored. I feel that it is Vaadin's JPAContainer specific – FableBlaze Apr 12 '15 at 12:48