我认为hibernate只考虑带注释的类变量@Column.但奇怪的是,今天当我添加一个变量(没有映射到任何列,只是我在类中需要的变量)时,它试图将该变量作为列名包含在select语句中并抛出错误 -
'字段列表'中的未知列'team1_.agencyName'
我的课 -
@Entity
@Table(name="team")
public class Team extends BaseObject implements Serializable {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private Long id;
@Column(length=50)
private String name;
@Column(length=10)
private String code;
@Column(name = "agency_id")
private Long agencyId;
private String agencyName; //note: not annotated.
}
Run Code Online (Sandbox Code Playgroud)
仅供参考...我在另一个具有多对多映射的类中使用上面的类
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name="user_team",
joinColumns = { @JoinColumn( name="user_id") },
inverseJoinColumns = @JoinColumn( name="team_id")
)
public Set<Team> getTeams() {
return teams;
}
Run Code Online (Sandbox Code Playgroud)
为什么会这样?!
这有什么区别......
if (is_null($var)) {
do_something();
}
Run Code Online (Sandbox Code Playgroud)
还有这个?
if ($var === null) {
do_something();
}
Run Code Online (Sandbox Code Playgroud)
检查变量是否包含null时哪种形式更好?我应该注意哪些边缘情况?(我初始化所有变量,因此不存在的变量不是问题.)
给定n个整数的排序数组,如下所示:
ary = [3, 5, 6, 9, 14]
Run Code Online (Sandbox Code Playgroud)
我需要计算每个元素和数组中下一个元素之间的差异.使用上面的例子,我最终得到:
[2, 1, 3, 5]
Run Code Online (Sandbox Code Playgroud)
开始数组中可能包含0,1或许多元素,我将要处理的数字将更大(我将使用纪元时间戳).我尝试过以下方法:
times = @messages.map{|m| m.created_at.to_i}
left = times[1..times.length-1]
right = times[0..times.length-2]
differences = left.zip(right).map { |x| x[0]-x[1]}
Run Code Online (Sandbox Code Playgroud)
但我上面的解决方案既不是最优的,也不理想.任何人都可以帮我一把吗?
如果我在某个地方(未预先确定)有一个链接,就像这样:
<div id="foo">
<div>
<div>
<a href="asdf.com">link</a>
<a href="#bar" class="specialLink">link</a>
<a href="#bar2" class="specialLink">link</a>
<a href="#bar3" class="specialLink">link</a>
</div>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我如何使用.find()选择"specialLink"类的第一个链接?
我的非工作猜测是:
$("#foo").find(".specialLink a:first")
Run Code Online (Sandbox Code Playgroud) 我想从比我更聪明的人那里了解Delphi,如果在'uses'指令中有很多单位导入,是不是让我的应用程序更慢或更大?
或者,如果我导入但未使用的单位很多,删除它们会更好吗?
在使用jquery时如何获得嵌套的表单id?
我们可以说表格是
<form id="search-theme-form">
<div id = "search">
<div id="edit-search-theme-form-1-wrapper" class="form-item">
</div>
<input id="edit-submit" class="form-submit btn">
</div>
</form>
Run Code Online (Sandbox Code Playgroud)
那将会
$('#search-theme-form').submit(function () {
$('#search #edit-submit').click(function () {
if ($("#search input:text").val() == "Search this community..." || $("#search input:text").val() == "") {
alert("Please enter a search term");
return false;
}
});
});
Run Code Online (Sandbox Code Playgroud) 我最近偶然发现了Javadoc Collection.checkedMap系列函数,用于创建标准集合类型的动态类型安全视图.考虑到他们在诊断相对常见的程序员错误的集合之上添加了另一层安全性,我认为它们会更受欢迎.但是出于某种原因,在我所做的所有大型Java项目中,我都没有看到它们被使用过一次.
我的问题是:Java程序员是否有更频繁地使用这些检查包装器的特殊原因?或者只是缺乏利益/缺乏对其存在的了解?
编辑:为了澄清我的问题,集合的通用版本仍然包含类型不安全的功能. Map的containsKey,containsValue,remove,和get所有的操作上Object,例如.我的主要问题是,鉴于此类型 - 不安全,为什么更多人不使用已检查的实现来诊断运行时类型违规.
这个问题真的是这个问题的一个分支,但我认为它应该得到自己的答案.
根据ECMA-334第15.13节(关于using声明,以下称为资源获取):
在资源获取中声明的局部变量 是只读的,并且应包括初始化器.如果嵌入语句试图修改这些局部变量(通过赋值或发生编译时间错误
++和--操作员)或它们传递作为ref或out参数.
这似乎解释了为什么下面的代码是非法的.
struct Mutable : IDisposable
{
public int Field;
public void SetField(int value) { Field = value; }
public void Dispose() { }
}
using (var m = new Mutable())
{
// This results in a compiler error.
m.Field = 10;
}
Run Code Online (Sandbox Code Playgroud)
但是这个怎么样?
using (var e = new Mutable())
{
// This is doing exactly the same thing, but …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Jasmine为基本的jQuery AJAX请求编写一些BDD规范.我目前在独立模式下使用Jasmine(即通过SpecRunner.html).我已配置SpecRunner来加载jquery和其他.js文件.任何想法为什么以下不起作用?has_returned并不成真,甚至想到了"yuppi!" 警报显示正常.
describe("A jQuery ajax request should be able to fetch...", function() {
it("an XML file from the filesystem", function() {
$.ajax_get_xml_request = { has_returned : false };
// initiating the AJAX request
$.ajax({ type: "GET", url: "addressbook_files/addressbookxml.xml", dataType: "xml",
success: function(xml) { alert("yuppi!"); $.ajax_get_xml_request.has_returned = true; } });
// waiting for has_returned to become true (timeout: 3s)
waitsFor(function() { $.ajax_get_xml_request.has_returned; }, "the JQuery AJAX GET to return", 3000);
// TODO: other tests might check size of …Run Code Online (Sandbox Code Playgroud) 我运行了以下代码,随着时间的推移(一两个小时),我注意到迭代项目需要更长时间.我正在做的事情导致这种情况发生吗?如果是这样我该怎么办呢?
int totalProcessed = 0;
int totalRecords = MyList.Count();
Parallel.ForEach(Partitioner.Create(0, totalRecords), (range, loopState) =>
{
for (int index = range.Item1; index < range.Item2; index++)
{
DoStuff(MyList.ElementAt(index));
Interlocked.Increment(ref totalImported);
if (totalImported % 1000 == 0)
Log(String.Format("Processed {0} of {1} records",totalProcessed, totalRecords));
}
});
public void DoStuff(IEntity entity)
{
foreach (var client in Clients)
{
// Add entity to a db using EF
client.Add(entity);
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助