1

我正在使用 play-2.1.3 框架。我想从数据库中检索数据。我正在使用 eclipse、hibernate 和 postgreSQL。

当我想使用实体管理器从数据库中检索数据时,它给了我一个错误,我找不到答案......请帮助我。

----------------------日志文件中的错误------------------------ --

2013-10-06 19:08:53,729 - [ERROR] - from org.hibernate.engine.jdbc.spi.SqlExceptionHelper in play-akka.actor.default-dispatcher-3 
ERROR: column client0_._ebean_intercept does not exists
  Position: 31

我的实体类:

package models;
import play.db.ebean.*;
import play.data.validation.*;
import javax.persistence.*;
@Entity
@Table(name="clients")
public class Client extends Model {


    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Id
    @Constraints.Min(10)
    public Long id;

  @Constraints.Required
  public String username;

  @Constraints.Required
  public String email;

  @Constraints.Required
  public String password;

  @Constraints.Required
  public String passwordsignup_confirm;

  public boolean online;


  public boolean getOnline() {
        return online;
    }

    public void setOnline(boolean online) {
        this.online = online;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getConfirm() {
        return passwordsignup_confirm;
    }

    public void setConfirm(String confirm) {
        this.passwordsignup_confirm= confirm;
    }



}

------------------在我的控制器类中----------

public static Client ckeckEmailAndPassword(String email, String password)
    {
        Client client = null;
        em.getTransaction().begin();

            try
            {
                List<Client> cli = em.createQuery("SELECT d FROM Client d WHERE d.email = ?1 AND d.password = ?2").setParameter(1, email).setParameter(2, password).getResultList();

                em.getTransaction().commit();

            }catch(Exception e){
                e.printStackTrace();
            }
            return client;

    }

--------------------------------------Build.scala

import sbt._
import Keys._
import play.Project._

object ApplicationBuild extends Build {

  val appName         = "unity"
  val appVersion      = "1.0-SNAPSHOT"

  val appDependencies = Seq(
    // Add your project dependencies here,

    javaCore,
    javaJdbc,
    javaEbean,
    "org.hibernate" % "hibernate-entitymanager" % "4.2.5.Final"
  )

  val main = play.Project(appName, appVersion, appDependencies).settings(
      ebeanEnabled := false      
  )





}

------------------------------------------------------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_2_0.xsd"
             version="2.0">

    <persistence-unit name="manager" transaction-type="RESOURCE_LOCAL">
        <provider>org.hibernate.ejb.HibernatePersistence</provider>
        <non-jta-data-source>DefaultDS</non-jta-data-source>

        <properties>
            <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
        </properties>
    </persistence-unit>


</persistence>

- - - - - - - - - - - - - - - - - - - - - - - - -应用.conf

 db.default.driver=org.postgresql.Driver
 db.default.url="jdbc:postgresql:postgres"
 db.default.user=postgres
 db.default.password="root"

 db.default.jndiName=DefaultDS
4

1 回答 1

1

您必须将配置文件(application.conf)用于您的数据库。

enter code here
# Database configuration
# ~~~~~ 
db.default.driver=org.postgresql.Driver
db.default.url="jdbc:postgresql://localhost:5432/nameof_you_DB"
db.default.user=your_user_name
db.default.password=you_password
于 2013-12-19T14:57:24.743 回答