FableBlaze
FableBlaze

Reputation: 1895

JPAContainerFactory does not create the database table

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?

Upvotes: 1

Views: 143

Answers (2)

Andy Ying
Andy Ying

Reputation: 22

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

Upvotes: 0

Andy Ying
Andy Ying

Reputation: 22

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

Upvotes: 0

Related Questions