当我在Model类中将变量定义为String时,它在DB中转换为'VARCHAR(255)'.
但是,我想保存超过255,因为这些数据是由几段组成的非常长的文本.
据我所知,DB中有一个TEXT类型可以保存很长的文本.
如何在Play中定义TEXT类型!框架?
我尝试在Play中定义Constraints.MaxLength和Constraints.Max!框架api.
但是,仍然1.sql文件(由Ebean DDL自动创建)将此变量定义为VARCHAR(255).
提前致谢!
我有以下课程:
@Entity
@Table(name = "clients")
public class Client extends Model {
@Id
public int id;
@Formula(select = "inv.some_data",
join = "left join (select 1 as some_data) as inv")
public int someData;
public static Finder<String, Client> find =
new Finder<String, Client>(String.class, Client.class);
public static int countClientsWithData() {
return Client.find.where().gt("someData", 0).findRowCount();
}
}
Run Code Online (Sandbox Code Playgroud)
它有someData字段(播放框架将自动生成getter和setter).并且还在子句中countClientsWithData使用此字段where.现在,如果我这样做
int count = Client.countClientsWithData();
Run Code Online (Sandbox Code Playgroud)
它会NullPointerException在尝试执行查询时抛出
select count(*) from clients t0 where inv.some_data > ?
Run Code Online (Sandbox Code Playgroud)
看起来findRowCount无法识别@Formula注释中的连接.有关如何解决这个问题的任何想法?
更新的问题: …
我们正在使用Play Framework 2.0.3建立一个稍微复杂的项目.
我们需要访问几个数据库(预先存在),并希望使用框架内置工具(即EBean)来实现.
我们尝试在"models"包中创建所有模型类,然后使用其FQN将每个类映射到application.conf中的相应EBean属性:
ebean.firstDB="models.ClassA,models.ClassB,models.ClassC"
ebean.secondDB="models.ClassD"
ebean.thirdDB="models.ClassE,models.ClassF"
Run Code Online (Sandbox Code Playgroud)
这似乎不起作用:
PersistenceException: Error with [models.SomeClass] It has not been enhanced but it's superClass [class play.db.ebean.Model] is? (You are not allowed to mix enhancement in a single inheritance hierarchy) marker[play.db.ebean.Model] className[models.SomeClass]
Run Code Online (Sandbox Code Playgroud)
我们检查并重新检查,配置正常!
然后,我们尝试为每个数据库模型类使用不同的Java包,并在application.conf中相应地映射它们:
ebean.firstDB = "packageA.*"
ebean.secondDB = "packageB.*"
ebean.thirdDB = "packageC.*"
Run Code Online (Sandbox Code Playgroud)
这在从数据库中读取信息时工作正常,但是当您尝试保存/更新对象时,我们得到:
PersistenceException: The default EbeanServer has not been defined? This is normally set via the ebean.datasource.default property. Otherwise it should be registered programatically via registerServer()
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
谢谢!里卡多
基本问题:为什么@Embedded对象不会被实例化?
有趣的观察是,如果那些不包含基本数据类型(int,boolean ...)或之前未被触及的话,Ebean不会实例化@Embedded对象.例:
@Entity
public class Embedder {
// getNotAutoInstantiated() will return null if this field was not touched before
@Embedded
private NotAutoInstantiated notAutoInstantiated = new NotAutoInstantiated();
// getAutoInstantiated() will always return an instance!
@Embedded
private AutoInstantiated autoInstantiated = new AutoInstantiated();
}
@Embeddable
public class AutoInstantiated {
// theKey is why this embedded object is always instantiated
private int theKey;
private String field1;
}
@Embeddable
public class NotAutoInstantiated {
private String field2;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Play Framework 2和Ebean.当用户提交表单以编辑数据库中的现有对象时,它不会保存空值.我想这是为了防止覆盖不在表单中的字段为null.但是,如果他们需要,我如何让他们将表单中的字段设置为null?
例如,用户编辑Event对象. Event.date是1/1/13.用户将Event.date表单中的字段设置为空并提交表单.Event.date在调试器中检查显示其值为null.我救了Event.如果我查看Event数据库中的数据,它的值仍然是1/1/13.
编辑:似乎有一种方法.唯一的问题是它不适用于嵌套实体.对此有何解决方案?
update(Object bean,Set<String> properties)
Run Code Online (Sandbox Code Playgroud) 经过对谷歌的一些研究,我没有找到任何有我问题的人,这就是我在这里发布的原因.在我的应用程序中,我有三个实体:用户(摘要),客户,代理商.客户和代理商扩展用户.这是用户的代码:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class User extends AbstractModel {
@Column(unique = true)
@NotNull
@Email
public String email;
@NotNull
public String password;
}
Run Code Online (Sandbox Code Playgroud)
问题是生成的模式只创建一个包含User,Customer和Agency字段的表,这通常是InheritanceType.SINGLE_TABLE(默认)的行为.
使用Ebean和@Inheritance注释有什么问题吗?我尝试了InheritanceType.TABLE_PER_CLASS,它也没有用.我从来没有使用JPA这个问题.有人可以帮忙吗?
非常感谢 ;)
我正在尝试进行查询,我想检查用户的电子邮件或名称是否以给定字符串开头.在sql查询中我会用这个写
name like 'queryString%' or email like 'queryString%'
Run Code Online (Sandbox Code Playgroud)
在ebean查询中,我希望写一些类似于:
find.where().or(like('name', 'queryString%'), like('email', 'queryString%'));
Run Code Online (Sandbox Code Playgroud)
问题是,或者接受表达式,而不是表达式列表,这是我在写作时得到的
find.where().like(...,...)
Run Code Online (Sandbox Code Playgroud)
据我所知,它做了这样的查询:
find.where().like(.., ...).like(..., ...)
Run Code Online (Sandbox Code Playgroud)
正在使用AND.
如何使用ebean编写这样的查询?
谢谢!
我正在使用最新版本的Play!构建应用程序.在定义Finder时(如在Model.Finder中),我的IDE给了我一个警告Finder已被弃用.我在文档中找不到任何关于Model.Finder被弃用的任何替代使用它的信息.有没有人遇到类似的问题,并知道另一种选择?
我有一个使用Ebean的Play 2.1.3 Java应用程序.我收到下面的OptimisticLockException.
[OptimisticLockException: Data has changed. updated [0] rows sql[update person
set name=? where id=? and email=? and name=? and password is null and created=?
and deleted is null] bind[null]]
Run Code Online (Sandbox Code Playgroud)
我知道它试图告诉我,当我阅读它和我试图写它时,记录已经发生了变化.但唯一的变化是在这种方法中发生的.
public void updateFromForm(Map<String, String[]> form) throws Exception {
this.name = form.get("name")[0];
String password = form.get("password")[0];
if (password != null && password.length() != 0) {
String hash = Password.getSaltedHash(password);
this.password = hash;
}
this.update();
}
Run Code Online (Sandbox Code Playgroud)
我做错了吗?我在zentasks中看到了类似的逻辑.另外,我应该能够看到绑定变量的值吗?
更新:我从控制器内部调用updateFromForm():
@RequiresAuthentication(clientName = "FormClient")
public static Result updateProfile() throws Exception {
final …Run Code Online (Sandbox Code Playgroud) ebean ×10
java ×5
database ×2
jpa ×2
embeddable ×1
forms ×1
inheritance ×1
orm ×1
save ×1
scala ×1