0

I'm using below maven dependencies in my spring mvc project:

<!-- Hibernate Validator -->
<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>4.2.0.Final</version>
</dependency>

<!-- hibernate -->


<dependency>
    <groupId>postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <version>9.1-901.jdbc4</version>
</dependency>

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>4.2.16.Final</version>
</dependency>
<dependency>
    <groupId>org.hibernate.javax.persistence</groupId>
    <artifactId>hibernate-jpa-2.0-api</artifactId>
    <version>1.0.0.Final</version>
</dependency>

and here is my persistence.xml

<?xml version="1.0" encoding="UTF-8" ?>
<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="PersistenceUnit" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <class>com.sepehrgh.domain.entity.UploadEntity</class>

    <properties>
        <property name="hibernate.connection.url" value="jdbc:postgresql://localhost/test_jpa" />
        <property name="hibernate.connection.useUnicode" value="true" />
        <property name="hibernate.connection.characterEncoding" value="UTF-8" />
        <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
        <property name="hibernate.connection.username" value="postgres" />
        <property name="hibernate.connection.password" value="" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL82Dialect" />
        <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
        <property name="hibernate.show_sql" value="true"/>
        <property name="hibernate.format_sql" value="true"/>
    </properties>
</persistence-unit>
</persistence>

UploadEntity:

@Entity
@Table(name = "uploads", schema = "public")
public class UploadEntity {
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Id
    @Column
    private long id;
    @Column
    private String title;
    @Column(columnDefinition = "text")
    private String description;

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

}

When I run project. I get following error, so no table get created: 201

6-05-30 21:07:38 ERROR SchemaExport:425 - HHH000389: Unsuccessful: create table public.uploads (id  bigserial not null, description text, title varchar(255), primary key (id))
2016-05-30 21:07:38 ERROR SchemaExport:426 - type not found or user lacks privilege: BIGSERIAL

And its totally strange because I'm using same codes and logic in another older project and its totally working! Am I missing something ?

Also you might need to know that persistence.xml is under META-INF in directory marked as resources. same place it is in all my other working projects! any idea?

FYI: when I run this query " create table public.uploads (id bigserial not null, description text, title varchar(255), primary key (id)) " in postgresql server, it works just fine! my postgresql version is 9.4, and Im running my project in Intellij Idea with TomEE web-profile 1.7

Sepehr GH
  • 1,297
  • 1
  • 17
  • 39

1 Answers1

0

In a EE server JPA uses non-jta-datasource for RESOURCE_LOCAL persistence-unit.

Either configure the datasource in resources.xml/tomee.xml or set in conf/system.properties: openejb.guess.resource-local-datasource-properties-configured=true

Romain Manni-Bucau
  • 3,354
  • 1
  • 16
  • 13