JPA + Hibernate + PostgreSQL9.4で接続エラー?

439 views
Skip to first unread message

Hidetoshi Kamata

unread,
Jul 6, 2015, 6:44:18 AM7/6/15
to pla...@googlegroups.com
カマタです。

PostgreSQL上に事前に作成したテーブルに対して、
Play上のプログラムよりアクセスしようとしています。

DB接続の設定エラーと思しき現象が起こっています。
設定の問題ではないかと考えているのですが、
問題点があれば指摘して頂けると有難いです。

環境は以下になります。
Windows 7 Professional
Play framework 2.4.2
PostgreSQL 9.4.4 (ローカルPCインストール)

build.sbt
name := """sample"""

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayJava)

scalaVersion := "2.11.6"

libraryDependencies ++= Seq(
  javaJdbc,
  cache,
  javaWs,
  javaJpa,
  "org.hibernate" % "hibernate-core" % "4.3.10.Final",
  "org.hibernate" % "hibernate-entitymanager" % "4.3.10.Final",
  "org.hibernate.javax.persistence" % "hibernate-jpa-2.1-api" % "1.0.0.Final",
  "org.postgresql" % "postgresql" % "9.4-1201-jdbc41"
)

routesGenerator := InjectedRoutesGenerator


application.conf のDB接続設定周り
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/book_shelf"
db.default.jndiName=DefaultDS
db.default.user=postgres
db.default.password=testpassword


persistence.xml
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"
             version="2.1">

    <persistence-unit name="defaultPersistenceUnit" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
        <non-jta-data-source>DefaultDS</non-jta-data-source>
        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQL94Dialect"/>
        </properties>
    </persistence-unit>

</persistence>


Modelクラスの内容
package models;

import javax.persistence.*;

@Entity
public class Book {
 @Id
 public Long id;
 public String name;
 
 public Book() { }
}

エラーの内容
[ProvisionException: Unable to provision, see the following errors:

1) Error injecting constructor, javax.persistence.PersistenceException: Unable to build entity manager factory
  at play.db.jpa.DefaultJPAApi$JPAApiProvider.<init>(DefaultJPAApi.java:35)
  at play.db.jpa.DefaultJPAApi$JPAApiProvider.class(DefaultJPAApi.java:30)
  while locating play.db.jpa.DefaultJPAApi$JPAApiProvider
  while locating play.db.jpa.JPAApi

1 error]

PostgreSQLの状態


Hidetoshi Kamata

unread,
Jul 6, 2015, 7:32:17 PM7/6/15
to pla...@googlegroups.com
(画像貼り付け失敗でご迷惑おかけしました)

補足です。Ebeanではすんなり接続できました。

build.sbt
name := """sample"""
version
:= "1.0-SNAPSHOT"

lazy val root
= (project in file(".")).enablePlugins(PlayJava, PlayEbean)

scalaVersion
:= "2.11.6"
libraryDependencies
++= Seq(
  javaJdbc
,
  cache
,
  javaWs
,

 
"org.postgresql" % "postgresql" % "9.4-1201-jdbc41"
)
routesGenerator
:= InjectedRoutesGenerator

application.conf のDB接続設定周り→(基本変更なし)

変更点

# Evolutions
# ~~~~~
# You can disable evolutions if needed
play
.evolutions.enabled=false

# You can disable evolutions for a specific datasource if necessary
play
.evolutions.db.default.enabled=false

#jpa.default=defaultPersistenceUnit
ebean
.default="models.*"


persistence.xml変更なし(むしろおかしい?)

Modelクラスの内容
package models;
import java.util.Date;
import javax.persistence.*;
import com.avaje.ebean.*;
import com.avaje.ebean.annotation.*;

@Entity
@Table(name = "books")
public class Book extends Model {
 
@Id
 
@GeneratedValue

 
public Long id;

 
public String name;

 
 
@CreatedTimestamp
 
@Column(name = "create_at")
 
public Date createAt;
 
 
@Version
 
@Column(name = "update_at")
 
public Date updateAt;
 
 
public static final Find<Long, Book> finder = new Find<Long, Book>(){};
}




Reply all
Reply to author
Forward
0 new messages