我有一个用序列生成的主键定义的实体:
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "id_key_gen")
@SequenceGenerator(name = "id_key_gen", sequenceName = "id_key_seq")
@Column(name = "id", unique = true, nullable = false)
public int getId() {
return this.id;
}
Run Code Online (Sandbox Code Playgroud)
我正在使用PostgreSQL,这个键定义为串行.根据PostgreSQL
select last_value from id_key_seq;
Run Code Online (Sandbox Code Playgroud)
回报
1603.
Run Code Online (Sandbox Code Playgroud)
当我执行create()来持久保存此实体的实例时,我在日志中看到以下内容(编辑出的无关内容):
05 15:15:26.948 org.hibernate.id.enhanced.SequenceStructure [DEBUG] - 获得的序列值:1604
05 15:15:26.948 org.hibernate.event.def.AbstractSaveEventListener [DEBUG] - 生成的标识符:1554,使用策略:org.hibernate.id.enhanced.SequenceStyleGenerator
后续的SQL插入语句引用值1554,而不是它应该使用的值1604(基于SequenceStructure返回的值.Hibernate从哪里获得1554?
在我看来,Hibernate有一个错误 - SequenceStructure知道正确的下一个值,但它没有被使用.知道如何解决这个问题吗?
仅供参考:我知道这个页面,它说要使用GenerationType.AUTO,因为"Hibernate人员完全搞砸了",但除此之外没有太多非常有帮助的陈述.
使用代码序列化对象时:
var xmlSerializer = new XmlSerializer(typeof(MyType));
using (var xmlWriter = new StreamWriter(outputFileName))
{
xmlSerializer.Serialize(xmlWriter, myTypeInstance);
}
Run Code Online (Sandbox Code Playgroud)
在输出xml文件中,我得到:
<MyType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Run Code Online (Sandbox Code Playgroud)
如何向其添加对xml架构的引用,因此它看起来像这样:
<MyType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xsi:noNamespaceSchemaLocation="mySchema.xsd">
Run Code Online (Sandbox Code Playgroud) 这是我的HTML:
<ul>
<li>
<p><label><input type="checkbox" name="permission" value="1" class="permission_check" checked> Joe Schmoe</label></p>
<p class="radio_option"><label><input type="radio" name="viewpromote" value="1"> View and Promote</label></p>
<p class="radio_option"><label><input type="radio" name="createedit" value="1" checked> ...plus Create and Edit</label></p>
</li>
<li>
<p><label><input type="checkbox" name="permission" value="1" class="permission_check" checked> Bob Smith</label></p>
<p class="radio_option"><label><input type="radio" name="viewpromote" value="1" checked> View and Promote</label></p>
<p class="radio_option"><label><input type="radio" name="createedit" value="1"> ...plus Create and Edit</label></p>
</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
我需要做的是当用户检查/取消选中permission_check输入时,它应该显示/隐藏该radio_option列表项的元素.
如果我经常引用:
$('#' + n + ':nth-child(2)').val()
Run Code Online (Sandbox Code Playgroud)
那么如何将$('#'+ n)缓存到变量中?
$n = $('#' + n);
$n:nth-child(2)
Run Code Online (Sandbox Code Playgroud) 我目前正在开展一个大型项目,并即将做出一些重大改变,并且正在寻找一种"备份"我之前工作的方法.Visual Studio中是否内置了功能以使用版本控制?
这个项目只由我开发,并没有使用Team Foundation Server(这是我的大部分谷歌搜索似乎给我答案).理想情况下,我想识别和恢复我的程序的所有不同版本,而不必担心完全弄乱某些东西......
欢呼并提前致谢!
---编辑---虽然有版本控制系统,是否会存储在单独的服务器上?或者可以在本地存储它吗?我更担心的是,我会严重搞砸我的代码而无法在某些时候撤消它...
我问的原因是,它只在方法参数声明中有效,不是吗?我试图在函数体中创建一个名为"params"的变量,但当然这不是什么大问题,只是想知道MS选择使其成为全局关键字而不是上下文的原因.
如何ActiveRecord::RecordNotUnique在控制器中处理异常?谢谢
编辑:我在生成唯一代码时遇到异常.我可以在application_controller.rb中处理异常,但我真正想要的是再次生成代码并且必须在控制器中完成.
generate_code
@couponcode = Couponcode.new(:user_id => current_user.id, :code => @code)
Run Code Online (Sandbox Code Playgroud)
编辑2:
generate_code
begin
@couponcode = Couponcode.new(:user_id => current_user.id, :code => @code)
rescue ActiveRecord::RecordNotUnique
#generate_code
@code = "111-11111"
@couponcode = Couponcode.new(:user_id => current_user.id, :code => @code)
end
Run Code Online (Sandbox Code Playgroud) 我已经使用了一段时间了,我已经阅读并使用了rspec.我还没有深入比较和对比.但在我看来,两者之间存在一些重叠,但它们不是1-1的替代品.
我正在考虑使用rspec在我的rails系统中编写一些单元测试,而不是替换用shoulda编写的所有现有测试.就像一种获得感觉的方式.
这是一个好主意吗?我可以逐渐从一个移动到另一个,还是我在寻找麻烦?
我应该考虑一个明显的优势吗?
谢谢!
我花了一天的大部分时间试图弄清楚为什么这不起作用。我有一个 WCF 服务,它将对象流式传输到客户端。然后客户端应该将文件写入其磁盘。但是当我调用stream.Read(buffer, 0, bufferLength)它时总是返回 0。这是我的代码:
namespace StreamServiceNS
{
[ServiceContract]
public interface IStreamService
{
[OperationContract]
Stream downloadStreamFile();
}
}
class StreamService : IStreamService
{
public Stream downloadStreamFile()
{
ISSSteamFile sFile = getStreamFile();
BinaryFormatter bf = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
bf.Serialize(stream, sFile);
return stream;
}
}
Run Code Online (Sandbox Code Playgroud)
服务配置文件:
<system.serviceModel>
<services>
<service name="StreamServiceNS.StreamService">
<endpoint address="stream" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IStreamService"
name="BasicHttpEndpoint_IStreamService" contract="SWUpdaterService.ISWUService" />
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IStreamService" transferMode="StreamedResponse"
maxReceivedMessageSize="209715200"></binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceThrottling maxConcurrentCalls ="100" maxConcurrentSessions="400"/>
<serviceMetadata …Run Code Online (Sandbox Code Playgroud) 我希望"s.value"全部变为小写,然后ucwords到它,但我不知道该怎么做,因为它在一个表单内.
基本上我想做这样的事情:ucwords(strtolower(s.value here));
这是形式:
<form role="search" method="get" id="searchform" action="http://chusmix.com/?s=" onsubmit="if (document.getElementById('s2').value.length > 5) window.location = action + '<php echo $city; ?>++++' + s.value; return false;" >
Run Code Online (Sandbox Code Playgroud)
谢谢