MyObject myObject = repositoryHibernateImpl.getMyObjectFromDatabase();
//transaction is finished, and no, there is not an option to reopen it
ThirdPartyUtility.doStuffWithMyObjectType( myObject );
Run Code Online (Sandbox Code Playgroud)
此时你已经定义了什么是懒惰和急切加载,第三方实用程序将尝试调用你的"myObject"实例上的所有方法,这很好,因为你不想为懒惰返回任何东西加载属性,不幸的是它不返回null,它抛出一个LazyInitializationException.
发生这种情况是因为您实际上是在Hibernate的对象代理上调用该方法,并且它知道它没有获取该数据,并抛出异常.
甚至可以使用null值获取底层对象,以便getter只返回null,并且不会抛出异常?基本上分离对象,以便Hibernate完全不再了解它.延迟加载的对象的访问器必须返回null,它不能返回实际值,我们希望能够将实体转换为POJO,而不必创建看起来像实体的对象,并且必须重新映射所有值.
我最近发现CGI脚本几乎可以用任何可以打印到stdout的语言编写.我写了一个小的guile cgi脚本,可以在我的本地apache安装上运行,但不能在我的共享主机上运行:
#!/usr/local/bin/guile -s
!#
(display "Content-Type: text/html")
(newline)
(newline)
(display "hi")
(newline)
Run Code Online (Sandbox Code Playgroud)
当我通过ssh从主机上的shell运行脚本时,这是输出:
$ ./scheme.cgi
Content-Type: text/html
hi
Run Code Online (Sandbox Code Playgroud)
所以,显然我的主机安装了guile.但是,当我尝试在浏览器中访问此文件时,出现"500 Internal Server Error".查看我的错误日志时,我发现我遇到了可怕的"脚本标头过早结束"错误:
[server.com] [Tue Aug 17 00:54:19 2010] [error] [client xx.xx.xx.xxx] (2)No such file or directory:
exec of '/home/www/vhosts/jcw.geekisp.com/cgi-bin/scheme.cgi' failed
[server.com] [Tue Aug 17 00:54:19 2010] [error] [client xx.xx.xx.xxx] Premature end
of script headers: scheme.cgi
Run Code Online (Sandbox Code Playgroud)
因为我在共享主机上,使用mod_lisp或guile的fastcgi实现是不可能的.话虽这么说,这可能是什么问题?类似的cgi脚本我用python,perl,ruby和sh编写的服务器上没有错误.我看到主机上安装了guile 1.8.7,但我的本地机器是最新版本.
我知道这是一个令人难以置信的小众问题,任何帮助将不胜感激!
我有一个用C#编写的加密/解密算法 - 我需要能够在PHP中生成相同的加密,这样我就可以通过HTTP发送加密文本,在C#端解密.这是加密的C#代码.
this.m_plainText = string.Empty;
this.m_passPhrase = "passpharse";
this.m_saltValue = "saltvalue";
this.m_hashAlgorithm = "SHA1";
this.m_passwordIterations = 2;
this.m_initVector = "1a2b3c4d5e6f7g8h";
this.m_keySize = 256;
public string Encrypt()
{
string plainText = this.m_plainText;
string passPhrase = this.m_passPhrase;
string saltValue = this.m_saltValue;
string hashAlgorithm = this.m_hashAlgorithm;
int passwordIterations = this.m_passwordIterations;
string initVector = this.m_initVector;
int keySize = this.m_keySize;
// Convert strings into byte arrays.
// Let us assume that strings only contain ASCII codes.
// If strings include Unicode characters, use Unicode, …Run Code Online (Sandbox Code Playgroud) 我们可以使用委托来调用回调方法.例如,
public delegol bool ContinueProcessing();
//稍后我们可以写代码,
ContinueProcessing cp = new ContinueProcessing(IsDataAvailable);
cp + = new ContinueProcessing(IsTransactionComplete);
//稍后在代码定义方法
bool IsDataAvailable(){return true; }
bool IsTransactionComplete(){return true; }
cp.Invoke();
上面的调用将一个接一个地调用两个布尔方法.为什么我们需要"活动"?"活动"的目的是什么?
我不知道我是只是在寻找错误的东西或者是什么,但是有一种简单的方法来评估范围并使用(2..100)语法检查整数是否在该范围内.
例如,如果我的整数x = 100和我的范围是(0..200),我想要评估为真,我只是在寻找简单,简洁的红宝石方式.
我正在使用file.readline()查找特殊行,以只读模式浏览文本文件的Python文件指针.一旦找到该行,我想将文件指针传递给一个方法,该方法期望文件指针位于该readline的START位置(不在它之后).
我如何在文件指针上实质上撤消一个file.readline()操作?
在我工作的地方,我经常看到这样的代码:
public void Test(Models.User.UserInfo userInfo, Models.User.UserParameter param)
{ ... }
Run Code Online (Sandbox Code Playgroud)
就个人而言,我更喜欢看到类似的东西:
public void Test(UserInfo userInfo, UserParameter param) { ... }
Run Code Online (Sandbox Code Playgroud)
并在顶部有一个导入.
你怎么看待这个?最佳做法是什么?两者的利弊是什么?我怎么能说服我的队友?
我发现第二种选择更加明确.
我想在运行git pull或svn update(在另一个项目中)执行一个shell命令来处理缓存文件和编译?
这是我的函数代码:
char * increment_b_string(char * b_string)
{
char * ret_string = (char *) malloc(7);
ret_string = "001aaa";
if (*(b_string + 2) == '9')
{
*(ret_string +2) == '0';
if (*(b_string + 1) == '9')
{
*(ret_string +1) = '0';
*(ret_string) = *(b_string) + 1;
} else {
*(ret_string + 1) = *(b_string + 1) + 1;
}
} else {
*(ret_string + 2) = *(b_string + 2) + 1;
}
return ret_string;
}
Run Code Online (Sandbox Code Playgroud)
有关它为什么会失败的任何想法?
一般的想法是b_string将包含类似"123aaa"的值."aaa"部分并不重要,永远不会改变.只有前3个数字会.它们需要增加,就好像它们是整数一样.需要在开始时保留前导零.因此,如果输入为"004aaa",则输出应为"005aaa".这只需要达到"300aaa",因此我不会考虑更多的东西.这是一个学校的编程任务,因此问题非常人为.
谢谢.
编辑:我改变了我的功能.这就是现在的情况.
void increment_b_string(char * …Run Code Online (Sandbox Code Playgroud)