Play Framework PersistenceException

时间:2014-08-18 16:44:15

标签: java oracle playframework persistence ebean

我正在尝试使用Play框架(Java)来简单地从几个Oracle表中读取一些数据,甚至可能稍后使用一些复杂的查询。我正在关注一个教程但是我在检索数据时遇到了一些问题。

我的模型类看起来像这样:

    package models;

    import java.util.ArrayList;
    import java.util.List;
    import play.libs.F;
    import javax.persistence.*;
    import com.avaje.ebean.*;
    import play.db.ebean.*;

    @Entity
    @Table(name="TABLESPACE.CAT_BONDS")
    public class Cat_Bond extends Model {

    @Id
    public String symbol; 
    public String database; 
    public String tickType; 
    public String assetClass; 
    public String sourcePlatform; 
    public String sourceExchange;

    public static Finder<String, Cat_Bond> find = new Finder<String, Cat_Bond>(String.class,Cat_Bond.class);

    public Cat_Bond(){}

    public Cat_Bond(String symbol, String database, String tickType, String assetClass, 
                    String sourcePlatform, String sourceExchange) {

        this.symbol = symbol;
        this.database = database;
        this.tickType = tickType;
        this.assetClass = assetClass;
        this.sourcePlatform = sourcePlatform;
        this.sourceExchange = sourceExchange;

    }

    /*
     * retrieve all rows from the 'cat_bonds' table
     */  
    public static List<Cat_Bond> findAll(){
        //return new ArrayList<Cat_Bond>(cat_bond);     
        return find.all();
    }

    /*
     * Find by EAN
     */
    public static Cat_Bond findByEan(String symbol){
        return find.where().eq("symbol", symbol).findUnique();
    }   
}

我的控制器类:

package controllers;

import java.util.List;

import views.html.*;
import models.Cat_Bond;
import play.data.Form;
import play.mvc.*;

public class Cat_Bonds extends Controller {

private static final Form<Cat_Bond> cat_bondForm = Form.form(Cat_Bond.class);

public static Result list(){
    List<Cat_Bond> cat_bond = Cat_Bond.findAll();
    return ok(list.render(cat_bond));
}

application.conf条目如下所示:

#Oracle
 db.default.driver=oracle.jdbc.OracleDriver
 db.default.url="jdbc:oracle:thin:@server.uk.net.intra:port/ALIAS"
 db.default.user=user
 db.default.password=pass


# Evolutions
# ~~~~~
# You can disable evolutions if needed
 evolutionplugin=disabled

问题是当在控制器中调用列表然后到模型中的findAll()时,我得到错误:

**[PersistenceException: Query threw SQLException:ORA-00904: "T0"."SOURCE_EXCHANGE": invalid identifier Bind values:[] Query was: select t0.symbol c0, t0.database c1, t0.tick_type c2, t0.asset_class c3, t0.source_platform c4, t0.source_exchange c5 from TABLESPACE.CAT_BONDS t0 ]**

2 个答案:

答案 0 :(得分:0)

@Column(名称= “XX”)

在模型类中定义的每个变量上方都需要映射到表列。

答案 1 :(得分:0)

您可以使用

clean 
compile
~run 

如果它无法正常工作,您可以在模型类中使用@EntityConcurrencyMode(ConcurrencyMode.NONE)