0

我得到了代码

public static List <Post> getPostForTopic(String topicName) {
    List <Post> list = find.where().eq("topic_name",topicName).findList();
    return list;
}

SQL 演进

# --- Created by Ebean DDL
# To stop Ebean DDL generation, remove this comment and start using Evolutions

# --- !Ups

create table post (
text                      varchar(255))
;

create table topic (
topic_name                varchar(255) not null,
constraint pk_topic primary key (topic_name))
;

create sequence topic_seq;




# --- !Downs

SET REFERENTIAL_INTEGRITY FALSE;

drop table if exists post;

drop table if exists topic;

SET REFERENTIAL_INTEGRITY TRUE;

drop sequence if exists topic_seq;

当我运行它时,我有执行异常:

[PersistenceException: Query threw SQLException:Столбец "TOPIC_NAME" не найден Column "TOPIC_NAME" not found; SQL statement: select t0.text c0 from post t0 where topic_name = ? [42122-158] Bind values:[null] Query was: select t0.text c0 from post t0 where topic_name = ? ] 

我和当我在我的 h2 数据库控制台中键入查询时,例如“Select * from topic”,我得到的结果是没有表“TOPIC”。请帮我找出错误

4

1 回答 1

2

我认为你使用了错误的取景器。

我敢打赌,您创建的find变量看起来像这样(我实际上不知道您使用什么类型作为主键):

 public static Finder<XXX,Post> find = new Finder<XXX,Post>(
    XXX.class, Post.class
  );

而你应该使用:

 public static Finder<String,Topic> find = new Finder<String,Topic>(
   String.class, Topic.class
 );
于 2013-01-14T21:28:22.463 回答