我在后面使用ebean作为ORM和SQL Server.当我尝试setMaxRows时,我得到了SQL语法错误的例外.生成的sql有类似的东西
select .... from ... where ... LIMIT 5
Run Code Online (Sandbox Code Playgroud)
虽然这可能适用于mysql,但SQLServer不喜欢它.
经过一些搜索后,我发现EBean,LimitOffsetSqlLimiter使用的默认SqlLimiter创建了这样的sql.我想知道我是否可以配置ebean,以便它可以使用其他实现,如RowNumberSqlLimiter,甚至我自己的实现,如这里提到的?
所以我有以下代码.我正在尝试创建一个名为SecurityType的表,其中包含值ID和描述.我想在其中添加两个字符串"Administrator"和"user".有没有办法可以将这两个排除在ebean表中的列之外?还是我需要搬到另一个班级?
@Entity
public class SecurityType extends Model {
public static final String ADMIN = "Administrator";
public static final String USER = "User";
@Id
public Long id;
public String description;
}
Run Code Online (Sandbox Code Playgroud) 我在尝试将数据保存到db中的模型时收到此错误.
@Entity
public class User extends Model {
@Required
public String name;
@Email
public String email;
@Required @MaxLength(value=10)
public String username;
@Required @MinLength(value=4)
public String password;
@Id
public int id;
}
Run Code Online (Sandbox Code Playgroud)
这是我的班级.
当我试图将模型保存到db时,这是错误.

我将不胜感激任何帮助!非常感谢.
编辑:表结构在这里

使用Play Framework,我有一个这样的模型:
class MyModel extends Model {
// Some columns
@ManyToOne
public OtherModel other;
public OtherModel getOther() {
return other;
}
}
Run Code Online (Sandbox Code Playgroud)
出于某种原因我无法理解,如果我调用myModel.otherOR myModel.getOther()(myModel作为实例MyModel),我得到一个Null值,即使它应该返回OtherModel的实例!
而且,如果我将getOther()方法更改为:
public OtherModel getOther() {
console.log (String.valueOf(other));
return other;
}
Run Code Online (Sandbox Code Playgroud)
getOther() 返回预期的实例 OtherModel
我只想说......是...... WTF?
有人可以向我解释为什么,以及如何解决这种奇怪的行为?
谢谢 :)
我有一个像这样的ManyToMany-Association:
@Entity
public class User extends Model implements RoleHolder {
@ManyToMany(cascade=CascadeType.ALL)
public List<Task> tasks;
}
Run Code Online (Sandbox Code Playgroud)
然后我这样做:
User u = Application.getLocalUser(session());
u.tasks.clear();
for (Task t : tasksToAdd)
u.tasks.add(t);
u.saveManyToManyAssociations("tasks");
u.update()
Run Code Online (Sandbox Code Playgroud)
但是当我尝试在Controller-Action中读取Collection时,只有一个"BeanList deferred"-Message
User u = Application.getLocalUser(session());
return ok(tasks.render(u.tasks));
Run Code Online (Sandbox Code Playgroud)
谢谢您的帮助
我的简化模型如下所示:
@Entity public class Aspect extends Model {
@Id public Long id;
@OneToMany(cascade = CascadeType.ALL) public List<Restriction> restrictions;
}
@Entity public class Restriction extends Model {
@Id public Integer id;
@ManyToOne public RestrictionTemplate restrictionTemplate;
}
@Entity public class RestrictionTemplate extends Model {
@Id private Integer id;
}
Run Code Online (Sandbox Code Playgroud)
基本上这个想法是这样的:每个Aspect都有一组限制.每个限制本身都依赖于RestrictionTemplate.
我希望Aspect创建表单是这样的:用户可以选择一些RestrictionTemplates,并在表单上提交新的限制应该创建并与新的Aspect相关联.
让我再次解释一下:在表单提交上,我想根据提供的RestrictionTemplate ids 创建Aspect和相关限制.
表格中的字段应该具有哪些名称才能使这种绑定成为可能?
适用于直接关系的命名:
restrictions[0].restrictionTemplate.id
restrictions[1].restrictionTemplate.id
Run Code Online (Sandbox Code Playgroud)
在这里不起作用(在DB中创建Aspect …
我有一个查询,我想在我的产品模型中写
select * from shop inner join product on product.shops_id=shop.id where product.name=keyword
Run Code Online (Sandbox Code Playgroud)
Shop.java
public class Shop extends Model {
@Id
@SequenceGenerator(name="shop_gen", sequenceName="shop_id_seq", allocationSize=1)
@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="shop_gen")
@Column(name="id")
public Long id;
@Required
public String name;
@Required
public String addressLine1;
public String addressLine2;
public String addressLine3;
@Required
public String city;
@Required
public String town;
@Required
public String phoneNumber;
@OneToMany(mappedBy = "shops",cascade = CascadeType.REMOVE)
public List<Product> products=new ArrayList<>();
@Required
@OneToOne
public String category;
@Lob
@Column(name = "shop_pic")
public byte[] shop_pic;
@ManyToOne
@Required
public User …Run Code Online (Sandbox Code Playgroud) 我有两个模型类
@Entity
public class CustomerAccount extends Model {
@Id
@Column(columnDefinition = "int(11)")
public int customer_id;
@Column(columnDefinition = "varchar(50) not null unique")
public String customer_email;
@Column(columnDefinition = "varchar(50) not null")
public String password;
}
Run Code Online (Sandbox Code Playgroud)
@Entity
public class Customer extends Model {
@Column(columnDefinition = "int(11) unique")
public int customer_id = 6;
@Column(columnDefinition = "varchar(50) not null")
public String customer_fname;
@Column(columnDefinition = "varchar(50) not null")
public String customer_lname;
@Column(columnDefinition = "varchar(50) unique not null")
public String email = "";
}
Run Code Online (Sandbox Code Playgroud)
现在我想在表CustomerAccount引用Customer表中添加一个foriegn键,如: …
Posts Model
/*set many to one relation with Privacy_Level model*/
@ManyToOne//(fetch = FetchType.LAZY)
@JoinColumn(name = "privacy_level_id",referencedColumnName = "id", insertable = false, updatable = false)
public Privacy_Level privacy_level_t;
-------------------------------------------------------------------------------------------------------------
Privacy_Level Model
/*set one to many relation with Posts model*/
@OneToMany(mappedBy = "privacy_level_t")
public List<Posts> posts;
/*set many to one relation with Table_Status model*/
@ManyToOne
@JoinColumn(name = "status",referencedColumnName = "id", insertable = false, updatable = false)
public Table_Status table_status;
--------------------------------------------------------------------------------------------------------------
Table_Status Model
/*set many to one relation with Privacy_level table*/
@OneToMany(mappedBy = …Run Code Online (Sandbox Code Playgroud) one-to-many many-to-one playframework ebean playframework-2.6
我有一个基于Play框架Scala 2.11.1版本的应用程序。我想为其添加单元测试的方法有几种。这些方法通过Ebean直接调用数据库。
我尝试使用此链接使用嘲笑-ebean来模拟这些调用。但是导入不成功
我也尝试过powermock。但是它需要为模拟调用设置内存中的ebean服务器。但是不建议将其设置为用于单元测试的内存服务器。
知道下一个方向是什么?