我希望有人之前遇到过这个问题,可以帮助我.基本上,Hibernate插入父行(ID指向子行),但不插入具有关联ID的子行,这使数据库处于错误状态.这是Hibernate尝试加载未正确保存的对象时抛出异常的示例:
27 Jun 2011 13:55:31,380 ERROR [scheduler_Worker-4] -
Job DEFAULT.queryScrubJobDetail threw an unhandled Exception:
org.springframework.scheduling.quartz.JobMethodInvocationFailedException:
Invocation of method 'doIt' on target class [XXX] failed; nested exception is
org.springframework.orm.hibernate3.HibernateObjectRetrievalFailureException:
No row with the given identifier exists:
[XXX.DataProviderTransaction#60739703]; nested exception is org.hibernate.ObjectNotFoundException:
No row with the given identifier exists:
[com.idology.persist.DataProviderTransaction#2]
Run Code Online (Sandbox Code Playgroud)
这部分应用程序有三个实体:
以下是映射:
来自查询:
@OneToMany(mappedBy = "query", cascade =
{ CascadeType.PERSIST, CascadeType.MERGE }, fetch = FetchType.LAZY)
@Cascade(org.hibernate.annotations.CascadeType.SAVE_UPDATE)
@JoinColumn(name = "query_id")
public List<DataProviderTransactionReference> getDataProviderTransactionReferences() …Run Code Online (Sandbox Code Playgroud) 我试图通过使用 SQLite3 内存数据库作为应用程序的测试数据库来加快 Rails 应用程序的测试速度。我已按照这篇博文中的说明进行操作。
我的数据库配置database.yml如下所示:
test:
adapter: sqlite3
database: ":memory:"
encoding: utf8
verbosity: quiet
Run Code Online (Sandbox Code Playgroud)
我还按照建议创建了初始化程序:
def in_memory_database?
Rails.env == "test" and
ActiveRecord::Base.connection.class == ActiveRecord::ConnectionAdapters::SQLiteAdapter ||
ActiveRecord::Base.connection.class == ActiveRecord::ConnectionAdapters::SQLite3Adapter and
Rails.configuration.database_configuration['test']['database'] == ':memory:'
end
if in_memory_database?
ActiveRecord::Schema.verbose = false
puts "creating sqlite in memory database"
load "#{Rails.root}/db/schema.rb"
end
Run Code Online (Sandbox Code Playgroud)
我的所有测试都失败了,因为无法加载装置,如您所见:
creating sqlite in memory database
Loaded suite test/unit/vendor_appliance_test
Started
E
Finished in 0.070079 seconds.
1) Error:
test_the_truth(VendorApplianceTest):
ActiveRecord::StatementInvalid: Could not find table 'advertisers'
1 tests, 0 assertions, …Run Code Online (Sandbox Code Playgroud) 我正在使用FasterCSV在Rails 3应用程序中生成报告的CSV输出.这是一段代码片段:
<%= FasterCSV.generate do |csv|
@groups.each do |b|
record = [ b.group, b.organization_name, b.status, b.comments ]
csv << record
end
end
%>
Run Code Online (Sandbox Code Playgroud)
当FasterCSV包含空字符串时,它使用一对空的双引号.
不幸的是,Rails 3将这些引号编码为实体,这对Excel不起作用.这是我的CSV输出的样子(当b.comments为nil或空字符串时):
Rafeland,Rafe Organization,Submitted,""
Run Code Online (Sandbox Code Playgroud)
什么是阻止Rails编码这些实体的普遍接受的方法?我知道"原始"方法,但它不会阻止我可以将CSV生成.